You are viewing a single comment's thread. Return to all comments →
Sorry, but this is just bruteforce. Your code runs in O(n), but the input is O(M). By creating the array in code (which is not part of the input) you are using exponential memory and runtime (because the length of N is logarithmic compared to the actual length of the array).
See my anwser for a better idea about the solution.
I like how this comment correctly points out the insufficiencies of the original post using actual theoretical arguments, yet still gets downvoted massively.