Compare Version Numbers Problem

Compare Version Numbers Problem — ExecCode Easy DSA Practice

Solve the Compare Version Numbers problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given two version strings, version1 and version2, compare them. Your task is to compute the required answer and return the following:. A version string consists of revisions separated by dots '.'. The value of the revision is its integer conversion ignoring leading zeros. To compare version strings, compare their revision values in left-to-right order. If one of the version strings has fewer revisions, treat the missing revision values as 0.

Examples

Input {"version1": "1.01", "version2": "1.001"}; Output 0. Input {"version1": "1.0", "version2": "1.0.0"}; Output 0. Input {"version1": "0.1", "version2": "1.1"}; Output -1

Constraints

1 <= version1.length, version2.length <= 500 version1 and version2 only contain digits and '.'. version1 and version2 are valid version numbers. All the given revisions in version1 and version2 can be stored in a 32-bit integer.

Practice Compare Version Numbers free on ExecCode. Browse DSA problems, topic map, and placement guides.