Motorola Solutions Interview Question

They asked me to solve a problem on leetcode