Simple code for java


#1

public class Solution
{
public int findCount(final List A, int B)
{
int index = A.indexOf(B);
int num =0;

    if(index==-1)
    return 0;
    
    while(index<A.size())
    {
        if(A.get(index)==B)
        {
            index++;
            num++;
        }
        else 
        break;
    }
    return num;
}

}


#2

Time complexity of code is O(n) as indexOf() does linear search. It is asked to complete in O(log n).