I faced this questions when I joined Google's coding challenge GOCC56: Google's Online Challenge - Coding - Intern / NewGrad.
In my view, the level for those coding is medium.
The tricky of this coding that about the way to solve it:
Given an array has length N and a number M.
The operation of array has following this conditions:
+ i is index . i belongs to (0, N).
+ A[i] = max(0, A[i]-k).
Find the minimum operations less than or equals M so that it makes for each values at each indexs equal to 0.
Example:
N = 4, M = 5;
A[] = 5,6,3,8
Choose k: = 6
1st operation: 5 into 0 => 0,6,3,8
2nd operation: 6 into 0 => 0,0,3,8
3rd operation: 3 into 0 => 0,0,0,8
4th operation; 8 into 2 => 0,0,0,2
5th operation: 2 into 0 => 0,0,0,0
5 operisons is <= M (5) => the result is 5
But my problem is the answer must be 4 if we choose 8 => we just only need 4 operations to do the logic.
Are there any ideas or suggestions about this coding interview. Thanks a lot :)