Grab interview question

normal confusing algo question