Cubic Logics Interview Question

Two DSA problem, react hooks