Count Ways to Split a Concatenated Promo String Into Valid Codes

Last updated: November 29, 2026

Quick Overview

A partner exported promo codes without delimiters; given the concatenated string and the set of valid codes, return how many ways the string can be segmented entirely into valid codes, modulo 1,000,000,007.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


A partner exported promo codes without delimiters; given the concatenated string and the set of valid codes, return how many ways the string can be segmented entirely into valid codes, modulo 1,000,000,007.

Uber Eats runs many merchant and partner promotions, and malformed exports are a realistic data-cleaning problem. The online assessment checks a 1D DP over prefixes with a bound on code length to avoid quadratic slicing, plus correct modular counting.

What the Interviewer Expects
  • Define dp[i] as the number of ways to segment the first i characters
  • Only try code lengths up to the longest valid code
  • Use a set for O(1) membership
  • Apply the modulus during accumulation
  • Handle the empty string and no-solution cases
Key Topics to Cover
dynamic programming
word break
hash set
modular counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return one valid segmentation, or all of them when the count is small
  • How would a trie speed this up with many long codes?
  • What if codes may overlap and you want the minimum number of codes used?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: string s, list codes.
  • Output: number of sequences of codes whose concatenation equals s, modulo 1e9 + 7.
  • Empty s has exactly one segmentation (the empty one)....
High-Level Design

dp[0] = 1. For each end position i, look back over lengths L from 1 to maxlen; if s[i - L:i] is a valid code, add dp[i - L]. Bounding L by the longest code turns O(n^2) slices into O(n x...


Submit Your Answer
Markdown supported