PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Implement power and balance-parentheses algorithms

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Design and implement two algorithms: 1) Fast exponentiation: Implement a function pow(x, n) that returns a real number x raised to an integer exponent n using exponentiation by squaring in O(log |n|) time. Handle negative exponents, x = 0, n = 0, very large |n|, and discuss iterative vs. recursive trade-offs and numerical precision. Analyze time and space complexity. 2) Minimal-removal parentheses balancing: Given a string s consisting of lowercase letters and parentheses '()' only, remove the minimum number of parentheses to make s valid (properly nested). Return any one valid result. Provide an O(n) solution; compare a stack-based approach to a two-pass marking approach; justify minimality and analyze time and space complexity.

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

Return x raised to integer n using 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

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.

Minimum Remove to Balance Parentheses

Remove the minimum number of parentheses to make s valid, preserving other characters.

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

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
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.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)