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.

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

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
String Parsing
Tokenization
Comparison Functions
Semantic Versioning
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 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 Problems
Sample Answer
Requirements
  • Input: two strings made of dot-separated non-negative integers, optionally followed by -tag (for example 2.0-beta).
  • Output: -1 if a < b, 0 if equal, 1 if a > b.
  • 1.2 and 1.2.0 a...
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 ...


Submit Your Answer
Markdown supported