RingCentral interview question

got one question on string manip + greedy