Tap here to switch tabs
Problem
Submissions

Problem: Most Frequent IDs

Most Frequent IDs tracks a changing collection as each step adds or removes occurrences of a specified ID. Return the maximum frequency after every operation, or zero when empty.

Statement

You are given two integer arrays nums and freq of length nn. Each step represents an operation on a collection of IDs that is initially empty:

At step i, freq[i] instances of the ID nums[i] are added to the collection if freq[i] is positive, or removed from the collection if freq[i] is negative.

Return an array ans of length nn, where ans[i] is the maximum frequency of any ID in the collection after the operation at step i. If the collection is empty, the maximum frequency is 00.

Constraints:

  • 1≤1 \leq nums.length =freq.length≤105= {freq.length} \leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • −105≤-10^5 \leq freq[i] ≤105\leq 10^5

  • freq[i] ≠0\neq 0

  • The input is generated such that the occurrences of an ID will not be negative in any step.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Most Frequent IDs

Most Frequent IDs tracks a changing collection as each step adds or removes occurrences of a specified ID. Return the maximum frequency after every operation, or zero when empty.

Statement

You are given two integer arrays nums and freq of length nn. Each step represents an operation on a collection of IDs that is initially empty:

At step i, freq[i] instances of the ID nums[i] are added to the collection if freq[i] is positive, or removed from the collection if freq[i] is negative.

Return an array ans of length nn, where ans[i] is the maximum frequency of any ID in the collection after the operation at step i. If the collection is empty, the maximum frequency is 00.

Constraints:

  • 1≤1 \leq nums.length =freq.length≤105= {freq.length} \leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • −105≤-10^5 \leq freq[i] ≤105\leq 10^5

  • freq[i] ≠0\neq 0

  • The input is generated such that the occurrences of an ID will not be negative in any step.