human
Write me a code to largest subset whose all elements are Fibonacci numbers and the other steps required given the following:
Largest subset whose all elements are Fibonacci numbers | Prints largest subset of an array whose all elements are fibonacci numbers.
Find maximum element in arr [ ].
Generate all Fibonacci numbers till max and store them in hash ..
Npw iterate through all numbers and quickly check for Fibonacci using hash ..
Driver code"
How can the above be solved in Python?
assistant
#Here is code to largest subset whose all elements are Fibonacci numbers and the other steps required.
 def findFibSubset ( arr , n ) :
	m = max ( arr )
	a = 0
	b = 1
	hash = [ ]
	hash . append ( a )
	hash . append ( b )
	while ( b < m ) :
		c = a + b
		a = b
		b = c
		hash . append ( b )
	for i in range ( n ) :
		if arr [ i ] in hash :
			print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 4 , 2 , 8 , 5 , 20 , 1 , 40 , 13 , 23 ]
	n = len ( arr )
	findFibSubset ( arr , n )