Compare Version Numbers

Medium

Given two version numbers, compare them.

A version number consists of one or more revisions connected by a dot.
Each revisions consists of digits and may contain leading zeroes. Each revision consists atleast one digit.

Revisions are 0-indexed from left to right.
To compare two versions, compare revisions in the left-to-right order. Revisions are compared using their integer value ignoring any leading zeroes.

Example 1

version 1: 1.1.0
version 2: 1.2.0

version 2 > version 1.

Example 2

version 1: 1.001.2
version 2: 1.1.2

version 2 = version 1.

Example 3

version 1: 1.100.2
version 2: 1.1.2

version 2 < version 1.

Example 4

version 1: 1.2.1.1
version 2: 1.2

version 2 < version 1.

Testing

Input Format

The first line contains an integer ‘T’ denoting the number of test cases.

For each test case, the input has two lines:

  • string version1.
  • string version2.

Output Format

For each test case, the output has a lines with the value:

  • 1 if version1 > version2.
  • -1 if version1 < version2.
  • 0 if version1 = version2.

Sample Input

5
2.3.01
2.4.01
1.1.1
1.1.1
3.3.001
3.3.1
4.4.1
4.3.1
2.3.0
2.3

Expected Output

-1
0
0
1
0

Constraints

1 <= T <= 100
1 <= version1.size, version2.size <= 104

Companies
Editorial Link: Editorial