BinaryCrazy's blog

By BinaryCrazy, history, 5 years ago, In English

Hi all,

Hope you are having a great day. I found this question on HackerEarth, and received a "Partially Accepted" verdict, but have no idea why.

Can someone please explain where my logic is wrong? I have listed my logic below.


Logic

Sort all the values for which one needs to perform the HIT operations.

Next, for each value, binary search to find the last index that satisfies the following inequality:

a[i] — i >= x[i] (1 indexing)

We subtract that from the original value, and output the resulting array.

Implementation.


Thanks a lot for your time and help.

It is greatly appreciated.

Regards,

BC

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