< Summary

Information
Class: LeetCode.Algorithms.NumberOfStudentsUnableToEatLunch.NumberOfStudentsUnableToEatLunchQueue
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\NumberOfStudentsUnableToEatLunch\NumberOfStudentsUnableToEatLunchQueue.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 52
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountStudents(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\NumberOfStudentsUnableToEatLunch\NumberOfStudentsUnableToEatLunchQueue.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 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.NumberOfStudentsUnableToEatLunch;
 13
 14/// <inheritdoc />
 15public class NumberOfStudentsUnableToEatLunchQueue : INumberOfStudentsUnableToEatLunch
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^2)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="students"></param>
 22    /// <param name="sandwiches"></param>
 23    /// <returns></returns>
 24    public int CountStudents(int[] students, int[] sandwiches)
 225    {
 226        var studentsQueue = new Queue<int>(students);
 27
 228        var sandwichesIndex = 0;
 29
 230        var count = 0;
 31
 1832        while (studentsQueue.Count > 0 && sandwichesIndex < sandwiches.Length &&
 1833               count < sandwiches.Length - sandwichesIndex)
 1634        {
 1635            var student = studentsQueue.Dequeue();
 1636            var sandwich = sandwiches[sandwichesIndex];
 37
 1638            if (student == sandwich)
 739            {
 740                count = 0;
 741                sandwichesIndex++;
 742            }
 43            else
 944            {
 945                count++;
 946                studentsQueue.Enqueue(student);
 947            }
 1648        }
 49
 250        return studentsQueue.Count;
 251    }
 52}