← HubSpot Interview Insights

HubSpot·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Round 3 at HubSpot was a coding interview built around a JSON parsing calculator problem, with four progressive parts that got increasingly tricky. Parts 1 and 2 went fine with recursion, but Part 3 blindsided me on something I should've known cold.

Questions Asked (4)

Q1

Given a JSON string where each node has a type field indicating either a literal number or an arithmetic operation (+, -, *, /), implement a calculator that evaluates the expression. Start with flat (non-nested) expressions involving two numbers.

API & IntegrationsAlgorithms & Data Structures
Author's notes

This part was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the JSON structure and expected input/output, then design a recursive evaluator that handles the base case of a literal number and recursively evaluates operation nodes. Implement the solution with clean separation of concerns, and discuss how to extend it to nested expressions and error handling.

Pro tip: Mention that you would use a recursive descent approach because it naturally handles nested expressions, and proactively discuss edge cases like division by zero and invalid operation types to show production-level thinking.

1. Clarify Requirements and Constraints

Ask about the JSON schema, whether expressions can be nested, what operations to support, and how to handle errors or invalid input. Confirm the expected output type (e.g., number).

2. Design the Recursive Evaluator

Define a function that takes a node: if it's a literal, return its value; if it's an operation, recursively evaluate its operands and apply the operator. This handles both flat and nested cases uniformly.

3. Implement with Clean Code

Write the evaluator with clear separation of parsing and evaluation, use a map for operators, and include input validation. For the initial flat case, you can simplify but keep the structure extensible.

4. Test and Handle Edge Cases

Test with simple expressions, then nested ones. Cover division by zero, unknown operators, missing fields, and type mismatches. Discuss how to return errors gracefully.

5. Discuss Extensions and Trade-offs

Talk about supporting more operations, variables, or parsing from a string. Compare recursive vs. iterative (stack-based) approaches and mention performance considerations.

Key Points to Mention

  • Recursive evaluation naturally handles nested expressions and is easy to extend.
  • Use a dictionary/map to dispatch operations instead of long if-else chains.
  • Validate input: check for required fields, correct types, and valid operators.
  • Handle division by zero and other arithmetic errors explicitly.
  • Separate parsing (JSON to AST) from evaluation for better testability.
  • Consider iterative stack-based evaluation for very deep expressions to avoid stack overflow.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Extend the calculator to handle arbitrarily nested JSON expressions, for example evaluating 1 + (1 + 2) where inner nodes are themselves full expression objects.

Algorithms & Data StructuresAPI & Integrations
Author's notes

Recursion made this pretty clean once I had Part 1 working.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the JSON schema for expressions (e.g., leaf nodes vs. operator nodes) and then propose a recursive evaluation function that handles both cases. Emphasize that recursion naturally mirrors the nested structure, and discuss how to handle errors and edge cases.

Pro tip: Mention that recursion depth could be an issue for deeply nested expressions, and suggest an iterative approach with an explicit stack as an alternative if needed. This shows you consider scalability and robustness beyond the basic solution.

1. Clarify the JSON schema

Ask or state assumptions about the structure: e.g., leaf nodes have a 'value' field, operator nodes have 'operator', 'left', and 'right' fields. Confirm that operators are binary and that nesting can be arbitrary.

2. Design a recursive evaluator

Write a function that takes an expression node. If it's a leaf, return its value. If it's an operator, recursively evaluate left and right, then apply the operator.

3. Handle operators and errors

Map operators to functions (e.g., +, -, *, /). Include error handling for unknown operators, division by zero, or invalid node types.

4. Test with examples

Walk through the given example (1 + (1 + 2)) and maybe a deeper nested case to demonstrate correctness. Mention edge cases like single leaf or deeply nested expressions.

5. Discuss complexity and alternatives

Analyze time and space complexity (O(n) time, O(d) space where d is depth). Mention iterative approach with explicit stack to avoid recursion limits.

