< Summary

Information
Class: LeetCode.Algorithms.SmallestMissingMultipleOfK.SmallestMissingMultipleOfKLookup
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SmallestMissingMultipleOfK\SmallestMissingMultipleOfKLookup.cs
Line coverage
83%
Covered lines: 15
Uncovered lines: 3
Coverable lines: 18
Total lines: 52
Line coverage: 83.3%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MissingMultiple(...)60%101083.33%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SmallestMissingMultipleOfK\SmallestMissingMultipleOfKLookup.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.SmallestMissingMultipleOfK;
 13
 14/// <inheritdoc />
 15public sealed class SmallestMissingMultipleOfKLookup : ISmallestMissingMultipleOfK
 16{
 17    private const int MaxValue = 100;
 18
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="nums"></param>
 24    /// <param name="k"></param>
 25    /// <returns></returns>
 26    public int MissingMultiple(int[] nums, int k)
 227    {
 228        Span<bool> numsLookup = stackalloc bool[MaxValue + 1];
 29
 2430        for (var i = 0; i < nums.Length; i++)
 1031        {
 1032            var num = nums[i];
 33
 1034            numsLookup[num] = true;
 1035        }
 36
 237        if (k > MaxValue / 2)
 038        {
 039            return numsLookup[k] ? k * 2 : k;
 40        }
 41
 1242        for (var num = k; num <= MaxValue; num += k)
 643        {
 644            if (!numsLookup[num])
 245            {
 246                return num;
 47            }
 448        }
 49
 050        return ((MaxValue / k) + 1) * k;
 251    }
 52}