< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CheckStrings(...)100%1010100%
GetIndex(...)100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfStringsCanBeMadeEqualWithOperations2\CheckIfStringsCanBeMadeEqualWithOperations2FrequencyArray.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.CheckIfStringsCanBeMadeEqualWithOperations2;
 13
 14/// <inheritdoc />
 15public sealed class CheckIfStringsCanBeMadeEqualWithOperations2FrequencyArray :
 16    ICheckIfStringsCanBeMadeEqualWithOperations2
 17{
 18    private const byte AlphabetLength = 'z' - 'a' + 1;
 19
 20    /// <summary>
 21    ///     Time complexity - O(n)
 22    ///     Space complexity - O(1)
 23    /// </summary>
 24    /// <param name="s1"></param>
 25    /// <param name="s2"></param>
 26    /// <returns></returns>
 27    public bool CheckStrings(string s1, string s2)
 2028    {
 2029        Span<int> evenFrequencies = stackalloc int[AlphabetLength];
 2030        Span<int> oddFrequencies = stackalloc int[AlphabetLength];
 31
 24232        for (var i = 0; i < s1.Length; i++)
 10133        {
 10134            var index1 = GetIndex(s1[i]);
 10135            var index2 = GetIndex(s2[i]);
 36
 10137            if (i % 2 == 0)
 5238            {
 5239                evenFrequencies[index1]++;
 5240                evenFrequencies[index2]--;
 5241            }
 42            else
 4943            {
 4944                oddFrequencies[index1]++;
 4945                oddFrequencies[index2]--;
 4946            }
 10147        }
 48
 80649        for (var i = 0; i < AlphabetLength; i++)
 39050        {
 39051            if (oddFrequencies[i] == 0 && evenFrequencies[i] == 0)
 38352            {
 38353                continue;
 54            }
 55
 756            return false;
 57        }
 58
 1359        return true;
 2060    }
 61
 62    private static int GetIndex(char c)
 20263    {
 20264        return c - 'a';
 20265    }
 66}