< Summary

Information
Class: LeetCode.Algorithms.RobotBoundedInCircle.RobotBoundedInCircleSimulation
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\RobotBoundedInCircle\RobotBoundedInCircleSimulation.cs
Line coverage
88%
Covered lines: 23
Uncovered lines: 3
Coverable lines: 26
Total lines: 73
Line coverage: 88.4%
Branch coverage
88%
Covered branches: 15
Total branches: 17
Branch coverage: 88.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsRobotBounded(...)88.23%171788.46%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\RobotBoundedInCircle\RobotBoundedInCircleSimulation.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.RobotBoundedInCircle;
 13
 14/// <inheritdoc />
 15public class RobotBoundedInCircleSimulation : IRobotBoundedInCircle
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="instructions"></param>
 22    /// <returns></returns>
 23    public bool IsRobotBounded(string instructions)
 424    {
 425        var direction = 0;
 26
 427        var x = 0;
 428        var y = 0;
 29
 5030        foreach (var instruction in instructions)
 1931        {
 1932            switch (instruction)
 33            {
 34                case 'G':
 1235                    switch (direction)
 36                    {
 37                        case 0:
 638                            y++;
 39
 640                            break;
 41                        case 1:
 142                            x++;
 43
 144                            break;
 45                        case 2:
 446                            y--;
 47
 448                            break;
 49                        case 3:
 150                            x--;
 51
 152                            break;
 53                    }
 54
 1255                    break;
 56                case 'L':
 757                    {
 758                        direction = (direction + 3) % 4;
 59
 760                        break;
 61                    }
 62                case 'R':
 063                    {
 064                        direction = (direction + 1) % 4;
 65
 066                        break;
 67                    }
 68            }
 1969        }
 70
 471        return (x == 0 && y == 0) || direction != 0;
 472    }
 73}

Methods/Properties

IsRobotBounded(System.String)