We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
@nbsarda, I have viewed your code carefully, and I also get correct result in my local machine, and then I run online by using custom test cases, I found difference result, so it is probably because of overflow problem. "if(a[i-2]>k)" When i is decrease for n - 1 times, i will be equal to 1, and a[i - 2] will be a[-1], here is the bug.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
@nbsarda, I have viewed your code carefully, and I also get correct result in my local machine, and then I run online by using custom test cases, I found difference result, so it is probably because of overflow problem. "if(a[i-2]>k)" When i is decrease for n - 1 times, i will be equal to 1, and a[i - 2] will be a[-1], here is the bug.