Pass functions and analyze basic data structures
Company: eBay
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates proficiency with higher-order functions, passing functions or delegates, closures, and reasoning about side effects, alongside the ability to analyze fundamental data structures and their performance characteristics.
Read the full eBay Software Engineer interview experience this question came from
Constraints
- 0 <= len(ops) <= 100
- Each op is one of: 'add v', 'mul v', 'pow e', 'neg', 'abs'
- v is a signed 64-bit integer; e is an integer in [0, 9]
- x is a signed 64-bit integer
- Apply operations left-to-right; 'pow e' uses integer exponentiation
- If ops is empty, return x (identity)
Hints
- Parse each operation by splitting on whitespace; handle negative constants (e.g., 'add -5').
- Apply operations sequentially to build f(x); then apply the same sequence again to f(x).
- Consider creating a helper that applies ops once to a value.
- If ops is empty, the identity function is applied twice, so return x.
- Treat operations as pure (no side effects) so applying twice is deterministic.