Compare Version Numbers
Medium About 15 min Free, no account needed
Compare dotted version strings numerically, not textually.
The brief
Given two version strings ("1.01", "1.0.0", ...), compare them revision
by revision (split on ., compare each part as an integer, missing parts
are 0). Return -1, 0 or 1.
String comparison says "1.10" < "1.2" and "1.01" != "1.001". The hidden
tests are exactly these: leading zeros and revision counts that differ.
Starter code
using System;
public class Solution
{
// TODO: return -1, 0 or 1 comparing two dotted version strings.
public int CompareVersions(string v1, string v2)
{
throw new NotImplementedException();
}
}How it is graded
Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.
What it practices
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Decode String Medium Free Expand k[encoded] patterns, nesting included.
- Count Substring Occurrences Medium Free Count overlapping occurrences by comparing characters, not slicing strings.
- Hex Checksum Medium Free Sum the bytes of a hex string with nibble arithmetic, not substrings.
- Integer to Roman Medium Free Write Roman numerals the way Romans did - greedily.