Check whether Array represents a Fibonacci Series or not | Returns true if a permutation of arr [ 0. . n - 1 ] can form a Fibonacci Series ; Sort array ; After sorting , check if every element is equal to the sum of previous 2 elements ; Driver Code
def checkIsFibonacci ( arr , n ) : NEW_LINE INDENT if ( n == 1 or n == 2 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT arr . sort ( ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( ( arr [ i - 1 ] + arr [ i - 2 ] ) != arr [ i ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 8 , 3 , 5 , 13 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE if ( checkIsFibonacci ( arr , n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT