Compare iOS Version Strings Including Beta and RC Builds

Last updated: November 29, 2026

Quick Overview

Implement compare(a, b) for version strings like '17.4', '17.4.1', '18.0-beta3' and '18.0-rc1'. Return -1, 0 or 1. Missing numeric parts count as zero, and for the same numeric version beta < rc < final release.

Apple
Coding & Algorithms
Software Engineer
Apple
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Implement compare(a, b) for version strings like '17.4', '17.4.1', '18.0-beta3' and '18.0-rc1'. Return -1, 0 or 1. Missing numeric parts count as zero, and for the same numeric version beta < rc < final release.

Software update, App Store minimum OS checks and crash triage all compare version strings, so Apple interviewers use this to test careful parsing. They check zero padding, numeric rather than lexical comparison, and a clear ordering for pre-release tags.

What the Interviewer Expects
  • Split numeric and pre-release parts
  • Compare numeric components as integers with zero padding
  • Rank pre-release channels with an explicit table
  • Compare pre-release numbers numerically so beta10 > beta2
  • Reject or clearly handle malformed input
Key Topics to Cover
string parsing
comparators
normalization
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
  • Support build numbers such as '18.0 (22A3354)'.
  • Sort a list of 10,000 versions efficiently.
  • Implement a range check like '>= 17.2, < 18.0' for an App Store requirement.
  • How would you handle a version string with letters like '17.4a'?
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: strings of the form N(.N)* optionally followed by -beta<K> or -rc<K>. Output: -1 if a < b, 0 if equal, 1 if a > b. '17.4' equals '17.4.0'. Final releases rank above any pre-release of the...

High-Level Design

Parse each string into a key tuple: the numeric parts with trailing zeros stripped, then a channel rank (beta = 0, rc = 1, final = 2), then the pre-release number (0 for final). Stripping trailing zer...


Submit Your Answer
Markdown supported