Reported February 2024
TikTokhash table

Count Purchases

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

TikTok's February OA hit candidates with Count Purchases, a deceptively simple problem that trips up people who overthink it. You've got transaction data, and the task is to count or aggregate purchases in some way. The trick isn't complex math or fancy data structures. It's usually about picking the right grouping, the right filter, and the right iteration order. StealthCoder can spot the exact grouping logic in seconds if you freeze mid-solve, so you're covered if your first approach doesn't land.

Pattern and pitfall

Count Purchases almost certainly involves hash tables or dictionaries to bucket transactions by some key (user ID, date, product category, or a combination). The pattern is straightforward: iterate through the input, accumulate counts keyed on the grouping dimension, then return the result. Common pitfall: candidates assume they need to sort or use a fancy data structure first. Most of the time you don't. The real challenge is reading the problem carefully enough to know what 'count' means in context. If it's 'count purchases per user' you're grouping by user. If it's 'count users with more than X purchases' you're filtering after. StealthCoder will parse the exact requirement in real time during the OA, eliminating ambiguity.

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 Count Purchases 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 TikTok's OA.

TikTok 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.

Count Purchases FAQ

Is Count Purchases a hash table problem?+

Almost certainly. You're aggregating or bucketing by some dimension (user, date, category). A dictionary or map is the natural fit. Sorting comes after, if at all. Keep your grouping logic separate from your filtering logic.

What's the most common mistake candidates make on this one?+

Overthinking the output format. Some return a count, some a list of users, some a dictionary. Read the exact return type requirement in the problem statement. That one detail catches people mid-solve.

Do I need to sort the transactions?+

Usually no, unless the problem explicitly asks for results ordered by date or by count. Most Count Purchases variants want a hashmap result. Sort only if the problem says to or if the expected output is obviously a list.

How hard is this compared to other TikTok OA problems?+

It's on the easier side of the difficulty spectrum. The mental model is simple: group, count, return. If you're blanking on which grouping key to use, StealthCoder will show you the exact pattern in seconds during the live OA.

Can I solve this in one pass?+

Yes. Read through transactions once, update your dictionary keyed on the grouping dimension, then return or filter the result. No need for multiple passes unless the problem asks for sorted output or a specific aggregation.

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