Solve String Addition and Expression Evaluation
Company: Bytedance
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
The interview included two coding problems:
1. **Add numbers from character arrays**
- You are given two non-empty character arrays, where each array represents a non-negative integer in decimal form.
- Each element is a digit character such as `'0'` through `'9'`.
- Return the sum as a string.
- You may not convert the entire input directly into a built-in integer type.
Example:
- Input: `['1','2','3']`, `['9','9']`
- Output: `"222"`
2. **Evaluate a basic arithmetic expression**
- You are given a string expression containing non-negative integers, spaces, and the operators `+`, `-`, `*`, and `/`.
- Evaluate the expression and return the integer result.
- Operator precedence should be respected: multiplication and division before addition and subtraction.
- Integer division truncates toward zero.
- The expression is guaranteed to be valid and contains no parentheses.
Example:
- Input: `"3+2*2"`
- Output: `7`
- Input: `" 14-3/2 "`
- Output: `13`
Quick Answer: This question evaluates string manipulation and parsing skills for numeric computation, covering addition of integers represented as character arrays and correct evaluation of arithmetic expressions with operator precedence.