Implement power and balance-parentheses algorithms
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithmic design and analysis skills, covering fast exponentiation with attention to numerical edge cases and precision, and minimal-removal parentheses balancing with string-processing and data-structure reasoning.
Fast Exponentiation by Squaring
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (2, 10)
Expected Output: 1024.0
Explanation: Positive exponent.
Input: (2, -2)
Expected Output: 0.25
Explanation: Negative exponent.
Input: (0, 0)
Expected Output: 1.0
Explanation: Conventional programming result.
Input: (-2, 3)
Expected Output: -8.0
Explanation: Negative base.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.
Minimum Remove to Balance Parentheses
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ('lee(t(c)o)de)',)
Expected Output: 'lee(t(c)o)de'
Explanation: Remove extra close.
Input: ('a)b(c)d',)
Expected Output: 'ab(c)d'
Explanation: Remove unmatched close.
Input: ('))((',)
Expected Output: ''
Explanation: Remove all parentheses.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.