there n item belong zero m group groupi group ith item belong equal 1 ith item belong group the item group zero index a group item belong itReturn sorted list item thatthe item belong group sort listThere relation item beforeItemsi list contain item come ith item sort array leave ith itemreturn solution solution return list solution Example 1input n 8 m 2 group 11100101 beforeitem 65636output 63415207example 2input n 8 m 2 group 11100101 beforeitem 65634output Explanation this example 1 4 need 6 sorted list Constraints1 m n 3 104grouplength beforeitemslength n1 groupi m 10 beforeitemsilength n 10 beforeItemsij n 1i beforeItemsijbeforeItemsi contain duplicate element