Skip to content
RED SAGSkills
easy15 ptsstringsdevops

Compare Release Versions

A deploy tool must decide whether a release is newer than the one running. Versions look like MAJOR.MINOR.PATCH, optionally with a leading v, for example v2.10.3.

Compare a and b part by part as numbers (so 1.10.0 is newer than 1.9.0). Return 1 if a is newer, -1 if b is newer and 0 if they are the same version.

Example 1

Input: a = "1.2.10", b = "1.2.9"
Output: 1
Explanation: Patch 10 beats patch 9 numerically.

Example 2

Input: a = "v2.0.0", b = "2.0.0"
Output: 0
Explanation: The v prefix does not change the version.

Constraints

  • Each version has exactly three non-negative integer parts
  • Each part is at most 10^6
  • An optional lowercase v prefix may appear on either version
Hint 1

Strip the v, split on ., convert each part with Number.

Hint 2

Comparing the strings directly gets 1.10.0 vs 1.9.0 wrong.

Good practice for: Backend Developer, DevOps Engineer, Cloud Engineer, Mobile App Developer, Full Stack Developer, Automation Test Engineer

Run checks your code on 3 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.