RingCentral Interview Question

got one question on string manip + greedy