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 would have to agree with you. I think this is O(n). If it was O(1) you would read the input by itself and find the output without loop. Putting logic in the loop you use to read the input doesn't make your solution O(1); your logic not only can, but must loop N times.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
I would have to agree with you. I think this is O(n). If it was O(1) you would read the input by itself and find the output without loop. Putting logic in the loop you use to read the input doesn't make your solution O(1); your logic not only can, but must loop N times.