Reported April 2024
Nutanixgreedy

No Adjacent Characters

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

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

Nutanix asked this in April 2024, and it's a constraint-satisfaction problem that trips up candidates who overthink it. You have a string or set of characters, and you need to arrange or filter them so no two identical (or sometimes adjacent in value) characters sit next to each other. The trick is recognizing whether you're building a valid sequence or counting valid arrangements. StealthCoder will pattern-match this instantly if you blank on the greedy or heap approach during the live OA.

Pattern and pitfall

The core pattern is greedy with a max-heap or frequency counter. You pick the character with the highest remaining count, place it, then move to the next highest available. If no character can be placed without violating the adjacency rule, you either return failure or use a secondary character to 'buffer'. The pitfall is assuming a simple sort works, it doesn't. The real constraint is that at each step, the most frequent character must be placed smartly, or the string becomes impossible to build. This is a weighted greedy problem, not a permutation search. StealthCoder reads the exact constraint and suggests the heap-plus-buffer pattern in real time, so you don't waste 15 minutes on a backtracking dead end.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill No Adjacent Characters 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

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

⏵ The honest play

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

Nutanix reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

No Adjacent Characters FAQ

Is this just rearranging a string, or building it from scratch?+

Depends on the exact input, but typically you're building a valid sequence given a character set and frequency. If it says 'rearrange', you must use all characters exactly once. Check the problem statement carefully. The algorithm is the same, but the output shape matters.

Does 'no adjacent' mean identical characters only, or any characters?+

Almost always identical characters. Very rarely it means adjacent by ASCII value or a given rule. The problem text will be explicit. If it's ambiguous in the OA, re-read the example. The constraint rule is everything.

What if it's impossible to build a valid string?+

Return an empty string, or false, or -1 depending on the ask. If the most frequent character appears more than ceil(n/2) times, it's impossible. Check this early to avoid unnecessary computation.

Is a heap always required, or can I use a frequency map and two pointers?+

Heap is cleaner for always grabbing the max-frequency character, but a frequency map plus sorting on each iteration works too. Heap is O(n log k) where k is alphabet size. Pick whichever you code faster under pressure.

How do I prepare in 48 hours if I've never seen this?+

Understand the max-heap greedy pattern. Write pseudo-code: extract top two frequencies, place them, push back. Practice one example by hand. Know the impossibility rule (freq > (n+1)/2). That's the floor. StealthCoder handles the edge cases live.

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

OA at Nutanix?
Invisible during screen share
Get it