Oracle interview question

Algorithm question was Medium level leetcode one.