PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Implement exponentiation and link tree neighbors

Last updated: Mar 29, 2026

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.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Maze and Suffix Problems - Meta (medium)
Meta logo
Meta
Sep 6, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
1
0

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.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.