Reported September 2025
Goldman Sachsdynamic programming

Lock Code

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

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

Goldman Sachs asked this in September 2025 and it's a constraint-satisfaction problem disguised as a lock puzzle. You're given a numeric code with rules about which digits can appear where, and you need to count valid combinations or reconstruct the code. It's not a brute-force problem. The trap is overthinking the constraints. StealthCoder can help you pattern-match the rule set in real time if you freeze on the logic.

Pattern and pitfall

Lock Code is fundamentally a counting or validation problem wrapped in a physical metaphor. The core pattern involves interpreting lock constraints (usually digit adjacency, range restrictions, or positional rules) and either enumerating valid codes or determining if a given code satisfies all constraints. The trick is parsing the rules cleanly and avoiding nested loops when dynamic programming or mathematical counting works. Common pitfall: testing every possible combination instead of pruning the search space early. If the problem asks you to count valid codes, think combinatorics first. If it asks you to validate or reconstruct, think constraint propagation. StealthCoder can help you read the exact rule set and match it to the right algorithm pattern when pressure hits.

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 Lock Code 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 Goldman Sachs's OA.

Goldman Sachs 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.

Lock Code FAQ

Is this a brute-force problem or is there a math shortcut?+

Usually a math shortcut. Parse the constraints carefully. If digits are independent across positions, multiply the valid counts per position. If they're linked (e.g., adjacent digits must differ), use dynamic programming or graph coloring. Brute force fails on large code lengths.

What's the most common mistake on Lock Code?+

Misreading the constraint grammar. Phrases like 'no adjacent digits match' or 'digit X must precede digit Y' need exact parsing. Spend 2 minutes writing out the rules in pseudocode before coding. One misread ruins the whole solution.

Do I need to actually generate all valid codes or just count them?+

Re-read the problem. If it asks 'how many', you count (combinatorics or DP). If it asks 'find the code' or 'validate this code', you construct or check. Goldman Sachs often asks for the count, not the list.

How do I handle digit restrictions by position?+

Model each position as a state. Use DP where dp[pos][last_digit] = number of valid ways to fill positions up to pos, where last_digit is the digit used at pos-1. Transition only through digits allowed at position pos that respect constraints.

Is this still a common pattern at Goldman Sachs?+

Yes. Constraint satisfaction and counting problems stay popular in their OA. If you see a lock, code, or sequence problem with explicit rules, expect this pattern. Study constraint propagation and DP on digit sequences before your OA.

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

OA at Goldman Sachs?
Invisible during screen share
Get it