RMS interview question

Walk me through your though process to implement this logic