There's "successful completion", and then there's what Google is looking for. They want optimal code, and they want you to explain your thought process as you're writing. They want you to hit all the subtle corner cases without being prompted (and for you to verbally note why you coded it that way).
You solved the problem if you give them the O(n^2) answer, but they're looking for the more complicated O(n) answer, because then they'll get to present you with the 2nd and 3rd variations on the question, rather than spending time refining the first.