PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates numerical algorithm implementation and in-place tree traversal skills, specifically fast exponentiation with careful edge-case and precision handling and iterative linking of next pointers in a perfect binary tree.

  • Medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Implement exponentiation and link tree neighbors

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Solve two independent tasks. Task A — Fast exponentiation: Implement fastExponent(x, n) that returns x raised to the integer power n, where x is a double and n is a 32-bit signed integer. Requirements: O(log |n|) time via exponentiation by squaring; O( 1) extra space with an iterative approach; correctly handle negative exponents, n == Integer.MIN_VALUE, and edge cases such as x == 0 or x == ±1. Return a double; a relative error up to 1e-10 is acceptable. Task B — Link neighbors in a perfect binary tree: Given the root of a perfect binary tree whose nodes have fields (val, left, right, next), set each node’s next pointer to its immediate right neighbor on the same level; if none, set it to null. Constraints: O(n) time, O( 1) extra space, and do not use recursion. Afterward, each level should be traversable using next pointers starting from its leftmost node.

Quick Answer: This question evaluates numerical algorithm implementation and in-place tree traversal skills, specifically fast exponentiation with careful edge-case and precision handling and iterative linking of next pointers in a perfect binary tree.

Fast Exponentiation

Return x raised to integer n using exponentiation by squaring.

Examples

Input: (2.0, 10)

Expected Output: 1024.0

Explanation: Positive exponent.

Input: (2.0, -2)

Expected Output: 0.25

Explanation: Negative exponent.

Input: (1.5, 0)

Expected Output: 1.0

Explanation: Zero exponent.

Input: (-2.0, 3)

Expected Output: -8.0

Explanation: Negative base.

Link Neighbors in a Perfect Binary Tree

For a perfect tree represented level-order, return each node's next value or None.

Examples

Input: ([1, 2, 3, 4, 5, 6, 7],)

Expected Output: [None, 3, None, 5, 6, 7, None]

Explanation: Three levels.

Input: ([1],)

Expected Output: [None]

Explanation: Single root.

Input: ([],)

Expected Output: []

Explanation: Empty tree.

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)