CS-OA cs-vo Faang

Welcome to The Amazon Coding challenge – Optimizing Error Correction in Amazon’s Binary String Algorithm: Detailed Solutions to Two Challenging Problems – 最小错误数 – OA代写 – VO辅助 – 面试代面

亚马逊的数据库不支持非常大的数字,所以数字以二进制字符01的字符串形式存储。偶尔会出现一些错误,某些位置的字符会变成!,而我们不知道这些字符应该是0还是1

错误字符串由字符01!组成。字符!是由某个正确字符01变过来的。由于!是不可确定的,题目中的问题是找到最小错误数:在字符串中,对于每个子序列01出现时会生成x个错误,对于每个子序列10出现时会生成y个错误。需要找到最小错误数。

示例:

假设给定错误字符串"01!0!"x=2y=3

  • 如果替换后的字符串为"01010",那么:
    • 子序列01出现了2次,产生的错误数为2 * 2 = 4
    • 子序列10出现了3次,产生的错误数为3 * 3 = 9
    • 总错误数为4 + 9 = 13
  • 如果替换后的字符串为"01110",那么:
    • 子序列01出现了1次,产生的错误数为1 * 2 = 2
    • 子序列10出现了1次,产生的错误数为1 * 3 = 3
    • 总错误数为2 + 3 = 5

最小的错误数是5。由于答案可能很大,需要返回结果对10^9 + 7取模。

Function Description

Complete the function getMinErrors in the editor below.

getMinErrors has the following parameter(s):

  • string errorString: a string of characters 0, 1, and !
  • int x: the number of errors generated for every occurrence of subsequence 01
  • int y: the number of errors generated for every occurrence of subsequence 10

Returns:

  • int: the minimum number of errors possible, modulo 109+710^9 + 7109+7.

Constraints:

示例用例 0

输入:

  • errorString = "01!0!"
  • x = 2
  • y = 3

输出:

  • 8

解释: 最优字符串为"01010"。在此字符串中,有一个子序列01和两个子序列10。生成的总错误数计算如下:2 * 1 + 3 * 2 = 8

示例用例 1

输入:

  • errorString = "!!!!!!!"
  • x = 23
  • y = 47

输出:

  • 0

解释: 对于最佳字符串"0000000""1111111",没有子序列0110,错误数为0。

With our OA writing service, our Optiver company's OA perfectly achieved a full score. If you also need OA assistance, please contact us.

如果你需要OA代写,请联系我们, 确保满分。

Leave a Reply

Your email address will not be published. Required fields are marked *