• + 6 comments

    Hey, there must be a issue with the problem. For the first testcase I'm getting 197 and the expected response is 196.

    • Max=9991
    • 9 count=106
    • 26 count=34
    • 27 count=31
    • 45 count=15
    • 61 count=7
    • 76 count=3
    • 86 count=1
    • 98 count=0

    Can someone tell me what I'm doing wrong?

    I started with brute force and I'm getting the same results. To avoid getting "timeout" I'm sorting the array, the last value is the max. For every processed value that is repeating I'm using the last computed value-1.

    C Sharp

    static int solve(int[] arr) {

        arr=arr.OrderBy(a=>a).ToArray();
        int max=arr[arr.Length-1];
        Console.WriteLine($"max={max}");
        int toReturn=0;
        int lastNumber=-1;
        int cnt=0;
        for (int i=0;i<arr.Length-1;i++){
            Console.Write(arr[i]);      
            if (lastNumber==arr[i]){
                toReturn+=--cnt;
                continue;
            }else{
                lastNumber=arr[i];
                cnt=0;
            }
            var diff=max/arr[i];
    
            for (int j=i+1;j<arr.Length;j++){
                if (arr[j]<=diff){
                        cnt++;
                }else{
                    break;
                }
            }
            Console.WriteLine($" count={cnt}");
            if (cnt==0){
                break;
            }
            toReturn+=cnt;
        }
            return toReturn;
    }