注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
如题,申请的是24Technology Engineer Intern,同时收到了一个不限时的性格测试,大概30min可做完
OA 是60min 两道easy题,pass后收到了video assessment还没做
Question 1
Start with an initial string of zeros. Choose any digit to flip. When a digit is flipped, its value and those to the right switch state between 0 and 1. Given a target string of binary digits, determine the minimum number of flips required to achieve the target.
Example:
Target = 01011
Start with a string of 5 zeros, the same length string as the target.
Initial String -> 00000
Flip the 3rd digit -> 00111
Flip the 2nd digit -> 01000
Flip the 4th digit -> 01011
3 flips are required to reach the target. The return value is 3.
Function Description
Complete the function minimumFlips in the editor below.
minimumFlips has the following parameter(s):
String target: a string of 0s and 1s to match
Returns:
Int: the minimum number of flips needed to obtain the target string
Input Format for Custom Testing
The first line contains an integer, n, the length of the target
The next line contains a string, target
Stdin Function
5 -> numbers[] size n = 5
75 -> numbers = [75, 80, 99, 100, 50]
80
99
100
50
Sample Output0
LXXV
LXXX
XCIX
C
L
Explanation 1
We preform the following n = 5 conversions on the array [75, 80, 99, 100, 50]
0. numbers[0] = 75 corresponds to Roman numeral LXXV, L(50) + X(10) + X(10) + V(5)
1. numbers[1] = 80 corresponds to Roman numeral LXXX, L(50) + X(10) + X(10) + X(10)
2. numbers[2] = 99 corresponds to Roman numeral XCIX,XC(90) + IX(9)
3. numbers[3] = 100 corresponds to Roman numeral C
4. numbers[4] = 50 corresponds to Roman numeral L.
Return the array [LXXV, LXXX, XCIX, C, L] as the answer |