Reported September 2026
Salesforcestack

Flatten Nested Map Paths with a Stack

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

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

A stack is what this Salesforce OA question, reported in September 2026, hinges on. You get a token stream like a{, b{, c=1, }, and you have to spit out dotted paths for every leaf. It looks like parsing, but it's really bookkeeping. Push a key when a map opens, pop when it closes, and build the path at each leaf. If you've got an OA invite and 48 hours, this is a clean pattern to lock in. StealthCoder sits invisible on your screen as a safety net if you blank mid-assessment, but the logic here is short enough to own.

The problem

tokens encode a nested ordered map:
key{ opens a nested map under key.
} closes the current map.
key=value is a leaf; value may be a scalar or a bracketed list such as [x,y].
Return every leaf in encounter order as parent.child.key=value, including all parent keys.

Function
flattenNestedMap(tokens: String[]) → String[]

Examples
Example 1
tokens = ["a{","b{","c=1","}","d=2","}"]
return = ["a.b.c=1","a.d=2"]
The path stack contains a,b for c and only a for d.
Example 2
tokens = ["root{","items=[x,y]","}"]
return = ["root.items=[x,y]"]
A list value is retained as one leaf value.
Example 3
tokens = ["x=1","y=2"]
return = ["x=1","y=2"]
Top-level leaves have no parent prefix.

Constraints
1 <= tokens.length <= 10^5.
The token stream is balanced and valid; keys are nonempty and contain no dots or delimiters.
Leaf values are nonempty and contain no equals sign.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is one stack of keys that mirrors your current nesting depth. For a token ending in {, strip the brace and push the key. For a token that is exactly }, pop. Otherwise it's a leaf: split on the first equals sign, join the stack with dots, append the key, then add =value. Output order falls out naturally because you process tokens left to right. The pitfalls are small but real. Don't split on every equals sign, and don't split list values like [x,y] on commas, since the list stays one leaf value. Top-level leaves need no prefix, so handle an empty stack. Don't rebuild the joined path from scratch in a way that goes quadratic on deep input with 10^5 tokens. Keep it linear in practice. If your mind goes blank live, StealthCoder is the hedge, but the stack idea is the whole problem.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Flatten Nested Map Paths with a Stack 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Salesforce reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Flatten Nested Map Paths with a Stack FAQ

How hard is the Salesforce flatten nested map problem really?+

Easy to medium. There's no clever algorithm, just a stack and careful token handling. Most people lose points on edge cases like top-level leaves with no prefix or list values containing commas, not on the core idea. If you know stacks, you finish fast.

What's the trick to solving it?+

Keep a stack of keys for the current nesting path. Push on a token ending in {, pop on }, and treat anything else as a leaf. At a leaf, join the stack with dots, add the key, and append =value. One pass, left to right.

How do I tell a leaf from an opener?+

Check the token shape. A token that ends with { opens a map, and its key is everything before the brace. A token that equals } closes one. Anything else contains an equals sign and is a leaf. Check the closer first so you don't misread it.

Do I need to parse the list values like [x,y]?+

No. Per the examples, a list value is kept as one leaf value, so root.items=[x,y] comes out verbatim. Split the token only on the first equals sign and keep the rest as the value string untouched.

How do I prepare for this in 48 hours?+

Write the solution once from scratch, then test it on the three examples plus a deeply nested case and a top-level-only case. Also do two or three related stack problems like valid parentheses or decode string. That covers the pattern well enough for this OA.

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

OA at Salesforce?
Invisible during screen share
Get it