Frage im Vorstellungsgespräch bei Meta

Leetcode medium difficulty question with slight modification