Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Questions

Jimmy

Sep 10, 2024

  1. Why are we sorting the capacities in ascending order and then iterating from the end? Why don't we just sort the capacities in descending order and iterate from the start? Seems simpler and less convoluted.
  2. Why is the space complexity O(n)? Shouldn't the space be O(m) since we are sorting the capacity (and not the apple) array?

0

0

Comments
Comments
Run Qi Jack Li
Run Qi Jack Lia year ago

Good question. I think the same for your first and second point.

  1. Sorting the capacity array in descending order is more intuitive to understand.

  2. should be O(m) because we are sorting the capacity of the boxes, not the apples.