Reported August 2026
TikTokhash table

Find Sum Pairs (for mle also :)

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

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

The TikTok OA reported in August 2026 looks like a query-processing problem, but it's a frequency map in disguise. You get two arrays, a stream of updates to a, and count queries asking how many (i, j) pairs sum to x. Don't brute force it with nested loops per query. Build a count of b once, then every count query becomes a lookup over distinct values of a. If you blank on the update bookkeeping during the live assessment, StealthCoder runs invisibly as a safety net and hands you the structure.

The problem

You are given two arrays of integers, a and b, and an array queries. Process every query in order.
Each query has one of the following forms:
[0, i, x]: assign a[i] the value x.
[1, x]: count the number of pairs of indices i and j such that a[i] + b[j] = x.
Return an array containing the results of the queries of the form [1, x], in the same order as those queries appear.

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

Examples
Example 1
a = [3, 4]
b = [1, 2, 3]
queries = [[1, 5], [0, 0, 1], [1, 5]]
return = [2, 1]
For the first query [1, 5], there are two valid pairs: a[0] + b[1] = 3 + 2 = 5 and a[1] + b[0] = 4 + 1 = 5.
The query [0, 0, 1] changes a[0] to 1, so a = [1, 4].
For the final query [1, 5], only a[1] + b[0] = 4 + 1 = 5 remains valid.
Example 2
a = [1, 1]
b = [2, 3]
queries = [[1, 3], [0, 1, 2], [1, 3], [1, 4]]
return = [2, 1, 2]
Initially both values in a pair with b[0] = 2 to form 3, so the first answer is 2.
After assigning a[1] = 2, the arrays are a = [1, 2] and b = [2, 3]. There is one pair that sums to 3 and two pairs that sum to 4.

Constraints
a and b are arrays of integers.
Each update query has the form [0, i, x].
Each count query has the form [1, x].

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: pair counting reduces to hash maps. Store freq_b as value to count. Store freq_a the same way. For a count query [1, x], sum freq_a[v] * freq_b[x - v] over each distinct v in freq_a. For an update [0, i, x], decrement freq_a[old a[i]], delete it if it hits zero, write the new value into a, and increment freq_a[x]. The common pitfall is rebuilding the map on every update, or looping over every index pair per query. Another trap is forgetting that a changes but b never does, so you only maintain one dynamic map. Also watch for assigning the same value that's already there. If you freeze on the update logic, StealthCoder is the hedge during the live OA, since it reads the problem and gives you a working solution while the proctor sees nothing. Use a 64-bit safe count if the arrays are large.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Find Sum Pairs (for mle also :) 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as finding pairs with a certain sum. If you have time before the OA, drill that.

⏵ The honest play

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

TikTok reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Sum Pairs (for mle also :) FAQ

What's the trick in the TikTok Find Sum Pairs problem?+

Stop thinking in index pairs. Keep a frequency map of b, which never changes, and a frequency map of a, which changes on updates. A count query becomes a sum of freq_a[v] times freq_b[x - v]. Updates are just two map adjustments, so they run in constant time.

How hard is this one really?+

Easy to medium. The logic is short once you see the hash map. The difficulty is spotting that naive nested loops per query will be too slow, and handling the update so the old value is removed cleanly from the map.

What's the time complexity of the best approach?+

Updates are O(1). Each count query is O(d), where d is the number of distinct values in a, because you look up x - v in b's map for each one. Setup is O(n + m). You can also iterate whichever array has fewer distinct values to speed queries up.

What edge cases should I test?+

Test an update that assigns the same value already in a, duplicates in both arrays, a query with no valid pairs returning 0, and values that go negative. Also check that you delete zero-count keys or handle them safely, so stale entries don't produce wrong counts.

How do I prepare for this in 48 hours?+

Practice two-sum style counting with hash maps, then add mutable updates. Write the solution from scratch twice using Example 1 and Example 2 as tests. Focus on clean map increment and decrement helpers, since most bugs come from update bookkeeping, not the counting itself.

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

OA at TikTok?
Invisible during screen share
Get it