


The input strings consist of digits and dots only and both the strings are started and terminated by a digit. There are no leading zeros and no zeros following a dot in both the strings except in the case of zero itself.
Version1 = “1.23.45”, Version2 = “1.23.456”
The first two parts of both the strings are the same. The third part of Version2 is greater than the third part of Version1, thus string Version2 is of the latest version.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first line of each test case contains the string ‘Version1’.
The second line of each test case contains the string ‘Version2’.
For each test case, print 1 if version 1 is latest, -1 if version 2 is latest and 0 if both versions are the same.
Print output of each test case in separate lines.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= |Version1| <= 10000
1 <= |Version2| <= 10000
Time limit: 1 second
The idea is to use a recursive approach to compare the versions. Here we will start iterating through both the strings to extract the number till we reach a dot (or the end of the string) and we will compare both the numbers. If they are the same, we will recursively compare the remaining string. If they are different, we will find out which one of them is bigger and will return the result of the comparison as our answer.
To compare the number represented as strings, we will need to design a function.
The working of comparison function can be understood as:
The idea is to use an iterative approach to compare both strings. The approach is similar to the previous approach just that we will be doing it in an iterative manner.
We will use four pointers ‘start1’, ‘end1’ (pointing to string Version1) and ‘start2’, ‘end2’ (pointing to string Version2) all initialised to 0. We will move ‘end1’ to the first dot to the right of ‘start1’ (or the end of the string if no such dot exists) and we will move ‘end2’ to the first dot to the right of ‘start2’ (or the end of the string if no such dot exists).
If :