Algorithm · Amazon · Medium
You are given an array of integers digits where every element is a digit (i.e., an integer from 0 to 9 inclusive). Your task is to reorder the elements into a sequence such that for every two consecutive elements, their sum is at most 9. If such an ordering exists, return any valid arrangement. If it is impossible to satisfy the condition, return an empty array. Hints: Since the values are constrained to the set {0,1,...,9}, you can avoid general sorting and instead use a…