FastPrepSpreadsheet Formula Evaluator
Problems/Spreadsheet Formula Evaluator

Spreadsheet Formula Evaluator

Harvey logoHarvey● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are building a small spreadsheet. Its cells have labels such as A1 and B10. A cell holds either a whole number or a formula. You are given an array of commands, commands. Each entry is one command, and you run the commands in the order they appear. Return an array with one result string for each command, in the same order.

A formula is made of non-negative whole numbers and cell labels joined by +, such as A1+20 or A1+A2+5. Its value is the sum of its parts. Only + is used. A formula may use a cell that is not set yet.

The commands are:

  • SET label value: set the cell label to a whole number or a formula. If the new value does not create a dependency cycle, the result is "OK". Otherwise the sheet stays exactly as it was and the result is "ERROR".
  • GET label: the result is the value of the cell as a whole number. The result is "ERROR" if the cell was never set, or if its value cannot be worked out because the formula uses a cell that is not set.

A dependency cycle means a cell depends on itself, directly or through other cells. For example, if A1 uses B1 and B1 uses A1, that is a cycle. You may work out values when they are asked for or right when a cell is set. Either way, GET must always use the latest values.

For example, take SET A1 10, GET A1, SET A2 A1+20 and GET A2. The first SET gives "OK" and GET A1 gives "10". A2 is 10 + 20, so the second SET gives "OK" and GET A2 gives "30". The answer is ["OK", "10", "OK", "30"].

Function

runSpreadsheet(commands: String[]) → String[]

Examples

Example 1

commands = ["SET A1 10", "GET A1", "SET A2 A1+20", "GET A2", "SET A3 A1+A2+5", "GET A3"]return = ["OK", "10", "OK", "30", "OK", "45"]

SET A1 10 gives OK, and GET A1 gives 10. A2 uses A1, so A2 is 10 + 20 = 30. A3 uses A1 and A2, so A3 is 10 + 30 + 5 = 45. Every command gives one result, so the answer is ["OK", "10", "OK", "30", "OK", "45"].

Example 2

commands = ["SET A1 10", "SET B1 A1+1", "SET A1 B1+1", "GET A1", "GET B1"]return = ["OK", "OK", "ERROR", "10", "11"]

A1 is 10, and B1 is A1 + 1 = 11. The third command would make A1 use B1. That is a cycle, because B1 already uses A1, so it gives ERROR and nothing changes. GET A1 still gives 10 and GET B1 still gives 11. The answer is ["OK", "OK", "ERROR", "10", "11"].

Constraints

  • Cell labels are uppercase letters followed by digits, such as A1 or B10.
  • Each command is SET label value or GET label, with single spaces between the parts.
  • A formula only needs addition with +. It is non-negative whole numbers (written without leading zeros) and cell labels joined by +, with no spaces.

More Harvey interview questions

  • Highlight and Rank Overlapping CitationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Duplicate Files in a FilesystemPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Highlight Matching PhrasesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • File System Shell CommandsONSITE INTERVIEW · Seen Nov 2026
  • Retrieve Vectors by Cosine SimilarityONSITE INTERVIEW · Seen Nov 2026
  • In-Memory Vault File SystemONSITE INTERVIEW · Seen Nov 2026
  • Evaluate an Expression MapONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Course Ordering with Concurrent UpdatesNuro · PHONE SCREENNuro interview questions
  • Order Validator Rule DAGByteDance · PHONE SCREENByteDance interview questions
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • Propagate Spreadsheet Cell UpdatesOpenAI · PHONE SCREENOpenAI interview questions
  • Parallel Courses IIISnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
  • Spreadsheet Formula DependenciesCitadel · PHONE SCREENCitadel interview questions
  • Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
  • Course Order and CycleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Choose a Road to Maximize Average Route Toll IncreaseHarness · PHONE SCREEN

Interview reports that mention this question

  • Harvey MLE Phone Screen and Virtual Onsite: 1 Experience

Harvey interview experiences

  • Harvey Experienced SWE Phone Screen: 1 Experience
All Harvey interview questionsSee Harvey hiring insights
Saved
class Solution {
    public String[] runSpreadsheet(String[] commands) {
        // write your code here
    }

}
Checking account…