Hitman
BAN USER
Questions (2)
Comments (5)
Reputation 270
 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
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Even this method helps, if we aren't allowed to use and hexnumbers.
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));
}
}

Hitman
February 09, 2013 Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
You can get away from sorting the array and the following approach would directly populate the array in place.
 Hitman October 22, 2014