Reported October 2026
Harveygraph

Spreadsheet Formula Evaluator

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

Harvey reported this one in October 2026, and it looks bigger than it is. Strip the spreadsheet dressing and you're building a directed graph of cell dependencies with a cycle check on every write. The only operations are SET and GET, and the only operator is +. If you have an OA invite for Harvey, this is a design-flavored problem you can finish cleanly with a small amount of code. If you blank on the cycle check live, StealthCoder is the invisible safety net that gets you unstuck while the assessment keeps running.

The problem

Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines for a small spreadsheet engine.
Problem Implement a spreadsheet with cell labels such as A1 and B10. The spreadsheet supports setting cells to integers or formulas, retrieving evaluated values, and detecting cycles.
A formula is a +-separated expression containing non-negative integer literals and/or cell labels. Operators other than + are not required.
Supported commands:
SET label value: set label to an integer or formula. Return OK if the assignment does not create a dependency cycle; otherwise leave the spreadsheet unchanged and return ERROR.
GET label: return the evaluated integer value of label. Return ERROR if the cell is unset or cannot be evaluated.
Cell dependencies are evaluated lazily or eagerly as you choose, but GET must always reflect the latest committed cell values.

Function
solveSpreadsheetFormulaEvaluator(input: String) → String[]
Complete solveSpreadsheetFormulaEvaluator. It has one parameter, String input, containing newline-separated commands. Return the stdout payload as an array of lines, without trailing newline characters.

Examples
Example 1
input = "SET A1 10\nGET A1\nSET A2 A1+20\nGET A2\nSET A3 A1+A2+5\nGET A3"
return = ["OK","10","OK","30","OK","45"]
A2 references A1, and A3 references both A1 and A2.
Example 2
input = "SET A1 10\nSET B1 A1+1\nSET A1 B1+1\nGET A1\nGET B1"
return = ["OK","OK","ERROR","10","11"]
The third command would create A1 -> B1 -> A1, so it is rejected and the previous values remain active.

Constraints
Cell labels consist of uppercase letters followed by digits, such as A1 or B10.
Formula expressions only need to support addition with +.
Assignments that introduce a cycle must be rejected.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that every SET is a proposed edge change. Parse the formula into a list of terms: integer literals and cell labels. Before committing, run a DFS from each referenced label through the existing dependency map and see if you can reach the cell you're assigning. If you can, or if the formula references the cell itself, return ERROR and change nothing. That rollback rule is the common pitfall. Don't mutate state until the check passes. For GET, evaluate recursively with the stored formulas. If any referenced cell is unset, return ERROR. Lazy evaluation is fine since cycles can never be committed. Memoization is optional and gets invalidated on every SET, so skip it unless you expect heavy GET traffic. Also watch input parsing: a value like 10 is a formula with one literal, and labels are uppercase letters plus digits. If you freeze on the reachability check during the live OA, StealthCoder can hand you the DFS skeleton without the proctor seeing anything.

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 Spreadsheet Formula Evaluator 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.

Spreadsheet Formula Evaluator FAQ

How hard is the Harvey Spreadsheet Formula Evaluator really?+

Medium. The code is short, but you have to get the cycle check and the no-mutation-on-error rule right. Most of the difficulty is parsing cleanly and not overthinking it. There's no fancy algorithm, just a graph reachability test and recursive evaluation.

What's the core trick for detecting cycles?+

Before committing a SET, check whether any label in the new formula can reach the target cell through existing dependencies. Run a DFS with a visited set. If it can, or the formula references the target directly, return ERROR and leave the sheet untouched.

Should I evaluate eagerly or lazily?+

Lazy is simpler. Store each cell's raw formula and compute on GET recursively. Since you reject cycles at SET time, recursion always terminates. Eager recomputation needs reverse dependency tracking, which adds code and bug surface for no benefit here.

What edge cases break most solutions?+

Self-reference like SET A1 A1+1, referencing an unset cell inside a formula, and overwriting an existing cell with a formula that creates a cycle. In that last case you must keep the old value. Also handle plain integer values as one-term formulas.

How do I prepare in 48 hours?+

Write this once from scratch. Use a dict of label to term list, a DFS reachability function, and a recursive evaluate. Test with both examples, especially the rejected cycle in Example 2. Then do a couple of graph cycle-detection problems to keep the DFS fresh.

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