PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Determine feasibility and clean parentheses string

Last updated: Mar 29, 2026

Quick Overview

This pair of problems evaluates proficiency with graph algorithms (dependency modeling and cycle detection/topological ordering) and string processing (parentheses balancing and minimal-edit transformations), focusing on algorithmic thinking, data-structure usage, and efficient linear-time solutions.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Determine feasibility and clean parentheses string

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given two independent coding tasks. ## 1) Check if all courses/tasks can be completed You have `n` courses labeled `0..n-1` and a list of prerequisite pairs `prereq`. - Each pair `[a, b]` means: to take course `a`, you must finish course `b` first. - Return `true` if it is possible to finish all `n` courses (i.e., there is no prerequisite cycle). Otherwise return `false`. **Input** - Integer `n` - List of pairs `prereq` where each element is `[a, b]` **Output** - Boolean **Constraints (typical interview scale)** - `1 ≤ n ≤ 10^5` - `0 ≤ |prereq| ≤ 2*10^5` --- ## 2) Remove the minimum invalid parentheses Given a string `s` consisting of lowercase letters and parentheses `'('` and `')'`, remove the minimum number of parentheses so that the resulting string is **valid**. A string is valid if: - Every `')'` has a matching `'('` before it. - Parentheses are properly nested. Return **one** valid string after performing the minimum removals. **Input** - String `s` **Output** - A valid string formed by deleting the minimum number of parentheses characters **Constraints (typical interview scale)** - `1 ≤ |s| ≤ 10^5` **Notes** - Deleting letters is not allowed/needed; only delete parentheses. - If multiple answers exist, returning any one is acceptable.

Quick Answer: This pair of problems evaluates proficiency with graph algorithms (dependency modeling and cycle detection/topological ordering) and string processing (parentheses balancing and minimal-edit transformations), focusing on algorithmic thinking, data-structure usage, and efficient linear-time solutions.

Related Interview 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)
Meta logo
Meta
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
28
0
Loading...

You are given two independent coding tasks.

1) Check if all courses/tasks can be completed

You have n courses labeled 0..n-1 and a list of prerequisite pairs prereq.

  • Each pair [a, b] means: to take course a , you must finish course b first.
  • Return true if it is possible to finish all n courses (i.e., there is no prerequisite cycle). Otherwise return false .

Input

  • Integer n
  • List of pairs prereq where each element is [a, b]

Output

  • Boolean

Constraints (typical interview scale)

  • 1 ≤ n ≤ 10^5
  • 0 ≤ |prereq| ≤ 2*10^5

2) Remove the minimum invalid parentheses

Given a string s consisting of lowercase letters and parentheses '(' and ')', remove the minimum number of parentheses so that the resulting string is valid.

A string is valid if:

  • Every ')' has a matching '(' before it.
  • Parentheses are properly nested.

Return one valid string after performing the minimum removals.

Input

  • String s

Output

  • A valid string formed by deleting the minimum number of parentheses characters

Constraints (typical interview scale)

  • 1 ≤ |s| ≤ 10^5

Notes

  • Deleting letters is not allowed/needed; only delete parentheses.
  • If multiple answers exist, returning any one is acceptable.

Submit Your Answer to Earn 20XP

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 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.