Find Longest Regex (Fungible :)

Problem Overview

  • Task: find the longest valid regex (uppercase letters, balanced [ ] groups with unique letters; each group matches one character) that matches x and y but not z.
  • Input/Output: three length-n uppercase strings; return the lexicographically smallest longest regex, or -1; regex length counts letters and brackets.
  • Context: prototype regex generator for strings, with simple character-set rules.
  • Company: from Amazon interviews; a coding interview problem and interview question.
  • Constraints: 1 ≤ n ≤ 1e5; answer may reach 1e6 chars.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: