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
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Dynamic Array
You are viewing a single comment's thread. Return to all comments →
The introduction is wrong; it does not mention that the index needs to be modulo by the n parameter, as described in the explanation. :@@@@@
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.