Hitman
BAN USER- 2of 2 votes
AnswersGot this sh***y problem.
- Hitman in United States
A judge tells a person under trial that if your answer is true, you get 2 year sentence and if your answer is false you get 3 year sentence. The person under trial gives an answer which made the judge set him free. What did he say?| Report Duplicate | Flag | PURGE
Oracle Puzzle - 10of 10 votes
AnswersYou are given with an array of 1s and 0s. And you are given with an integer m, which signifies number of flips allowed.
- Hitman in United States
find the position of zeros which when flipped will produce maximum continuous series of 1s.
e.g.
input:
arr={1 1 0 1 1 0 0 1 1 1 } m=1
output={1 1 1 1 1 0 0 1 1 1} position=2
arr={1 1 0 1 1 0 0 1 1 1 } m=2
output={1 1 0 1 1 1 1 1 1 1} position=5,6| Report Duplicate | Flag | PURGE
Amazon Algorithm
Even this method helps, if we aren't allowed to use and hex-numbers.
int bits = 8;
for(int i=0;i<bits;i+=2){
int multiplier_1 = (int) Math.pow(2, i);
int multiplier_2 = (int) Math.pow(2, i+1);
int result_1 = number & multiplier_1;
int result_2 = number & multiplier_2;
if(result_1 != result_2 && (result_1 ==0 || result_2 ==0)){
if(result_2 > result_1)
number = (int) (number - Math.pow(2, i));
else
number = (int) (number + Math.pow(2,i));
}
}
You can get away from sorting the array and the following approach would directly populate the array in place.
- Hitman October 22, 2014