Ctrl K

Which Release Is Newer

Medium
A software version number is a few non-negative integers (parts) joined by dots, such as "4.12.0". Leading zeros in a part mean nothing: "012" is 12. Versions are compared part by part from left to right, and the first pair of differing parts decides. If one version has fewer parts, the missing ones count as 0. Given two versions left and right, return -1 if left is older (smaller) than right, 1 if it is newer (larger), and 0 if they are equal.
Example 1
left="2.9.1", right="2.10" → -1

The first parts are equal (2 and 2); in the second ones 9 < 10, so left is older. Nothing further needs comparing.

Example 2
left="3.04", right="3.4.0" → 0

04 means 4, and the missing third part of left counts as zero. The versions are equal.

Example 3
left="1.0.7", right="1" → 1

The second and third parts of right count as zeros, and 7 > 0, so left is newer.

Constraints
  • 1 ≤ length of left, right ≤ 500
  • Strings contain only digits and dots, and every part between dots is non-empty
  • Every part is less than 2³¹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Mirror Fragment MediumWords in Reverse Order MediumExactly One Edit Apart MediumReverse the Word Order in Place MediumPacking Runs in Place Medium
loading Python…
Input
left="2.9.1", right="2.10"
Expected
-1

Run checks the first 3 tests in your browser. Submit checks all 122 tests on the server, hidden ones included.