Amazon interview question

graph coloring math puzzle next smaller element