Lassi

 avatar
bruteCoder
java
8 months ago
537 B
4
Indexable
Never
class Solution {
    
    public boolean countSub(long arr[], long n)
    {
        // Your code goes here
        
        for(int i = 0 ;i<n;i++){
            if(!condiChecker(arr,n,i)) return false;
        }
        
        return true;
       
    }
    
    public boolean condiChecker(long arr[],long n , int i){
        int left = i*2 +1;
        int right = i*2+2;
        
        if(left < n && arr[left] > arr[i]) return false;
        if(right < n && arr[right] > arr[i]) return false;
        
        return true;
    }
}
Leave a Comment