Cubic Logics interview question

Two DSA problem, react hooks