Skip to content

Latest commit

 

History

History
9 lines (9 loc) · 497 Bytes

File metadata and controls

9 lines (9 loc) · 497 Bytes
  • Type: Array (greedy)
  • Approach:
    1. Sort the array.
    2. Use greedy method to traverse each token from small to large. Every time we would like smallest value in the tokens (deque.popleft()) to waste in power and largest value of tokens (deque.pop()) to add the power.
    3. Use collections.deque to make tokens a deque so that it can be popped the top value like a queue.
  • Complexity:
    • Time: O(nlogn)
    • Space: O(n)