TapeRecordia
BAN USER- 3of 11 votes
AnswersGiven a binary representation of an integer say 15 as 1111, find the maximum longest continous sequence of 0s. The twist is it needs to be done in log N. I could think of O(N) solution. but couldn't go for log(N).
- TapeRecordia in United States
For example. 10000101
the answer should be 4, because there are 4 continouos zeroes.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -3of 3 votes
Answers4 individual numbers which could be permuted in 4 factorial ways. permutation of these 4 integers is an 0indexedarray consisting of 4 digits in some order when integers are different. the best permute of the 4 integers is by the following funciton func(summ) = abs(summ[0] - summ[1]) + abs(summ[1] - summ[2] + abs(summ[2] - summ[3])) that would give maximum value.
- TapeRecordia in United States
method signature
public int answer(int w, int x, int y, int z){
}
w = 5
x = 3
y = -1
z = 5
the sample permute wiht given numbers in the given function that would give maximum value is as follows.
for the
summ[0] = 5
summ[1] = -1
summ[2] = 5
summ[3] = 3
This should be done in O(1)time ans space complexity. My questions wordings may be confusing, but the function and sample data are perfectly correct.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm
Where did you study all these...you are genius
- TapeRecordia October 24, 2013But for finding the first maximum and first minimum also we need to traverse through all elements of the array right which leads to O(N). Could you explain more with some code. Please.
- TapeRecordia October 24, 2013
Before sending the number to this method, we need to convert an int to binary representation. I tried using Integer.toBinaryString(133) which actually returns a string on which I couldn't use the function. How to code this extension. btw i edited your code to java and it doesn't seems to give correct input. Could you help me.
- TapeRecordia October 25, 2013