T-Mobile Interview Question

Technical question and was asked to whiteboard the solution