PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/TikTok

Segment a message with width-constrained suffixes

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithm design and string-processing skills, focusing on constraint-aware segmentation with variable-length suffix metadata and the accompanying complexity analysis.

  • Medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Segment a message with width-constrained suffixes

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a message string s and an integer width W, split s into consecutive segments and append a suffix "i/n" to each segment indicating its 1-indexed position i out of the total n segments. Part A (suffix excluded from width): Split s into chunks of up to W characters (not counting the suffix), then append the suffix to each line; return the list of lines. Part B (suffix included in width): Now len(chunk) + len(suffix(i,n)) must be ≤ W for every line, but n is unknown in advance because the suffix length depends on n. Produce valid lines that cover the entire message in order (breaking anywhere is allowed; no reordering). If impossible (e.g., W < len("1/1")), return an error. Implement an efficient algorithm to determine n and the segmentation and analyze its complexity.

Quick Answer: This question evaluates algorithm design and string-processing skills, focusing on constraint-aware segmentation with variable-length suffix metadata and the accompanying complexity analysis.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

Given a message string s and an integer width W, split s into consecutive segments and append a suffix "i/n" to each segment indicating its 1-indexed position i out of the total n segments. Part A (suffix excluded from width): Split s into chunks of up to W characters (not counting the suffix), then append the suffix to each line; return the list of lines. Part B (suffix included in width): Now len(chunk) + len(suffix(i,n)) must be ≤ W for every line, but n is unknown in advance because the suffix length depends on n. Produce valid lines that cover the entire message in order (breaking anywhere is allowed; no reordering). If impossible (e.g., W < len("1/1")), return an error. Implement an efficient algorithm to determine n and the segmentation and analyze its complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Software Engineer•TikTok Software Engineer•TikTok Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.