Skip to content

Tag: algorithm

Moving character efficiently on a row

Given input (items = 6, position = 3) creates a row of 6 items and a character positioned on item 3 {0,1,2,[3],4,5} A call to left() moves the character two positions to the left and the item at position 3 is removed {0,[1],2,4,5} The next call to right() moves the character two positions to the right and the…

Find the first Recurring letter in Java

I wrote the code as follows but it doesn’t return the first recurring letter properly. Example: In the word “statistics” the recurring letters are s, t, and i. But the letter t recurs sooner than the letter s and i, but my program returns s instead of t. What do I need to do for it to return…

Time limit exceeded in hackerearth exercise

I’m trying to solve this exercise in HackerEarth. But I have an error of time limit exceeded. This is the code that I wrote : Answer Your solution is a little bit slow because of the bad implementation. I rewrote your solution in better implementation with the same logic and time complexity of your solu…

Check if array is sorted using recursion

I am getting true as answer even for unsorted(isNonDescending) arrays. Where is the bug? I want to break the array into smaller problem from the start of the array only. //Check for isNonDescending. Answer Instead of passing the size of the array as a parameter, which makes no sense anyway, because you can si…