Determine dictionary-based string segmentation

Quick Overview

This question evaluates string segmentation competency, including understanding of dynamic programming, scalable token-matching techniques (prefix data structures and hashing), and handling large input sizes.

Determine dictionary-based string segmentation

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a string s and a set of tokens dict. Determine whether s can be segmented into a sequence of one or more tokens from dict. If segmentation is possible, return one valid segmentation; otherwise return an empty result. Discuss and implement an approach that scales to |s| up to 1e5 and |dict| up to 1e5 (consider prefix pruning via tries or hashing, and dynamic programming with early exits). Analyze time and space complexity, and explain how you would extend the solution to count the number of distinct segmentations modulo 1,000,000,007.

Quick Answer: This question evaluates string segmentation competency, including understanding of dynamic programming, scalable token-matching techniques (prefix data structures and hashing), and handling large input sizes.

|Home/Coding & Algorithms/Microsoft
Microsoft logo
Microsoft
Aug 14, 2025, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
3
0

You are given a string s and a set of tokens dict. Determine whether s can be segmented into a sequence of one or more tokens from dict. If segmentation is possible, return one valid segmentation; otherwise return an empty result. Discuss and implement an approach that scales to |s| up to 1e5 and |dict| up to 1e5 (consider prefix pruning via tries or hashing, and dynamic programming with early exits). Analyze time and space complexity, and explain how you would extend the solution to count the number of distinct segmentations modulo 1,000,000,007.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...