Question d’entretien chez Qualcomm

Standard leetcode medium question, not easy for sure.