Skip to content
Katabench
Try free

Most Common Word Length

Medium About 15 min Free, no account needed

Which word length appears most often? Count lengths, not words.

The brief

Given text of words separated by spaces, return the word length that occurs most often (ties go to the smaller length; 0 for an empty text).

The allocation budget

Splitting allocates every word just to read its .Length. The hidden test has 15,000 words under a 32 KB allocation budget, so splitting the text blows the budget. You only need the lengths, not the words themselves, so watch your allocations.

Starter code

C#
using System;
using System.Collections.Generic;

public class Solution
{
    // TODO: return the most frequent word length (ties to the smaller length).
    public int MostCommonWordLength(string text)
    {
        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.
Allocation-free code
Avoid per-item strings and copies with spans, indexes and arithmetic in hot loops.

Related katas