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.
I agree that it could've been explicit, but the first alternative I got was using a check if the index wasn't within the array bounds and continue the loop if that was the case. It solved the error I was getting from trying to access a non-existent array in my arr, but if If did it that way, one query simply wasn't being processed, resulting in the wrong output.
The modulo of n gave this wrapping effect that gave me the expected output.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Dynamic Array
You are viewing a single comment's thread. Return to all comments →
I agree that it could've been explicit, but the first alternative I got was using a check if the index wasn't within the array bounds and continue the loop if that was the case. It solved the error I was getting from trying to access a non-existent array in my arr, but if If did it that way, one query simply wasn't being processed, resulting in the wrong output.
The modulo of n gave this wrapping effect that gave me the expected output.