PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Can Finish Courses

Return whether the prerequisite graph is acyclic.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (2, [[1,0]])

Expected Output: True

Explanation: No cycle.

Input: (2, [[1,0],[0,1]])

Expected Output: False

Explanation: Cycle prevents completion.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.

Minimum Remove To Valid Parentheses

Remove the minimum number of parentheses to make the string valid; letters are preserved.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ('lee(t(c)o)de)',)

Expected Output: 'lee(t(c)o)de'

Explanation: Already valid string is unchanged.

Input: ('a)b(c)d',)

Expected Output: 'ab(c)d'

Explanation: Remove unmatched close parenthesis.

Input: ('))((',)

Expected Output: ''

Explanation: Remove all invalid parentheses.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
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)