< Summary

Information
Class: LeetCode.Algorithms.DesignBrowserHistory.DesignBrowserHistoryArray
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignBrowserHistory\DesignBrowserHistoryArray.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 74
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Visit(...)100%11100%
Back(...)100%11100%
Forward(...)100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignBrowserHistory\DesignBrowserHistoryArray.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.DesignBrowserHistory;
 13
 14/// <inheritdoc />
 15public sealed class DesignBrowserHistoryArray : IDesignBrowserHistory
 16{
 17    private const int Capacity = 5000;
 18    private readonly string[] _history;
 19    private int _current;
 20    private int _last;
 21
 22    /// <summary>
 23    ///     Time complexity - O(1)
 24    ///     Space complexity - O(1)
 25    /// </summary>
 26    /// <param name="homepage"></param>
 127    public DesignBrowserHistoryArray(string homepage)
 128    {
 129        _history = new string[Capacity];
 130        _history[0] = homepage;
 131        _current = 0;
 132        _last = 0;
 133    }
 34
 35    /// <summary>
 36    ///     Time complexity - O(1)
 37    ///     Space complexity - O(1)
 38    /// </summary>
 39    /// <param name="url"></param>
 40    public void Visit(string url)
 441    {
 442        _current++;
 43
 444        _history[_current] = url;
 45
 446        _last = _current;
 447    }
 48
 49    /// <summary>
 50    ///     Time complexity - O(1)
 51    ///     Space complexity - O(1)
 52    /// </summary>
 53    /// <param name="steps"></param>
 54    /// <returns></returns>
 55    public string Back(int steps)
 456    {
 457        _current = Math.Max(0, _current - steps);
 58
 459        return _history[_current];
 460    }
 61
 62    /// <summary>
 63    ///     Time complexity - O(1)
 64    ///     Space complexity - O(1)
 65    /// </summary>
 66    /// <param name="steps"></param>
 67    /// <returns></returns>
 68    public string Forward(int steps)
 269    {
 270        _current = Math.Min(_last, _current + steps);
 71
 272        return _history[_current];
 273    }
 74}