PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Find second-minimal word segmentation count

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of string segmentation, combinatorial enumeration, and optimization techniques such as dynamic programming and search strategies, testing skills in the Coding & Algorithms domain.

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

Find second-minimal word segmentation count

Company: TikTok

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a string s and a dictionary D of non-empty words, define a 'segmentation' as splitting s into a sequence of words from D whose concatenation equals s. Let the cost of a segmentation be the number of words used. Return the second-smallest possible cost among all valid segmentations, or -1 if fewer than two valid segmentations exist. Only return the cost; do not enumerate segmentations. Describe your algorithm, justify its time and space complexity, and explain how you would handle large inputs.

Quick Answer: This question evaluates understanding of string segmentation, combinatorial enumeration, and optimization techniques such as dynamic programming and search strategies, testing skills in the Coding & Algorithms domain.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Maximize sum with no adjacent elements - TikTok (medium)
TikTok logo
TikTok
Aug 7, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
3
0

Given a string s and a dictionary D of non-empty words, define a 'segmentation' as splitting s into a sequence of words from D whose concatenation equals s. Let the cost of a segmentation be the number of words used. Return the second-smallest possible cost among all valid segmentations, or -1 if fewer than two valid segmentations exist. Only return the cost; do not enumerate segmentations. Describe your algorithm, justify its time and space complexity, and explain how you would handle large inputs.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Machine Learning Engineer•TikTok Machine Learning Engineer•TikTok Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.