there long thin painting represent number line the painting paint multiple overlap segment segment paint unique color you give 2D integer array segment segmentsi starti endi colori represent halfclose segment starti endi colori colorThe color overlap segment paint mix paint when color mix form new color represent set mixed colorsfor example color 2 4 6 mixed result mixed color 246for sake simplicity output sum element set setyou want describe paint minimum number nonoverlapping halfclose segment mixed color these segment represent 2D array paint paintingj leftj rightj mixj describe halfclosed segment leftj rightj mixed color sum mixjfor example paint create segment 145177 describe paint 1412477 because14 color 57 sum 12 second segments47 color 7 second segmentreturn 2d array paint describe finished painting exclude part paint you return segment ordera halfclose segment b section number line point b include point include point b example 1input segment 145477179output 14144716explanation the painting describe follow 14 color 59 sum 14 segment 47 color 79 sum 16 second segmentsExample 2input segment 17968158107output 169672478158107explanation the painting describe follow 16 color 9 segment 67 color 915 sum 24 second segment 78 color 15 second segment 810 color 7 segmentexample 3input segment 1451474714711output 14124712explanation the painting describe follow 14 color 57 sum 12 second segment 47 color 111 sum 12 fourth segmentsnote return single segment 17 incorrect mixed color set different Constraints1 segmentslength 2 104segmentsilength 31 starti endi 1051 colori 109each colori distinct