Close
Topic list
Compare Version Numbers
EASY
10 mins
Strings
Topics (Covered in this problem)
Problem solved
Skill meter
Strings
-
-
Other topics
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Compare Version Numbers

Contributed by
Nishant Chitkara
Easy
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share

Problem Statement

You are given two versions numbers A and B as a string. Your task is to compare them and find out which one of them is a newer version.

Note:
``````There are no leading zeros in any of the strings except in the case of zero itself. Note that, the leading zeroes are not allowed even after a '.' ie: 121.005 is an invalid version, while 121.5 is an valid version.
``````
For Example:
``````A = “1.23.45”, B = “1.23.456”

The first two parts of both the strings are the same i.e 1 and 23 and the third part of B is greater than the third part of A i.e. 45 < 456, thus string B is the latest version.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
``````2
1.2.4
1.2.3
10.2.2
10.2.2
``````
Sample Output 1:
``````1
0
``````
Explanation for Sample Input 1:
``````For the first test case, the first two parts of both the strings are the same but the third part of the 1st version is bigger than the 2nd version. Hence our answer is 1

For the second test case, both the versions are identical here, so the answer will be 0.
``````
Sample Input 2:
``````2
123.45
123
1.0.0
1
``````
Sample output 2:
``````1
0
``````
Auto
Console