We use optional cookies for analytics and affiliate attribution. Essential cookies and marketing measurement are always on. Read our privacy policy

We just launched our Black Friday sale. You can use code BF2026 to get 25% off all subscriptions, valid until Nov 30th. There is a limit of 100 redemptions.

Logo

Expression Evaluator

What this preview is

Expression Evaluator is a medium quant coding problem on language knowledge in Cpp.

Difficulty
Medium
Topic
Language Knowledge
Discipline
Quant development
Language
Cpp

Building a recursive expression evaluator with std::variant and std::visit in C++

This is a medium-difficulty C++ problem that tests your command of modern language features: std::variant for type-safe sum types, std::unique_ptr for owning recursive data structures, and std::visit for exhaustive runtime dispatch. It is representative of the kind of systems programming work that trading firms and financial software teams encounter.

The core challenge is modeling a recursive tree where each node is one of several unrelated types — a literal value, or one of three operations — without virtual functions. You must break the recursion cycle using unique_ptr, implement ownership-transferring factory functions, and write two visitors (one for evaluation, one for string conversion) that handle all node types correctly. The problem exercises move semantics, const-correctness, and the relationship between variant and visitor — common patterns in high-performance C++ codebases.

  • Type-safe variant composition and recursive ownership
  • Visitor pattern with std::visit for exhaustive handling
  • Move semantics and unique_ptr for efficient tree construction
  • Formatting and tree traversal without modifying state

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.