Sunday, July 17, 2022

Equal Levels | HackerRank

public static int updateTimes(List<int> signalOne,
     List<int> signalTwo)
{
    int noOfUpdate = 0;
    int maxEqual = int.MinValue;
    int length;
    int signalOneCount = signalOne.Count;
    int signalTwoCount = signalTwo.Count;

    if(signalOneCount < signalTwoCount)
        length = signalOneCount;
    else
        length = signalTwoCount;

    for(int i = 0; i < length; i++)
    {
        if(signalOne[i] == signalTwo[i])
        {
            if(maxEqual < signalOne[i])
            {
                maxEqual = signalOne[i];
                noOfUpdate++;
            }
        }
    }
    return noOfUpdate;
} 

No comments:

Post a Comment

horizontal ads