PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Solve four algorithmic problems

Last updated: Mar 29, 2026

Quick Overview

This multi-part question evaluates algorithmic problem-solving and data-structure proficiency across string processing (validating parentheses with minimal deletions), tree operations (lowest common ancestor using parent pointers), nested-structure traversal and accumulation (depth-weighted sum), and geometric selection/ordering (k closest points).

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve four algorithmic problems

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Solve the following coding tasks. For each, describe your approach, complexity, and handle edge cases. ### 1) Make parentheses string valid with minimal deletions **Input:** a string `s` containing lowercase letters and parentheses `'('`, `')'`. **Task:** Remove the minimum number of characters so the resulting string has **valid parentheses** (every closing parenthesis matches a previous unmatched opening parenthesis, and parentheses are properly nested). Return **any** valid result. **Constraints (typical):** `1 <= len(s) <= 1e5`. --- ### 2) Lowest common ancestor with parent pointers You are given two nodes `p` and `q` in a tree where each node has a pointer to its `parent` (and optionally `left/right` if it’s a binary tree). **Task:** Return their **lowest common ancestor** (the deepest node that is an ancestor of both). You may assume both nodes belong to the same tree. **Constraints (typical):** up to `1e5` nodes. --- ### 3) Weighted sum of a nested integer list **Input:** a nested list structure where each element is either an integer or a nested list (arbitrary depth). **Task:** Compute the **depth-weighted sum**: each integer is multiplied by its depth (top-level depth = 1). Example: `[1,[4,[6]]]` → `1*1 + 4*2 + 6*3 = 27`. --- ### 4) K closest points to the origin **Input:** an array of points `points[i] = (xi, yi)` and an integer `k`. **Task:** Return any `k` points with the smallest Euclidean distance to the origin (distance comparison can use squared distance `xi^2 + yi^2`). **Constraints (typical):** `1 <= n <= 1e5`. **Note:** If distances tie, any order is acceptable unless specified otherwise.

Quick Answer: This multi-part question evaluates algorithmic problem-solving and data-structure proficiency across string processing (validating parentheses with minimal deletions), tree operations (lowest common ancestor using parent pointers), nested-structure traversal and accumulation (depth-weighted sum), and geometric selection/ordering (k closest points).

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
Oct 12, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

Solve the following coding tasks. For each, describe your approach, complexity, and handle edge cases.

1) Make parentheses string valid with minimal deletions

Input: a string s containing lowercase letters and parentheses '(', ')'.

Task: Remove the minimum number of characters so the resulting string has valid parentheses (every closing parenthesis matches a previous unmatched opening parenthesis, and parentheses are properly nested). Return any valid result.

Constraints (typical): 1 <= len(s) <= 1e5.

2) Lowest common ancestor with parent pointers

You are given two nodes p and q in a tree where each node has a pointer to its parent (and optionally left/right if it’s a binary tree).

Task: Return their lowest common ancestor (the deepest node that is an ancestor of both). You may assume both nodes belong to the same tree.

Constraints (typical): up to 1e5 nodes.

3) Weighted sum of a nested integer list

Input: a nested list structure where each element is either an integer or a nested list (arbitrary depth).

Task: Compute the depth-weighted sum: each integer is multiplied by its depth (top-level depth = 1).

Example: [1,[4,[6]]] → 1*1 + 4*2 + 6*3 = 27.

4) K closest points to the origin

Input: an array of points points[i] = (xi, yi) and an integer k.

Task: Return any k points with the smallest Euclidean distance to the origin (distance comparison can use squared distance xi^2 + yi^2).

Constraints (typical): 1 <= n <= 1e5.

Note: If distances tie, any order is acceptable unless specified otherwise.

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.