1.

There are N floating blocks in a pond and they are arranged in a straight line. Each of these blocks has a value associated with them which is written on top of them.After every 1 minute, blocks at the odd positions get submerged underwater. You must shift the remainingblocks to one position left to fill in the emptied space. This process is repeated till only one block is leftfloatingYou must retum the value of the last block which is left floating.Note: The position index starts with 1 and blocks are numbered from 1 to N in the left to right direction. It isgiven that N is always greater than 1Function DescriptionComplete the blockNum function in the editor below. It has the following parameter(s):NameTypeDescriptionParametersNINTEGERnumber of blocks floating in a pond initiallyReturnThe function must return an INTEGER denoting the value of the lastblock which is left floating..Constraints• 15NS 10^5Input Format For Custom Testing​

Answer»

ong>Answer:

If the input number N is in power of 2 , OUTPUT will be N

else if the number is not in power of 2(let SAY 2ᵃ + z ) , output will be 2ᵃ

Explanation:

1st case :N=4

1 2 3 4

2 4

4(output)

2nd case : N=9 (i.e. (2³)+1 )  

1 2 3 4 5 6 7 8 9

2 4 6 8

4 8

8 (=2³)



Discussion

No Comment Found