PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Evaluate an Arithmetic Expression

Last updated: May 12, 2026

Quick Overview

This question evaluates proficiency in parsing arithmetic expressions, handling unary and binary operators, parentheses, whitespace, numeric tokenization, and robust syntactic validation.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Evaluate an Arithmetic Expression

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement an expression evaluator for a simplified calculator. Given a string `s`, return the integer value of the expression. The expression may contain: - Non-negative integers - The binary operators `+` and `-` - Parentheses `(` and `)` - Arbitrary spaces Unary signs may appear at the beginning of the expression or immediately after an opening parenthesis, such as `-3 + (2 - 5)`. Examples: ```text Input: "1 + 2 - 3" Output: 0 Input: "(1 + (4 - 2)) - 3" Output: 0 Input: "-2 + (3 - 1)" Output: 0 ``` Follow-up: add string validation. Before evaluating, verify that the expression is syntactically valid. Reject expressions with invalid characters, mismatched parentheses, missing operands, consecutive binary operators, or malformed numbers. Define and document how your function reports invalid input, for example by returning an error or throwing an exception.

Quick Answer: This question evaluates proficiency in parsing arithmetic expressions, handling unary and binary operators, parentheses, whitespace, numeric tokenization, and robust syntactic validation.

Related Interview Questions

  • Thread-Safe Token-Bucket Rate Limiter - Uber (medium)
  • Group Anagrams - Uber (medium)
  • Quadtree for 2D Geospatial Points - Uber (medium)
  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
|Home/Coding & Algorithms/Uber

Evaluate an Arithmetic Expression

Uber logo
Uber
May 1, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0
Practice Read
Loading...

Implement an expression evaluator for a simplified calculator.

Given a string s, return the integer value of the expression. The expression may contain:

  • Non-negative integers
  • The binary operators + and -
  • Parentheses ( and )
  • Arbitrary spaces

Unary signs may appear at the beginning of the expression or immediately after an opening parenthesis, such as -3 + (2 - 5).

Examples:

Input:  "1 + 2 - 3"
Output: 0

Input:  "(1 + (4 - 2)) - 3"
Output: 0

Input:  "-2 + (3 - 1)"
Output: 0

Follow-up: add string validation. Before evaluating, verify that the expression is syntactically valid. Reject expressions with invalid characters, mismatched parentheses, missing operands, consecutive binary operators, or malformed numbers. Define and document how your function reports invalid input, for example by returning an error or throwing an exception.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.