Compare Two Android Build Version Strings With Pre-Release Tags
Last updated: November 29, 2026
Quick Overview
Given two version strings such as "1.10.2" or "2.0-beta", return -1, 0, or 1 depending on whether the first is older, equal, or newer, treating missing trailing segments as zero and pre-release tags as older than the plain release.
0
0
0 solved
Given two version strings such as "1.10.2" or "2.0-beta", return -1, 0, or 1 depending on whether the first is older, equal, or newer, treating missing trailing segments as zero and pre-release tags as older than the plain release.
A Google phone screen warm-up framed around the Play Console deciding whether an uploaded APK is newer than the live one. The interviewer wants numeric (not lexicographic) segment comparison, padding for unequal lengths, and a clear rule for the pre-release suffix.
What the Interviewer Expects
- Splits on dots and compares segments as integers, not strings
- Treats missing trailing segments as zero so 1.2 equals 1.2.0
- Defines and implements an ordering for pre-release tags
- Handles leading zeros like 1.01 without special code
- Traces an example such as 1.10 vs 1.9 out loud
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 million version strings efficiently?
- Full semantic versioning compares dotted pre-release identifiers numerically when they are digits; how would you extend the code?
- What if some segments can contain letters, like 3.2a?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: two strings made of dot-separated non-negative integers, optionally followed by
-tag(for example2.0-beta). - Output:
-1ifa < b,0if equal,1ifa > b. 1.2and1.2.0a...
High-Level Design
Parse each string into (numeric_segments, tag). Strip trailing zero segments so that padded and unpadded versions normalize to the same list. Walk both lists in parallel, substituting zero when one ...