That’s a very strange piece.
Second after you pop this algorithm you’ll be asked “what’s the complexity of your solution”, and second after that “can you do better than that?”. And that’s where the hard part starts, not before that.
Not to mention that you have about 20 minutes to solve that problem in the most optimal way.