Arrangement
Arrangement with priority queue
My original ideas:
Put items in PQ, each time take out K items; Decrement each count value and then put back; Edge condition: Total number of items in count, count remaining ones
Error1: Missed the edge case on K == 0
Error2: Did not handle the edge case: "abb", 2 - Output: "ab", expected "bab"
Read my previous answer, the basic idea is correct. However, edge cases (two above) are not handled correctly.
621.Task-Scheduler (H-)
My original ideas:
Calculate histogram. If current len(histogram) > n then no idle otherwise use idle to pad the missing entries.
Error1: cool down period n is actually smaller than interval
My original ideas:
Get stuck with 1405 so want to try a simpler verison of it.
Only two letters, maybe not need a PQ? If just use a PQ, the original solution won't work.
The idea is (suppose a > b) to construct the result as aab, aab, ..., then followed by abab...ab, or aa only
However, this solution does not work because given an example of a=4, b=1, aabaa
Optimize with three steps, aab...aab, ab...ab, aa
My original ideas:
Put items inside PQ, each time take out two different items from heap. Decrement and then put back in PQ. Since complexity O(10^9 * 10^5) = O(10^14)
Decrement is too small step in 1. Minus the biggest with the second biggest element and then put back in PQ. However, this solution does not work because it is incorrect in some cases
Read the answer:
The only exceptional case where not all milestones could be finished is when the biggest is too big.
So the problem reduces to an edge case handling math problem...... Totally unexpected.
Last updated