easy +10 pts

Compare Version Strings

Parse and compare dotted version strings like '1.2.3' against '1.10.0'.

Write a function `compare_versions(v1: str, v2: str) -> int` that compares two version strings and returns: - `-1` if `v1 < v2` - `0` if `v1 == v2` - `1` if `v1 > v2` A version string consists of one or more numeric components separated by periods (e.g., `"1.2"`, `"1.2.3"`, `"01.2"`). To compare, split each version by `"."` and compare the numeric values of the components from left to right. If one version has fewer components, treat the missing components as `0`. For example: - `"1.2"` equals `"1.2.0"`. - `"1.10"` is greater than `"1.9"`. - `"01.02"` equals `"1.2"`.

Constraints

- Both version strings contain only digits and periods. - Each component is a non-negative integer with no leading spaces. - The number of components is between 1 and 100. - Each component's integer value fits in a standard Python `int` without overflow. - You may assume the input strings are well-formed as described.

Example

```python
>>> compare_versions("1.2", "1.10")
-1
>>> compare_versions("1.2", "1.2.0")
0
>>> compare_versions("2.0.1", "1.9.9")
1
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Split each string by '.' and convert each part to int.
Pad the shorter list with zeros to match the longer length.
Compare component by component until you find a difference.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.