< Summary

Information
Class: LeetCode.Algorithms.FindThePrefixCommonArrayOfTwoArrays.FindThePrefixCommonArrayOfTwoArraysFrequencyArray
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindThePrefixCommonArrayOfTwoArrays\FindThePrefixCommonArrayOfTwoArraysFrequencyArray.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FindThePrefixCommonArray(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindThePrefixCommonArrayOfTwoArrays\FindThePrefixCommonArrayOfTwoArraysFrequencyArray.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.FindThePrefixCommonArrayOfTwoArrays;
 13
 14/// <inheritdoc />
 15public class FindThePrefixCommonArrayOfTwoArraysFrequencyArray : IFindThePrefixCommonArrayOfTwoArrays
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="a"></param>
 22    /// <param name="b"></param>
 23    /// <returns></returns>
 24    public int[] FindThePrefixCommonArray(int[] a, int[] b)
 225    {
 226        var result = new int[a.Length];
 227        var frequencyArray = new int[a.Length];
 228        var count = 0;
 29
 1830        for (var i = 0; i < a.Length; i++)
 731        {
 732            frequencyArray[a[i] - 1]++;
 33
 734            if (frequencyArray[a[i] - 1] == 2)
 335            {
 336                count++;
 337            }
 38
 739            frequencyArray[b[i] - 1]++;
 40
 741            if (frequencyArray[b[i] - 1] == 2)
 442            {
 443                count++;
 444            }
 45
 746            result[i] = count;
 747        }
 48
 249        return result;
 250    }
 51}