< Summary

Information
Class: LeetCode.Algorithms.NextGreaterElement1.NextGreaterElement1BruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\NextGreaterElement1\NextGreaterElement1BruteForce.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 66
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
NextGreaterElement(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\NextGreaterElement1\NextGreaterElement1BruteForce.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.NextGreaterElement1;
 13
 14/// <inheritdoc />
 15public class NextGreaterElement1BruteForce : INextGreaterElement1
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n * m)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="nums1"></param>
 22    /// <param name="nums2"></param>
 23    /// <returns></returns>
 24    public int[] NextGreaterElement(int[] nums1, int[] nums2)
 225    {
 226        var result = new int[nums1.Length];
 27
 1428        for (var i = 0; i < nums1.Length; i++)
 529        {
 530            var nextIndex = -1;
 31
 2832            for (var j = 0; j < nums2.Length; j++)
 1433            {
 1434                if (nums1[i] != nums2[j])
 935                {
 936                    continue;
 37                }
 38
 539                nextIndex = j;
 40
 541                break;
 42            }
 43
 544            var next = -1;
 45
 546            if (nextIndex >= 0)
 547            {
 2248                for (var j = nextIndex; j < nums2.Length; j++)
 849                {
 850                    if (nums2[j] <= nums1[i])
 651                    {
 652                        continue;
 53                    }
 54
 255                    next = nums2[j];
 56
 257                    break;
 58                }
 559            }
 60
 561            result[i] = next;
 562        }
 63
 264        return result;
 265    }
 66}