Solutions for Pythagoras

    • @kristeencoupp91
    • @Ethan, submitted in Python 3, achived 100% score
    def solve(ar): 
        n = len(ar)
        y="YES"
        # Square all the elemennts 
        for i in range(n): 
            ar[i] = ar[i] * ar[i] 
    
        # sort array elements 
        ar.sort() 
    
        # fix one element 
        # and find other two 
        # i goes from n - 1 to 2 
        for i in range(n-1, 1, -1): 
            # start two index variables from  
            # two corners of the array and  
            # move them toward each other 
            j = 0
            k = i - 1
            while (j < k): 
                # A triplet found 
                if (ar[j] + ar[k] == ar[i]): 
                    return y
                else: 
                    if (ar[j] + ar[k] < ar[i]): 
                        j = j + 1
                    else: 
                        k = k - 1
        # If we reach here, then no triplet found 
        n="No"
        return n