PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates parsing and expression-evaluation skills, specifically handling operator precedence, integer division truncation, multi-digit numbers, and whitespace handling within the Coding & Algorithms domain.

  • medium
  • Docker
  • Coding & Algorithms
  • Software Engineer

Evaluate an arithmetic expression

Company: Docker

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given a valid string expression containing non-negative integers, spaces, and the operators `+`, `-`, `*`, and `/`, return the computed result. Requirements: - The expression does not contain parentheses. - Integer division truncates toward zero. - The input may contain multi-digit numbers and arbitrary spaces. - You must handle operator precedence correctly: multiplication and division before addition and subtraction. Examples: - `"3+2*2"` -> `7` - `" 3/2 "` -> `1` - `" 3+5 / 2 "` -> `5` Discuss the time and space complexity of your approach.

Quick Answer: This question evaluates parsing and expression-evaluation skills, specifically handling operator precedence, integer division truncation, multi-digit numbers, and whitespace handling within the Coding & Algorithms domain.

Evaluate a valid expression with +, -, *, / and spaces, using precedence and truncating division toward zero.

Constraints

  • Expression has no parentheses and is valid

Examples

Input: ('3+2*2',)

Expected Output: 7

Explanation: Multiplication before addition.

Input: (' 3/2 ',)

Expected Output: 1

Explanation: Truncates toward zero.

Input: (' 3+5 / 2 ',)

Expected Output: 5

Explanation: Prompt example.

Input: ('14-3/2',)

Expected Output: 13

Explanation: Division before subtraction.

Hints

  1. Collapse multiplication/division onto the previous stack term; sum additive terms at the end.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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.