Reported July 2026
TikTokhash table

Count Access Code Pairs

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 reported this one in July 2026, and the detail that trips people is right in the statement: if two fragments both read 12, you count (2, 3) and (3, 2) as separate arrangements. It's a concatenation counting problem dressed up as a spy story. You get an array of positive integers and a target accessCode, and you count ordered index pairs whose digits glued together equal the target. It's a hash-table and string problem, nothing exotic. If you blank on the counting rules during the live OA, StealthCoder sits invisibly on your screen as a safety net. Know the trick first and you won't need it.

The problem

A spy agency has intercepted fragments of a secret code. Each fragment is represented as a positive integer in an array called fragments. Intelligence suggests that the complete access code is a specific number called accessCode.
Your mission is to determine how many different ways the fragments can be paired to form the complete access code. The agency's cryptography rules state that:
When fragments are combined, they are simply placed next to each other (not added mathematically)
Each specific pair of fragments (by position in the array) counts as a unique combination
The fragments can be used in any order, but each fragment position can only be used once in a combination
Practice clarification
For the callable version, write an arrangement as an ordered pair of distinct indices (i, j). It forms the access code when the decimal representation of fragments[i] followed by the decimal representation of fragments[j] equals accessCode. If both orders form accessCode, count both arrangements.
Return the total number of valid arrangements.

Function
countAccessCodePairs(fragments: int[], accessCode: int) → long

Examples
Example 1
fragments = [1, 212, 12, 12]
accessCode = 1212
return = 3
The valid ordered index pairs are (0, 1), because 1 followed by 212 gives 1212, and (2, 3) plus (3, 2), because the two distinct positions containing 12 can be used in either order. The answer is 3.
Example 2
fragments = [12, 121, 21]
accessCode = 12121
return = 2
The pair (0, 1) forms 12 followed by 121, and (1, 2) forms 121 followed by 21. Both concatenations equal 12121, so the answer is 2.
Example 3
fragments = [2, 2, 2]
accessCode = 22
return = 6
Any two different positions form 22. There are 3 choices for the first position and 2 remaining choices for the second, giving 3 * 2 = 6 ordered pairs.

Constraints
Every value in fragments is a positive integer.
accessCode is a positive integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Treat accessCode as a string. A pair (i, j) works only if fragments[i] is a prefix of the code and fragments[j] is the matching suffix. So build a frequency map of each fragment as a string. Then for each fragment that is a prefix of the code, compute the remaining suffix and look it up in the map. Add the suffix's count. If the suffix equals the prefix itself, subtract 1, because you can't reuse the same index. That handles the [2, 2, 2] with 22 case: each prefix finds 2 other matches, giving 6. The common pitfall is adding the numbers or comparing as integers, which breaks on leading digits. Another is returning an int when the answer can be large, so use a long. Brute force over all pairs is O(n^2) and will time out on big inputs. The map approach is O(n * L). StealthCoder is your hedge if the counting edge case slips your mind mid-assessment.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Count Access Code Pairs 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. If you're reading this with an OA window open, you're who this was built for.

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. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Access Code Pairs FAQ

What's the trick in Count Access Code Pairs?+

Convert everything to strings and count with a hash map. For each fragment that is a prefix of accessCode, the other half must be the exact remaining suffix. Look up that suffix's frequency instead of scanning every pair. That drops the work from quadratic to roughly linear.

How do I avoid counting the same index twice?+

When the prefix fragment and the needed suffix are the same string, subtract one from the map count. That removes the current index itself. With [2, 2, 2] and 22, each of the three fragments sees 2 others, so the total is 6.

Do (i, j) and (j, i) both count?+

Yes, if both orders form accessCode. The problem says to count both arrangements. Example 1 shows this with the two 12s. Iterating over every fragment as the first half naturally counts each ordered pair once.

How hard is this problem really?+

Easy to medium. The idea is short, but the edge cases decide it: same-index reuse, ordered pairs, and a long return type. Most failures come from brute force timing out or an off-by-one on duplicates, not from the concept.

How do I prepare for this in 48 hours?+

Write the solution once from scratch. Test it on the three given examples, especially [2, 2, 2] with 22. Then practice a few prefix and suffix hash-map counting problems. That covers the pattern, and you don't need much more than that for this question.

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