Practice Most Frequent IDs
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Start with an empty collection. At step i, add freq[i] copies of ID nums[i] when freq[i] is positive, or remove -freq[i] copies when negative. The input never removes more copies than are present. Return the highest remaining frequency after each step, or 0 when the collection is empty.
Source: Most Frequent IDs on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [2,3,2,1], freq = [3,2,-3,1]
Output
[3,3,2,2]
# Example 2
Input
nums = [5,5,3], freq = [2,-2,1]
Output
[2,0,1]
Constraints
1 <= nums.length == freq.length <= 10^5
1 <= nums[i] <= 10^5
-10^5 <= freq[i] <= 10^5
freq[i] != 0
The input is generated such that the occurrences of an ID will not be negative in any step.
Related LeetCode Problems
Practice more problems similar to Most Frequent IDs.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.