Arithmetic Triplets After Queries
Updated
Problem statement
You are given an ordered array queries and a positive integer diff. Start with an empty collection of integers that can contain repeated values.
+xadds one occurrence of integerx.-xremoves all occurrences of integerx. Removing an absent value changes nothing.
After each query, count the triples of occurrences whose values x, y, z satisfy x - y = y - z = diff. Each choice of occurrences counts separately, so a value triple contributes the product of its three frequencies. Return these counts in query order.
For this exercise, assume the first character of each query is the operation, and the remaining characters are a signed decimal integer with no spaces. For example, +-2 inserts negative two and --2 removes all negative twos. Counts use 64-bit integers.
Function
countArithmeticTriplets(queries: String[], diff: int) → long[]Examples
Example 1
queries = ["+1","+3","+5","+5"]diff = 2return = [0,0,1,2]The third query forms one triple with values 5, 3, 1. The fourth adds a second occurrence of 5, creating two choices for that occurrence.
Constraints
- For this exercise, assume
0 <= queries.length <= 10^5. - For this exercise, assume
-10^8 <= x <= 10^8and1 <= diff <= 10^8. - Every query has a valid operation followed by a valid signed decimal integer.
- Use a signed 64-bit integer for each returned count.
More Capital One Online Assessment questions
- Count Pairs of Overlapping SquaresOA · Seen Nov 2026
- Distinct Values on Maximum-Sum FramesOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Lowest Number in an Open RangeOA · Seen Nov 2026
- Branch with the Most FilesOA · Seen Nov 2026
- Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
- Earn the Most 🐝OA · Seen Nov 2026
- Rank Football TeamsOA · Seen Oct 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
- Count One-Swap Number PairsOA · Seen Oct 2026
Similar questions at other companies
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Bouncing Square Reaches a Screen CornerDuolingo · OADuolingo interview questions
- Fraction to Recurring DecimalAirbnb · OAAirbnb interview questions
- Pro-Rata Order BookIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
- Stock System with Updates and Percentage ChangeLead Bank · ONSITE INTERVIEWLead Bank interview questions
- Transaction Fee Calculator — Channel Volume TiersStripe · PHONE SCREENStripe interview questions
- Overheat Prevention ControllerOptiver · OAOptiver interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences