Reported September 2026
Visahash table

Shortest Digit Prefix for Target Multisets

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

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

The Visa OA reported in September 2026 looks like a string problem, but it's really a position lookup. Each target is a multiset of digits, and you need the earliest prefix that covers it. You've got a 200000-character source and up to 100000 targets, so rescanning per target is a trap. If you've got an invite for this one, the whole question is how fast you can answer each target. StealthCoder sits invisibly as a safety net if you blank on the live OA, but the idea below is short enough to hold in your head.

The problem

Given a digit string digits and an array targets, return one answer per target.
The answer is the minimum prefix length of digits whose characters contain every digit of the target with at least the same multiplicity. Prefix characters that are not used by the target may be ignored, so the target may be rearranged into any permutation.
Return 0 for an empty target and -1 when the full source string lacks a required occurrence.

Function
shortestDigitPrefixes(digits: String, targets: String[]) → int[]

Examples
Example 1
digits = "012340221"
targets = ["20","42","111","9"]
return = [3,5,-1,-1]
Each answer is the latest required occurrence among that target's digits; the source has too few ones and no nine for the final targets.
Example 2
digits = "777"
targets = ["","7","77","777"]
return = [0,1,2,3]
The empty target needs no characters, while repeated sevens need successive occurrences.
Example 3
digits = "314159"
targets = ["95","13","66"]
return = [6,2,-1]
Excess prefix digits may remain unused.

Constraints
0 <= digits.length <= 200000.
1 <= targets.length <= 100000.
All strings contain only characters 0 through 9.
The combined target length is at most 200000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's what it reduces to. For each digit 0 through 9, store the list of indices where it appears in digits. For a target, count how many times each digit is needed, say k copies of digit d. The k-th occurrence of d sits at position pos[d][k-1]. The answer is the max of those positions plus one across all digits in the target. If any digit has fewer than k occurrences, return -1. If the target is empty, return 0. Total work is the source length plus the combined target length, which fits the limits easily. Common pitfalls: treating the target as ordered, so you try subsequence matching instead of multiset counting. Off-by-one between index and prefix length. Forgetting the empty target. Also don't build a prefix count array of size n by 10 and binary search unless you want extra work. Direct k-th occurrence lookup is simpler. If you freeze mid-OA, StealthCoder can hand you this approach as a hedge.

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 Shortest Digit Prefix for Target Multisets 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

⏵ The honest play

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

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

Shortest Digit Prefix for Target Multisets FAQ

What's the trick in this Visa OA problem?+

Ignore order. Record the index of every occurrence of each digit once. For each target, count needed copies per digit, take the k-th occurrence index for each, and return the largest index plus one. That's the whole solution, and it runs linearly.

How hard is this problem really?+

Easy to medium. There's no fancy data structure. The difficulty is noticing it's a multiset coverage problem and not a subsequence problem, then handling edge cases like empty targets and missing digits cleanly.

Which edge cases will break a first attempt?+

The empty target must return 0. A digit absent from the source returns -1. A digit needed more times than it appears returns -1. An empty source string with a nonempty target returns -1. Also watch the off-by-one between a zero-based index and a prefix length.

What's the time complexity I should aim for?+

O(n + total target length), where n is the digits length. Build 10 position lists in one pass, then each target costs its own length. Avoid per-target scans of the source, since 100000 targets times 200000 characters would time out.

How do I prepare in 48 hours for something like this?+

Practice the pattern of precomputing positions or counts, then answering many queries fast. Write this solution once from scratch, including the -1 and 0 cases. Test with the repeated-digit examples like 777 so the k-th occurrence logic is second nature.

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

OA at Visa?
Invisible during screen share
Get it