Skip to content
Katabench
Try free

Multiply Numeric Strings

Medium About 25 min Free, no account needed

Schoolbook multiplication of numbers thousands of digits long.

The brief

Given two non-negative decimal numbers as strings, return their product as a string.

The hidden trap

Parsing into built-in integers dies on the hidden 3,000-digit factors, which overflow every fixed-width type. You will need to multiply the numbers digit by digit yourself. Mind the leading zeros (and the "0" result).

The performance bar

Digit-by-digit is necessary but not sufficient. Accumulating each partial product with result = digit + result copies the whole answer every time, which is O(n^2) in the answer length and misses the budget. Build into a char[] or a StringBuilder and reverse once.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the product of two non-negative numeric strings.
    public string Multiply(string a, string b)
    {
        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.
Math and number theory
Replace enumeration with a formula: GCD, modular arithmetic, digit math and closed-form counting.

Related katas