H1 interview question

React, algos