Skip to content
Katabench
Try free

Trimmed Sum

Easy About 8 min Free, no account needed

Sum everything except one min and one max - without sorting a copy.

The brief

Given nums (at least three elements), return the sum of all elements after removing one minimum and one maximum occurrence.

The allocation budget

OrderBy(...).ToArray() (or sorting a clone) allocates a full copy of the array. The hidden test streams 200,000 numbers under a 64 KB allocation budget. You need the answer in a single pass with effectively zero allocations, so sorting or copying the array is out.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the sum after dropping one min and one max occurrence.
    public long TrimmedSum(long[] nums)
    {
        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

Allocation-free code
Avoid per-item strings and copies with spans, indexes and arithmetic in hot loops.

Related katas