PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Bracket substrings matching any pattern

Last updated: May 17, 2026

Quick Overview

This question evaluates string manipulation and pattern-matching competency, including substring search, prioritization rules for leftmost and longest matches, and handling of edge cases.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Bracket substrings matching any pattern

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given a sentence `s` (words separated by single spaces) and a list of strings `patterns`. For **each word** in the sentence, if the word contains **any** pattern as a contiguous substring, wrap the matched substring in square brackets `[` and `]`. - If a word contains **multiple** possible matches (different patterns and/or different positions), choose the match with the **smallest start index** (leftmost occurrence). - If there is still a tie (same start index), choose the **longest** matching pattern. - If a word contains **no** pattern, leave it unchanged. - Matching is **case-sensitive**. Return the transformed sentence. ## Example - Input: `s = "hello uber"`, `patterns = ["ll", "ub"]` - Output: `"he[ll]o [ub]er"` ## Constraints (reasonable interview assumptions) - `1 <= len(s) <= 10^5` - `1 <= len(patterns) <= 10^4` - Total length of all patterns `<= 10^5` - Words contain only printable non-space characters. ## Function signature (language-agnostic) `transform(s: string, patterns: list[string]) -> string`

Quick Answer: This question evaluates string manipulation and pattern-matching competency, including substring search, prioritization rules for leftmost and longest matches, and handling of edge cases.

Related Interview Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)
Uber logo
Uber
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

Problem

You are given a sentence s (words separated by single spaces) and a list of strings patterns.

For each word in the sentence, if the word contains any pattern as a contiguous substring, wrap the matched substring in square brackets [ and ].

  • If a word contains multiple possible matches (different patterns and/or different positions), choose the match with the smallest start index (leftmost occurrence).
  • If there is still a tie (same start index), choose the longest matching pattern.
  • If a word contains no pattern, leave it unchanged.
  • Matching is case-sensitive .

Return the transformed sentence.

Example

  • Input: s = "hello uber" , patterns = ["ll", "ub"]
  • Output: "he[ll]o [ub]er"

Constraints (reasonable interview assumptions)

  • 1 <= len(s) <= 10^5
  • 1 <= len(patterns) <= 10^4
  • Total length of all patterns <= 10^5
  • Words contain only printable non-space characters.

Function signature (language-agnostic)

transform(s: string, patterns: list[string]) -> string

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

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