PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Solve two string algorithm tasks

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string algorithm skills — specifically parentheses balancing and shortest covering-substring problems — testing linear-time algorithm design, frequency tracking, and handling of large input-size constraints in the coding & algorithms domain.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve two string algorithm tasks

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Answer both parts. A) Parentheses correction: Given a string s consisting only of '(' and ')', output the minimum number of parentheses you must insert (at any positions) to make s a valid balanced parentheses string. Define validity in the usual way via matching pairs and proper nesting. Constraints: 1 <= |s| <= 100,000. Describe an O(n)-time algorithm with O( 1) or O(n) extra space and briefly justify correctness. B) Shortest covering substring: Given two strings s and t (ASCII), return the shortest contiguous substring of s that contains every character of t at least as many times as it appears in t; if no such substring exists, return the empty string. If multiple answers have the same length, return any. Constraints: 1 <= |s| <= 200,000; 1 <= |t| <= 10,000. Provide the algorithm, time and space complexities, and key edge cases.

Quick Answer: This question evaluates string algorithm skills — specifically parentheses balancing and shortest covering-substring problems — testing linear-time algorithm design, frequency tracking, and handling of large input-size constraints in the coding & algorithms domain.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Jul 15, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

Answer both parts. A) Parentheses correction: Given a string s consisting only of '(' and ')', output the minimum number of parentheses you must insert (at any positions) to make s a valid balanced parentheses string. Define validity in the usual way via matching pairs and proper nesting. Constraints: 1 <= |s| <= 100,000. Describe an O(n)-time algorithm with O(

  1. or O(n) extra space and briefly justify correctness. B) Shortest covering substring: Given two strings s and t (ASCII), return the shortest contiguous substring of s that contains every character of t at least as many times as it appears in t; if no such substring exists, return the empty string. If multiple answers have the same length, return any. Constraints: 1 <= |s| <= 200,000; 1 <= |t| <= 10,000. Provide the algorithm, time and space complexities, and key edge cases.

Submit Your Answer

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,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.