Problem · Hash Table
Array Manipulation
Learn this problemProblem statement
Start with an empty multiset of integers called numbers. Process the queries in order:
+xappends one occurrence ofx. Duplicate values are allowed.-xremoves every occurrence ofx. The value is guaranteed to be present.
After each query, count the triples of element occurrences (x, y, z) that can be rearranged so that x - y = y - z = diff. Return all counts in query order.
Function
arrayManipulation(queries: String[], diff: int) → int[]Examples
Example 1
queries = ["+4", "+5", "+6", "+4", "+3", "-4"]diff = 1return = [0, 0, 1, 2, 4, 0]After adding 6, the triple is (6,5,4). The second 4 doubles that count. Adding 3 also creates two copies of (5,4,3). Removing 4 removes all such triples.
Constraints
🐢More Databricks problems
- Find First Anagram IndexPHONE SCREEN · Seen Apr 2026
- Minimize CommuteOA · Seen Apr 2026
- Difference Between Sums of PositionsSeen Sep 2024
- Longest Common Prefix of Number PairsSeen Sep 2024
- Subarray CountingSeen Sep 2024
- Write 'Y' on MatrixSeen Sep 2024
- Binary String RequestsSeen Aug 2024
- Bouncing Diagonal WeightsSeen Aug 2024