Reported August 2024
Rubrikstring

Friendship String

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

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

Rubrik's August OA hit candidates with Friendship String, a string manipulation problem that looks deceptively simple until you realize the core trick. You're likely facing a pattern where adjacent characters or substring relationships matter more than you'd think at first glance. This is the kind of problem where the naive approach fails on edge cases, and StealthCoder acts as your safety net if you blank on the optimization during the live assessment.

Pattern and pitfall

Friendship String is almost certainly asking you to identify or construct strings where characters have some defined 'friendship' relationship, likely meaning adjacent characters must satisfy a constraint. The trap is overthinking the global structure when the answer often hinges on greedy character selection or understanding when a valid string is impossible. Most candidates try to build the string left-to-right without checking if future placements get blocked. The real pattern is usually string construction with constraint propagation, sometimes solvable with a greedy pass or by recognizing a parity or balance condition. StealthCoder can feed you the working pattern instantly if you're stuck on the iteration logic.

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 Friendship String 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 Rubrik's OA.

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

Friendship String FAQ

Is this a greedy problem or do I need dynamic programming?+

Usually greedy. Build the string character-by-character, always picking the lexicographically smallest valid next character. DP is overkill unless the problem explicitly asks for counting valid strings, not constructing one.

What's the main constraint I should watch for?+

Adjacent characters almost certainly have a rule: they can't be the same, can't be too close in ASCII value, or must satisfy some distance metric. Read the problem twice to nail down this exact rule before you code.

How do I know if a valid string is impossible?+

Check if the constraint creates a bottleneck. If you have n characters to place and only 2 valid choices per position, you'll often hit a dead end. Test small cases manually to spot the impossibility pattern.

Should I pre-sort the input or use a frequency map?+

Frequency map is your friend. Count available characters, then greedily pick the character with the highest remaining count that doesn't violate the friendship rule with the last placed character.

Is there a mathematical condition I'm missing?+

Sometimes yes. If one character dominates the frequency, the problem becomes unsolvable. The trick is often: if max_freq > (total_length + 1) / 2, answer is impossible.

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

OA at Rubrik?
Invisible during screen share
Get it