Morgan Stanley interview question

Leetcode medium question, followed by questions on SQL, design patterns, linux and Java OOP for superday