Reported July 2026
Shopifysorting

Deterministic Secret Santa Assignment

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

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

Shopify reported this one in July 2026, and the title sounds scarier than it is. Deterministic Secret Santa Assignment is a sort and a wraparound, nothing more. If you've got the OA coming up in the next day or two, relax a little. The names are noise, the emails are the key, and the output is just each sorted email paired with the next one. It's an array and sorting problem dressed up as a party game. The only real work is reading the spec carefully and not overthinking it. StealthCoder sits invisibly on your screen as a safety net if your brain freezes mid-assessment.

The problem

You are given a matrix participants. Each row contains exactly two strings: [name, email].
Build the deterministic Secret Santa assignment as follows:
Sort the participants by email address in ascending lexicographic order.
For each sorted participant, assign the next participant in that order as the recipient.
The final participant assigns a gift to the first participant.
Return a matrix whose rows are [giverEmail, recipientEmail], in ascending order of giverEmail.

Function
assignSecretSanta(participants: String[][]) → String[][]

Examples
Example 1
participants = [["Mina","mina@example.com"],["Ari","ari@example.com"],["Zoe","zoe@example.com"]]
return = [["ari@example.com","mina@example.com"],["mina@example.com","zoe@example.com"],["zoe@example.com","ari@example.com"]]
The sorted email order is ari, mina, zoe. Each giver receives the next email, and the last wraps to the first.
Example 2
participants = [["Ben","b@shop.test"],["Ana","a@shop.test"]]
return = [["a@shop.test","b@shop.test"],["b@shop.test","a@shop.test"]]
With two participants, each one is assigned to the other.
Example 3
participants = [["Kai","kai@x.dev"],["Kai","a@x.dev"],["Lee","m@x.dev"],["Rae","z@x.dev"]]
return = [["a@x.dev","kai@x.dev"],["kai@x.dev","m@x.dev"],["m@x.dev","z@x.dev"],["z@x.dev","a@x.dev"]]
Names do not determine identity or order; unique email addresses do.

Constraints
2 <= participants.length <= 10^5
participants[i].length == 2
Every name and email is a non-empty ASCII string of at most 100 characters.
All email addresses are unique.

Reported by candidates. Source: FastPrep

Pattern and pitfall

What it really reduces to: pull out the emails, sort them ascending, then pair index i with index (i+1) mod n. That's the whole algorithm. Names never matter, and example 3 proves it with two people named Kai. Complexity is O(n log n) for the sort, with n up to 10^5, so nothing fancy is needed. The pitfalls are small but real. Sort by email only, not by name or the full row. Use plain lexicographic string comparison, not a locale-aware compare that might reorder characters like dots or at signs. Don't forget the wrap so the last giver points to the first. With n at least 2, you never get a self-assignment. Output rows must be in giverEmail order, which the sorted array already gives you. If you blank on the comparator or the modulo during the live OA, StealthCoder is the hedge that hands you the working code.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Deterministic Secret Santa Assignment 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Shopify reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Deterministic Secret Santa Assignment FAQ

How hard is the Shopify Secret Santa OA problem really?+

Easy. It's a sort plus a circular pairing. If you can sort strings and use modulo on an index, you can solve it. The difficulty is reading carefully, not the algorithm. Most of your time should go to edge cases and output format, not to clever ideas.

What's the trick to this problem?+

Ignore the names. Extract the emails, sort them lexicographically, then for each index i pair email[i] with email[(i+1) % n]. The modulo handles the wraparound where the last person gives to the first. That's the entire solution, and the output is already in the required order.

What time complexity should I aim for?+

O(n log n) time from sorting, and O(n) extra space for the output. With up to 10^5 participants, that's comfortable. Don't try anything quadratic like repeatedly searching for the next smallest email. A single built-in sort is exactly what the problem wants.

What mistakes break the solution?+

Sorting by name, sorting the whole row instead of just the email, forgetting the wraparound for the last giver, or using a locale-aware comparison instead of plain lexicographic order. Also watch duplicate names like the two Kais in example 3. Emails are unique, names aren't.

How do I prepare for this in 48 hours?+

Practice a few sort-and-pair problems in your chosen language, and know how to sort strings with a custom key. Write this one from scratch once, test the three examples, and check n=2. Then spend your remaining time on harder array and hash-table patterns, since this one is a warmup.

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

OA at Shopify?
Invisible during screen share
Get it