Compare Douyin App Version Strings Including Prerelease Tags

Last updated: November 29, 2026

Quick Overview

Given two app version strings such as "8.3.0-beta.2" and "8.3.0", return -1, 0 or 1 depending on which is older, using numeric core comparison and semantic-version rules for prerelease tags.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given two app version strings such as "8.3.0-beta.2" and "8.3.0", return -1, 0 or 1 depending on which is older, using numeric core comparison and semantic-version rules for prerelease tags.

Douyin and CapCut ship to hundreds of millions of devices through staged rollouts, and the gray-release service decides which build a device gets by comparing version strings. ByteDance phone screens often open with a short parsing problem like this to check that you handle the details (missing segments, numeric versus lexical order) before moving on to a harder second question.

What the Interviewer Expects
  • Compare core segments numerically, not as strings, so 8.2.10 is newer than 8.2.9
  • Treat missing trailing segments as zero so 8.2 equals 8.2.0
  • Rank a prerelease below the release with the same core
  • Compare prerelease identifiers one at a time, numeric ones numerically
  • Write clean helper functions and test the tricky cases out loud
Key Topics to Cover
string parsing
semantic versioning
comparators
edge cases
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you sort a list of 10,000 versions with this comparator in Python?
  • What changes if build metadata like +20261128 must be ignored?
  • How would you validate malformed input such as 8..1 or a leading v?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is two strings of the form MAJOR.MINOR.PATCH[...] with an optional -prerelease suffix whose identifiers are separated by dots. Output is -1 if the first is older, 1 if newer, 0 if equal. Cor...

High-Level Design

Split each version on the first - into a core and a prerelease part. Parse the core into integers and pad the shorter list with zeros, then compare element by element. If the cores tie, a version wi...


Submit Your Answer
Markdown supported