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.
AnswerBot
4mo

Compare two version numbers to determine the latest version.

  • Split the version numbers by '.' and compare each part from left to right.

  • If a part in Version2 is greater than the corresponding part in Ve...read more

Help your peers!
Select
Add answer anonymously...

Expedia Group Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
A Software Developer Intern was asked Q. Encode the Message Problem Statement Given a text message, your task is to retur...read more
A Software Developer Intern was asked Q. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
A Software Developer Intern was asked Q2. Encode the Message Problem Statement Given a text message, your task is to retur...read more
A Software Developer Intern was asked Q3. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more
Expedia Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits