< Summary

Information
Class: LeetCode.Algorithms.MakeTwoArraysEqualByReversingSubarrays.MakeTwoArraysEqualByReversingSubarraysDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MakeTwoArraysEqualByReversingSubarrays\MakeTwoArraysEqualByReversingSubarraysDictionary.cs
Line coverage
78%
Covered lines: 18
Uncovered lines: 5
Coverable lines: 23
Total lines: 55
Line coverage: 78.2%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CanBeEqual(...)80%111078.26%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MakeTwoArraysEqualByReversingSubarrays\MakeTwoArraysEqualByReversingSubarraysDictionary.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.MakeTwoArraysEqualByReversingSubarrays;
 13
 14/// <inheritdoc />
 15public class MakeTwoArraysEqualByReversingSubarraysDictionary : IMakeTwoArraysEqualByReversingSubarrays
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="target"></param>
 22    /// <param name="arr"></param>
 23    /// <returns></returns>
 24    public bool CanBeEqual(int[] target, int[] arr)
 325    {
 326        var targetDictionary = new Dictionary<int, int>();
 27
 2528        foreach (var targetKey in target)
 829        {
 830            if (!targetDictionary.TryAdd(targetKey, 1))
 031            {
 032                targetDictionary[targetKey]++;
 033            }
 834        }
 35
 2436        foreach (var arrKey in arr)
 837        {
 838            if (targetDictionary.TryGetValue(arrKey, out var targetValue))
 739            {
 740                if (targetValue == 0)
 041                {
 042                    return false;
 43                }
 44
 745                targetDictionary[arrKey] = targetValue - 1;
 746            }
 47            else
 148            {
 149                return false;
 50            }
 751        }
 52
 253        return true;
 354    }
 55}