< Summary

Information
Class: LeetCode.Algorithms.MinimumNumberOfOperationsToMoveAllBallsToEachBox.MinimumNumberOfOperationsToMoveAllBallsToEachBoxTwoPass
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumNumberOfOperationsToMoveAllBallsToEachBox\MinimumNumberOfOperationsToMoveAllBallsToEachBoxTwoPass.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 59
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
MinOperations(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumNumberOfOperationsToMoveAllBallsToEachBox\MinimumNumberOfOperationsToMoveAllBallsToEachBoxTwoPass.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.MinimumNumberOfOperationsToMoveAllBallsToEachBox;
 13
 14/// <inheritdoc />
 15public class MinimumNumberOfOperationsToMoveAllBallsToEachBoxTwoPass : IMinimumNumberOfOperationsToMoveAllBallsToEachBox
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="boxes"></param>
 22    /// <returns></returns>
 23    public int[] MinOperations(string boxes)
 224    {
 225        var result = new int[boxes.Length];
 26
 227        var count = 0;
 228        var moves = 0;
 29
 2230        for (var i = 0; i < boxes.Length; i++)
 931        {
 932            result[i] += moves;
 33
 934            if (boxes[i] == '1')
 535            {
 536                count++;
 537            }
 38
 939            moves += count;
 940        }
 41
 242        count = 0;
 243        moves = 0;
 44
 2245        for (var i = boxes.Length - 1; i >= 0; i--)
 946        {
 947            result[i] += moves;
 48
 949            if (boxes[i] == '1')
 550            {
 551                count++;
 552            }
 53
 954            moves += count;
 955        }
 56
 257        return result;
 258    }
 59}

Methods/Properties

MinOperations(System.String)