Skip to content
Katabench
Try free

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.

The hidden trap

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

C#
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.

C# coding challenges →

What it practices

String processing
Parse, scan and match text character by character with correct edge cases.

Related katas