New Year Chaos

  • + 1 comment

    My appraoch is finding cycles.

    1.if element is at its respective index ,we need to do nothing

    2.Suppose for elements in the queue be 2 1, then one swap is

    needed. accounting to 1 bribe

    3.if elements in queue are 2 5 3 4 1 then 2 bribes are

    needed.as 2->5->1 .

    4.if that cycle increases ,then terminate .

    5.Else output the total bribes count .

    What is wrong with my approach . Pls explain....

    code : http://ideone.com/N9E8QO