Reported October 2025
Duolingohash table

Dynamic Pair Sum Queries

Reported by candidates from Duolingo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Duolingo OA. Under 2s to a working solution.
Founder's read

The Duolingo OA reported in October 2025 hands you two arrays and a stream of queries, and the first thing you notice is that checking every (i, j) pair per query will die the moment the arrays get big. This is Dynamic Pair Sum Queries. Updates change a, queries count pairs that hit a target sum, and b never moves. It's a hash-table counting problem dressed up as a query system. If you recognize it fast, it's short. If you blank, StealthCoder is the invisible safety net running during the live OA.

The problem

You are given two integer arrays a and b and a sequence of queries. Process the queries in order.
A query [0, i, x] adds x to a[i].
A query [1, x] asks for the number of index pairs (i, j) such that the current values satisfy a[i] + b[j] = x.
Return the answers to all type-1 queries in their original order.

Function
processPairSumQueries(a: int[], b: int[], queries: int[][]) → long[]

Examples
Example 1
a = [1,4]
b = [1,2,3]
queries = [[1,5],[0,0,2],[1,5]]
return = [1,2]
Before the update, only a[1] + b[0] = 4 + 1 = 5, so the first answer is 1. The update changes a[0] from 1 to 3. Then both 3 + 2 and 4 + 1 equal 5, so the second answer is 2.

Constraints
a, b, and queries are non-empty.
Every type-0 query has the form [0, i, x] with 0 <= i < a.length.
Every type-1 query has the form [1, x].
Array b is never modified.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: b is static, so build a frequency map of b once. For a type-1 query [1, x], loop over a and add freqB[x - a[i]]. That's O(n) per query instead of O(n*m). For updates, a[i] += x is O(1). If the constraints allow it, that's the intended solution. If a is also large and queries are many, maintain a frequency map of a instead, and on update decrement the old value's count and increment the new one. Then each query iterates over distinct values of the smaller map. The pitfall is the return type. Counts can exceed 32 bits, so use long. Another trap is forgetting that duplicates in b count as separate pairs. Walk through Example 1 by hand to confirm you get [1,2]. If the live OA freezes your brain, StealthCoder can surface the frequency-map approach while you keep typing.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Dynamic Pair Sum Queries cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Duolingo's OA.

Duolingo reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Dynamic Pair Sum Queries FAQ

What's the trick in Dynamic Pair Sum Queries?+

Don't compare every pair. Since b never changes, store its value frequencies in a hash map once. For each query, count how many b values equal x minus a[i]. Updates only touch a, so they stay cheap. The map turns a nested loop into a single pass.

How hard is this Duolingo OA question really?+

Medium-ish. The logic is simple once you spot the hash map, but the reported October 2025 version punishes brute force. The difficulty is noticing the constraint, not writing code. Most of the work is a frequency map and a loop.

Why do I need long for the answers?+

The return type is long[] for a reason. With duplicate values, the number of matching pairs can be as large as the product of the two array lengths. That overflows a 32-bit int. Accumulate in a long and return it.

Should I track a's frequencies too?+

Only if queries are heavy and a is large with many repeats. Keep a count map for a, and on an update decrement the old value and increment the new one. Then each query sums countA[v] * countB[x - v] over distinct values. Otherwise the simple loop over a is fine.

How do I prepare for this in 48 hours?+

Practice two-sum style counting with hash maps, then add updates to a mutable array. Write the example by hand: a=[1,4], b=[1,2,3]. Check you get [1,2]. Also test duplicates in b and an update that changes a value to something already present.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Duolingo.

OA at Duolingo?
Invisible during screen share
Get it