PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's understanding of dynamic programming and string-processing skills, along with algorithmic complexity analysis for segmentation problems.

  • medium
  • TikTok
  • Coding & Algorithms
  • Machine Learning Engineer

Determine if a string can be segmented

Company: TikTok

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given a string `s` and a list of strings `wordDict`, determine whether `s` can be segmented into a sequence of one or more dictionary words. - You may reuse dictionary words multiple times. - Return `true` if such a segmentation exists, otherwise return `false`. ### Input - `s`: a non-empty string - `wordDict`: a list of non-empty strings ### Output - Boolean indicating whether `s` can be segmented. ### Example - `s = "leetcode"`, `wordDict = ["leet", "code"]` → `true` - `s = "catsandog"`, `wordDict = ["cats","dog","sand","and","cat"]` → `false` ### Notes / constraints (typical interview assumptions) - `1 <= len(s) <= 10^4` - `1 <= len(wordDict) <= 10^5` - Total characters across `wordDict` can be large; aim for an efficient solution.

Quick Answer: This question evaluates a candidate's understanding of dynamic programming and string-processing skills, along with algorithmic complexity analysis for segmentation problems.

Return whether s can be segmented into dictionary words, allowing reuse.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ('leetcode', ['leet','code'])

Expected Output: True

Explanation: Prompt true example.

Input: ('catsandog', ['cats','dog','sand','and','cat'])

Expected Output: False

Explanation: Prompt false example.

Input: ('aaaaaaa', ['aaaa','aaa'])

Expected Output: True

Explanation: Reusable words.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)