Microsoft interview question

A leetcode medium question was asked