Reported September 2026
Harveyhash table

Evaluate an Expression Map

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

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

The edge case that breaks a naive solution on Harvey's Evaluate an Expression Map, reported September 2026, is a symbol that references one defined later in the list. Evaluate top to bottom and you crash on the first forward reference. This is a hash table plus dependency resolution problem with a cycle check bolted on. With up to 10^5 definitions, recursion depth and repeated recomputation will both hurt you. If you blank during the live OA, StealthCoder runs invisibly on your screen and gives you a working structure in real time. Here's the shape of the solution so you don't need it.

The problem

You are given symbol definitions in the form name=expression. An expression may contain integer constants, references to previously defined or later defined symbols, and the binary operators +, -, *, and /.
Evaluate the final integer value of every symbol. Return the results in the same order as the input definitions, formatted as "name=value".
If the dependency graph contains a cycle, return a single-element array ["CYCLE"] instead of partial results.

Function
evaluateExpressionMap(definitions: String[]) → String[]
Complete the function evaluateExpressionMap in the editor below.
evaluateExpressionMap has the following parameter:
String[] definitions: the symbol definitions
Returns String[]: evaluated symbol assignments in input order, or ["CYCLE"] if a cycle exists.

Examples
Example 1
definitions = ["a=1", "b=a+2", "c=b*3"]
return = ["a=1", "b=3", "c=9"]
Each symbol depends only on earlier evaluated values, so the map resolves cleanly.
Example 2
definitions = ["a=b+1", "b=a+1"]
return = ["CYCLE"]
The definitions form a cycle, so the special cycle marker is returned.

Constraints
1 <= definitions.length <= 10^5
Expressions use integer arithmetic and may reference other symbols.
Use cycle detection to avoid infinite recursion.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Parse each definition into a name and an expression, and store them in a hash map. Then resolve each symbol with DFS and memoization, using three states per node: unvisited, visiting, done. If you hit a node that's still visiting, you found a cycle, so return ["CYCLE"] immediately with no partial results. Alternatively, build the dependency graph and run a topological sort, which avoids deep recursion at 10^5 nodes. The pitfalls are concrete. Forward references break a single linear pass. Recursion depth can blow the stack on a long chain. Division needs a decision on integer semantics, so check how the statement treats it. Tokenize operators carefully and respect precedence. Return results in input order, not evaluation order. StealthCoder is the hedge if the parser or the cycle logic slips under live pressure, but the three-state DFS is the core idea.

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 Evaluate an Expression Map 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

⏵ The honest play

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

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

Evaluate an Expression Map FAQ

What's the trick in Evaluate an Expression Map?+

Treat it as a dependency graph. Store definitions in a hash map, resolve each symbol with memoized DFS, and track a visiting state to catch cycles. Forward references work naturally because you resolve on demand instead of in input order.

How do I detect the cycle correctly?+

Use three states: unvisited, visiting, done. If DFS reaches a symbol marked visiting, you're in a cycle. Return ["CYCLE"] for the whole input, not partial results. A simple visited set isn't enough because shared dependencies aren't cycles.

Will recursion be a problem with 10^5 definitions?+

It can be. A long chain like a1=a2+1, a2=a3+1 produces very deep recursion and may overflow the stack. Use an iterative DFS or Kahn's topological sort with in-degree counts to stay safe at this size.

How hard is this one really?+

Medium. The graph idea is standard, but expression parsing, operator precedence, and the cycle rule make it fiddly. Most mistakes come from output ordering and forgetting forward references, not from the core algorithm.

How do I prepare in 48 hours?+

Write a memoized DFS with cycle states from scratch, then a small tokenizer that handles +, -, *, / with precedence. Test a forward reference, a self-reference, and a long chain. That covers the failure modes in this problem.

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

OA at Harvey?
Invisible during screen share
Get it