karan.coder.agarwal's blog

By karan.coder.agarwal, 12 years ago, In English
You have an array of N integers. You know all the values in the array but you don't know their order. You are really intelligent but at the same time very unlucky. You have to turn K of the values in the array to 0. When a value turns 0 then u know it is 0 and u dont know how much it is before it turns 0. In 1 move you can choose a number and subtract 1 from in. You have to tell the worst case number of moves given an array of integers?

Examples: If you have a 3 element array 1 10 100 and u need to turn 1 value to 0 in worst case you need only 3 moves. first you choose 100 because after 1 move it does not turn 0 u know its either 10 or 100 then u choose 10 same thing happens so in 3 moves u get 1 value which is 0. Another example u have 2 element array 4 5 and u need to turn 1 value to 0. here if u choose 5 after 4 moves u realise its 5 but u do not switch u continue with that as after 1 more move u can get 0 so answer is 5.

Full text and comments »

  • Vote: I like it
  • -25
  • Vote: I do not like it