PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/TikTok

Solve three algorithm tasks

Last updated: Mar 29, 2026

Quick Overview

This multi-part question evaluates algorithmic problem-solving across string processing (text justification), handling ambiguous state in sequence validation (parentheses with wildcards), and grid graph traversal with path reconstruction, testing competencies in formatting and spacing logic, state-tracking for correctness under uncertainty, and shortest-path search and reconstruction. It is commonly asked in Coding & Algorithms interviews to assess correctness under edge cases, ability to reason about trade-offs and invariants, and the analysis of time and space complexity, requiring both conceptual understanding and practical implementation skills.

  • Medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Solve three algorithm tasks

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Solve the following algorithm tasks and explain your approach, time complexity, and space complexity for each: 1) Fully justify text: Given an array of words and an integer maxWidth, break the words into lines so that each line has exactly maxWidth characters and is fully justified. Distribute spaces as evenly as possible; when spaces do not divide evenly, put more spaces in the leftmost gaps. The last line should be left-justified with single spaces between words and padded on the right. Assume every word's length is <= maxWidth. Return the list of formatted lines. 2) Validate parentheses with wildcards: Given a string s consisting of '(', ')' and '*', where '*' may represent '(' or ')' or the empty string, determine whether there exists a replacement that yields a balanced parentheses sequence. Return a boolean result and, if true, optionally output one valid replacement instantiation. 3) Find a shortest path in a grid with obstacles: Given a 2D grid of 0s and 1s (0 = open cell, 1 = obstacle), a start coordinate (rs, cs), and a target coordinate (rt, ct), return any shortest path as a list of coordinates from start to target (inclusive). Movement is allowed only up, down, left, and right with unit cost. If no path exists, return an empty list. Discuss your path reconstruction method and how you handle cases where start/target are out of bounds or blocked.

Quick Answer: This multi-part question evaluates algorithmic problem-solving across string processing (text justification), handling ambiguous state in sequence validation (parentheses with wildcards), and grid graph traversal with path reconstruction, testing competencies in formatting and spacing logic, state-tracking for correctness under uncertainty, and shortest-path search and reconstruction. It is commonly asked in Coding & Algorithms interviews to assess correctness under edge cases, ability to reason about trade-offs and invariants, and the analysis of time and space complexity, requiring both conceptual understanding and practical implementation skills.

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
Aug 13, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0

Solve the following algorithm tasks and explain your approach, time complexity, and space complexity for each:

  1. Fully justify text: Given an array of words and an integer maxWidth, break the words into lines so that each line has exactly maxWidth characters and is fully justified. Distribute spaces as evenly as possible; when spaces do not divide evenly, put more spaces in the leftmost gaps. The last line should be left-justified with single spaces between words and padded on the right. Assume every word's length is <= maxWidth. Return the list of formatted lines.
  2. Validate parentheses with wildcards: Given a string s consisting of '(', ')' and ' ', where ' ' may represent '(' or ')' or the empty string, determine whether there exists a replacement that yields a balanced parentheses sequence. Return a boolean result and, if true, optionally output one valid replacement instantiation.
  3. Find a shortest path in a grid with obstacles: Given a 2D grid of 0s and 1s (0 = open cell, 1 = obstacle), a start coordinate (rs, cs), and a target coordinate (rt, ct), return any shortest path as a list of coordinates from start to target (inclusive). Movement is allowed only up, down, left, and right with unit cost. If no path exists, return an empty list. Discuss your path reconstruction method and how you handle cases where start/target are out of bounds or blocked.

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.