PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Design LCA and find K closest points

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of tree algorithms (LCA using parent pointers) and selection algorithms (sorting, max-heap, quickselect), emphasizing data structures, algorithmic correctness, and time/space complexity within the Coding & Algorithms domain.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Design LCA and find K closest points

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Part A — LCA with parent pointers: You are given two nodes a and b in a rooted tree where each node has a parent pointer (you may or may not have direct access to the root). Design and implement lowestCommonAncestor(a, b) that returns their lowest common ancestor without modifying the nodes. Aim for O(h) time and O( 1) extra space, where h is the height of the tree. Follow-up: State the time and space complexity of your approach. Part B — Return k closest points: You are given an array of n 2D integer points and an integer k (1 ≤ k ≤ n). Return any order of the k points closest to the origin by Euclidean distance (you may compare squared distances). Tasks: 1) Implement a baseline that sorts all points by distance and returns the first k. 2) Propose and implement a more efficient method when k ≪ n using either: - A size-k max-heap maintained while scanning the points, or - Quickselect partitioning to position the kth smallest distance and then collect any k closest points. 3) Define the minimal heap interface you will use (e.g., insert, peek, pop, size, comparator) and show how your solution uses it. Follow-up: For each approach, analyze time and space complexity and compare the trade-offs.

Quick Answer: This question evaluates understanding of tree algorithms (LCA using parent pointers) and selection algorithms (sorting, max-heap, quickselect), emphasizing data structures, algorithmic correctness, and time/space complexity within the Coding & Algorithms domain.

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
Software Engineer
Technical Screen
Coding & Algorithms
1
0

Part A — LCA with parent pointers: You are given two nodes a and b in a rooted tree where each node has a parent pointer (you may or may not have direct access to the root). Design and implement lowestCommonAncestor(a, b) that returns their lowest common ancestor without modifying the nodes. Aim for O(h) time and O(

  1. extra space, where h is the height of the tree. Follow-up: State the time and space complexity of your approach.

Part B — Return k closest points: You are given an array of n 2D integer points and an integer k (1 ≤ k ≤ n). Return any order of the k points closest to the origin by Euclidean distance (you may compare squared distances). Tasks:

  1. Implement a baseline that sorts all points by distance and returns the first k.
  2. Propose and implement a more efficient method when k ≪ n using either:
    • A size-k max-heap maintained while scanning the points, or
    • Quickselect partitioning to position the kth smallest distance and then collect any k closest points.
  3. Define the minimal heap interface you will use (e.g., insert, peek, pop, size, comparator) and show how your solution uses it. Follow-up: For each approach, analyze time and space complexity and compare the trade-offs.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software 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.