Version Comparison
Given two strings, Version1
and Version2
, each representing version numbers, determine which one is the latest version.
Explanation:
The input strings consist of digits and dots only. Both strings start and end with a digit. There are no leading zeros in each version part unless it is zero itself. Your task is to compare these version numbers and find the latest one.
Input:
The first line contains an integer 'T', representing the number of test cases.
For each test case:
- The first line contains the string ‘Version1’.
- The second line contains the string ‘Version2’.
Output:
For each test case, output 1 if Version1 is the latest, -1 if Version2 is the latest, and 0 if both versions are the same.
Output the results for each test case on separate lines.
Example:
Input:
Version1 = "1.23.45"
Version2 = "1.23.456"
Output:
-1
Explanation:
Version2's third part is greater than that of Version1, making it the latest version.
Constraints:
1 <= T <= 100
1 <= |Version1| <= 10000
1 <= |Version2| <= 10000
- Time limit: 1 second
Note:
You do not need to print anything. The output is already handled for you. Implement the required function to return the answer.
Be the first one to answer
Add answer anonymously...
Top Expedia Group Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Expedia Group Software Developer Intern
>
Expedia Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app