Skip to content
Katabench
Try free

Hex Checksum

Medium About 15 min Free, no account needed

Sum the bytes of a hex string with nibble arithmetic, not substrings.

The brief

Given an even-length string of lowercase hex digits ("0a1f..."), interpret each pair as a byte and return the sum of all byte values.

The allocation budget

Substring(i, 2) + Convert.ToInt32(..., 16) allocates a string per byte. The hidden test is a 100 KB hex string (50,000 bytes) under a 32 KB allocation budget, so per-byte string allocation blows the budget. Watch your allocations and process the characters in place.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the sum of the byte values encoded in the hex string.
    public long HexChecksum(string hex)
    {
        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 →

Related guides

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