Ad
  • Custom User Avatar

    The array result has been sorted such that the value in the first index represents the cashier with the shortest line. Because this is a greedy algorithm, the optimal solution involves adding this next customer to the shortest line (time wise). Does that help?

  • Custom User Avatar

    During each iteration, the array is sorted. result[0] is the slot with the smallest value, the next register that can take a customer. Initializing result to size n creates the a slot for each "register".