At Zoblik International, managing software and API versions is crucial for maintaining compatibility and ensuring smooth updates. Their versioning scheme follows a standard format: a sequence of non-negative integer revisions separated by dots (e.g., 1.2.3, 10.0.50). Each revision can consist of one or more digits and may contain leading zeros (e.g., 01 is equivalent to 1).
Your task is to implement a tool that compares two given software versions and determines their relative order. The comparison should follow these rules:
01 and 1 are both treated as the integer 1).1.2.3 is greater than 1.2 because 1.2 is implicitly 1.2.0.Your program should output 1 if the first version is greater, -1 if the second version is greater, and 0 if both versions are equivalent.
The first line contains an integer 'T', representing the number of test cases.
For each test case:
version1, representing the first software version.version2, representing the second software version.For each test case, print an integer on a new line:
1 if version1 > version2.-1 if version1 < version2.0 if version1 = version2.1 <= T <= 1001 <= version1.length, version2.length <= 1041 <= T <= 100; 1 <= version1.size, version2.size <= 10^4
Example 1: Basic Comparison
Input: 1 2.3.0 2.4.0 Output: -1 Explanation: Comparing "2.3.0" and "2.4.0": 1. First revisions: 2 vs 2. They are equal. 2. Second revisions: 3 vs 4. 3 is less than 4. Therefore, "2.3.0" < "2.4.0".Example 2: Leading Zeros
Input: 1 1.001.2 1.1.2 Output: 0 Explanation: Comparing "1.001.2" and "1.1.2": 1. First revisions: 1 vs 1. Equal. 2. Second revisions: 001 vs 1. Both are treated as integer 1. Equal. 3. Third revisions: 2 vs 2. Equal. Therefore, "1.001.2" = "1.1.2".Example 3: Unequal Lengths
Input: 1 1.2.1.1 1.2 Output: 1 Explanation: Comparing "1.2.1.1" and "1.2": 1. First revisions: 1 vs 1. Equal. 2. Second revisions: 2 vs 2. Equal. 3. Third revisions: 1 vs (implicit) 0. 1 is greater than 0. Therefore, "1.2.1.1" > "1.2".
String & Tries
Amazon, Intuit
Start coding and your submissions will appear here.