Key Points to Mention

  • Recursive structure of JSON expressions and base case for leaf nodes
  • Operator mapping and evaluation order (left-to-right, respecting parentheses via tree structure)
  • Error handling for invalid operators, malformed nodes, and division by zero
  • Time and space complexity: O(n) time, O(d) space for recursion depth
  • Potential stack overflow for deep nesting and iterative alternative
  • Testing strategy: unit tests for various nesting levels and operators

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Deserialize the raw JSON string directly into a typed Java object (with getters and setters) using a JSON library, rather than working with a generic tree structure.

API & IntegrationsTechnical Trade-offs
Author's notes

This is where things fell apart.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the benefits of deserializing directly into a typed object, such as type safety and cleaner code. Then, walk through the steps using a popular library like Jackson or Gson, highlighting how to map JSON fields to Java fields and handle potential mismatches. Finally, discuss error handling and validation to ensure robustness.

Pro tip: Mention that using annotations like @JsonProperty or @SerializedName can handle field name mismatches, and consider using @JsonIgnoreProperties(ignoreUnknown = true) to future-proof against API changes.

1. Choose the right library

Select a JSON library that supports direct deserialization, such as Jackson or Gson, and explain why it's suitable for the task.

2. Define the Java class

Create a POJO with fields matching the JSON structure, including getters and setters, and add necessary annotations for field mapping.

3. Perform deserialization

Use the library's API to convert the JSON string directly into an instance of the Java class, e.g., objectMapper.readValue(jsonString, MyClass.class).

4. Handle exceptions and validation

Catch and handle exceptions like JsonProcessingException, and validate the deserialized object to ensure data integrity.

5. Discuss trade-offs

Compare direct deserialization with using a generic tree model, highlighting advantages like type safety and disadvantages like rigidity.

Key Points to Mention

  • Type safety and compile-time checks
  • Reduced boilerplate code compared to manual parsing
  • Handling of nested objects and arrays
  • Use of annotations for custom field mapping
  • Error handling for malformed JSON or missing fields
  • Performance considerations and library choice

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Further extend the calculator to support variable references (e.g. x, y, z) that can be looked up and substituted during evaluation.

Algorithms & Data Structures
Author's notes

Didn't actually get here but the answer is pretty obvious in retrospect: just keep a map of variable names to values and do a lookup when the type field indicates a variable.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the requirements: how variables are defined (e.g., via assignment or an environment), whether they can be redefined, and how errors are handled. Then, extend the existing parser and evaluator to recognize identifiers and resolve them through a symbol table or environment during evaluation. Finally, discuss edge cases like undefined variables, scoping, and potential optimizations.

Pro tip: Mention that you would separate parsing from evaluation: the parser produces an AST with variable nodes, and the evaluator resolves them using an environment. This clean separation makes the design extensible and testable.

1. Clarify Requirements

Ask about variable definition syntax (e.g., assignment statements), whether variables can be reassigned, and how errors (like undefined variables) should be handled.

2. Extend the Parser

Modify the tokenizer to recognize identifiers and the parser to produce variable reference nodes in the AST, ensuring operator precedence and grammar remain correct.

3. Design Evaluation with Environment

Introduce an environment (e.g., a map) that stores variable values. During evaluation, look up variable names in the environment and substitute their values.

4. Handle Edge Cases and Errors

Decide behavior for undefined variables (e.g., throw an error), support variable reassignment if needed, and consider scoping if the calculator supports functions or blocks.

5. Test and Optimize

Write tests for variable lookup, reassignment, and error cases. Discuss potential optimizations like caching or constant folding if variables are immutable.

Key Points to Mention

  • Symbol table or environment for variable storage and lookup
  • AST modification to include variable nodes
  • Error handling for undefined variables
  • Scoping rules (if applicable) and variable shadowing
  • Separation of parsing and evaluation phases
  • Testing strategy for variable substitution and edge cases

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.