Reported September 2026
LinkedInbacktracking

Permutations II

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

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

The "aab" example in this LinkedIn OA, reported September 2026, is the whole problem in miniature: three distinct strings, not six. Two identical a's can't be allowed to produce the same output twice. It's Permutations II dressed up as a string task, and the output has to come back in ascending lexicographic order. That's a backtracking problem with a duplicate guard, and the input is capped at 8 characters. If you know the trick, it's ten minutes of work. If you blank on the dedupe logic, StealthCoder is the invisible safety net running during the live OA.

The problem

Given a lowercase string s, return every distinct permutation of its characters exactly once.
Return the permutations in ascending lexicographic order. Equal characters from different input positions must not create duplicate strings.

Function
uniquePermutations(s: String) → String[]

Examples
Example 1
s = "aab"
return = ["aab","aba","baa"]
There are three distinct arrangements after duplicate swaps of the two a characters are removed.
Example 2
s = "xxyy"
return = ["xxyy","xyxy","xyyx","yxxy","yxyx","yyxx"]
The four positions have six unique arrangements because each character appears twice.
Example 3
s = "z"
return = ["z"]
A one-character string has one permutation.

Constraints
1 <= s.length <= 8.
s contains only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Sort the characters first. Then backtrack, building the string one position at a time with a used array. The dedupe rule: skip index i if s[i] equals s[i-1] and s[i-1] isn't currently used. That forces equal characters to be picked left to right, so each distinct arrangement appears once. Sorting up front also gives you lexicographic output for free, because you always try smaller characters first. The common pitfall is dedupe with a set after generating everything. It works at length 8, but it wastes work and it's what interviewers frown at. Another pitfall is getting the used[i-1] condition backwards, which silently drops valid results. Test on "aab" and "xxyy" before submitting. If your mind goes blank under the clock, StealthCoder can supply the working solution live on screen without the proctor seeing it.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Permutations II 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as permutations ii. If you have time before the OA, drill that.

⏵ The honest play

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

LinkedIn reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Permutations II FAQ

What's the trick in LinkedIn's Permutations II question?+

Sort the string, then backtrack with a used array. Skip a character if it equals the previous one and the previous one isn't used in the current path. That guarantees each distinct permutation is built exactly once, with no set needed afterward.

Do I need to sort the output separately?+

No. If you sort the characters first and always iterate candidates in index order, the permutations come out in ascending lexicographic order naturally. Check it against the xxyy example, where yyxx should be last.

How hard is this one really?+

Medium. The backtracking skeleton is standard. The only real difficulty is the duplicate-skip condition. With length capped at 8, the maximum is 40320 permutations, so performance is not the concern. Correctness of dedupe is.

Can I just use a set to remove duplicates?+

It passes at length 8, but it generates redundant work and looks weaker. The sorted skip condition is a two-line change and shows you understand the problem. Use the set only as a last-resort fallback if you can't recall the condition.

How do I prepare for this in 48 hours?+

Write Permutations I and II from scratch twice each. Focus on the used[i-1] condition and why it works. Then trace aab and xxyy by hand. Also practice combination-sum-style dedupe, since the same skip idea shows up there.

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

OA at LinkedIn?
Invisible during screen share
Get it