Banana-Leopard/TASTY huggingface dataset:
# python3 program to find largest Fibonacci subset
# Prints largest subset of an array whose
# all elements are fibonacci numbers
def findFibSubset(arr, n):
  #Now iterate through all elements of the array..
  for i in range(n):
    #we are using the property of fibonacci series to check arr[i] is a
    # fib number or not by checking whether any one out of 5(n^2)+4 and 5(n^2)-4
    # is a perfect square or not.
    fact1=5*(arr[i]**2)+4
    fact2=5*(arr[i]**2)-4
    if int(fact1**(.5))**2==fact1 or int(fact2**(.5))**2==fact2:
      print(arr[i],end=" ")
  return None
          
         
 # Driver code
if __name__ == "__main__":
  
    arr = [4, 2, 8, 5, 20, 1, 40, 13, 23]
    n = len(arr)
    findFibSubset(arr, n)      
 # This code is contributed by Rajat Kumar (GLA University)

Time complexity: linear
Space complexity: constant
# python3 program to find largest Fibonacci subset
  
# Prints largest subset of an array whose
# all elements are fibonacci numbers
def findFibSubset(arr, n):
 
    # Find maximum element in arr[]
    m= max(arr)
  
    # Generate all Fibonacci numbers till
    # max and store them in hash.
    a = 0
    b = 1
    hash = []
    hash.append(a)
    hash.append(b)
    while (b < m):
     
        c = a + b
        a = b
        b = c
        hash.append(b)
     
  
    # Npw iterate through all numbers and
    # quickly check for Fibonacci using
    # hash.
    for i in range (n):
        if arr[i] in hash :
            print( arr[i],end=" ")
  
# Driver code
if __name__ == "__main__":
 
    arr = [4, 2, 8, 5, 20, 1, 40, 13, 23]
    n = len(arr)
    findFibSubset(arr, n)

Time complexity: linear
Space complexity: linear
# A brute force approach based Python3 program to
# find if there is a rectangle with 1 as corners.
 
# Returns true if there is a rectangle
# with 1 as corners.
def isRectangle(m):
 
    # finding row and column size
    rows = len(m)
    if (rows == 0):
        return False
    columns = len(m[0])
 
    # scanning the matrix
    for y1 in range(rows):
 
        for x1 in range(columns):
 
            # if any index found 1 then
            # try for all rectangles
            if (m[y1][x1] == 1):
                for y2 in range(y1 + 1, rows):
                    for x2 in range(x1 + 1, columns):
                        if (m[y1][x2] == 1 and
                            m[y2][x1] == 1 and
                            m[y2][x2] == 1):
                            return True
    return False
 
# Driver code
mat = [[1, 0, 0, 1, 0],
       [0, 0, 1, 0, 1],
       [0, 0, 0, 1, 0],
       [1, 0, 1, 0, 1]]
 
if (isRectangle(mat)):
    print("Yes")
else:
    print("No")
 
# This code is contributed
# by mohit kumar 29

Time complexity: quadratic
Space complexity: constant
# An efficient approach based Python program
# to find if there is a rectangle with 1 as
# corners.
 
# Returns true if there is a rectangle
# with 1 as corners.
def isRectangle(matrix):
 
    # finding row and column size
    rows = len(matrix)
    if (rows == 0):
        return False
 
    columns = len(matrix[0])
 
    # map for storing the index of
    # combination of 2 1's
    table = {}
 
    # scanning from top to bottom
    # line by line
    for i in range(rows):
        for j in range(columns - 1):
            for k in range(j + 1, columns):
 
                # if found two 1's in a column
                if (matrix[i][j] == 1 and
                    matrix[i][k] == 1):
 
                    # check if there exists 1's in same
                    # row previously then return true
                    if (j in table and k in table[j]):
                        return True
 
                    if (k in table and j in table[k]):
                        return True
 
                    # store the indexes in hashset
                    if j not in table:
                        table[j] = set()
                    if k not in table:
                        table[k] = set()
                    table[j].add(k)
                    table[k].add(j)
    return False
 
# Driver Code
if __name__ == '__main__':
    mat = [[ 1, 0, 0, 1, 0 ],
           [ 0, 0, 1, 0, 1 ],
           [ 0, 0, 0, 1, 0 ],
           [ 1, 0, 1, 0, 1 ]]
    if (isRectangle(mat)):
        print("Yes")
    else:
        print("No")
     
# This code is contributed
# by SHUBHAMSINGH10

Time complexity: quadratic
Space complexity: quadratic
# Python3 implementation comes from:
# https:#github.com/MichaelWehar/FourCornersProblem
# Written by Niteesh Kumar and Michael Wehar
# References:
#   [1] F. Mráz, D. Prusa, and M. Wehar.
#   Two-dimensional Pattern Matching against
#    Basic Picture Languages. CIAA 2019.
#   [2] D. Prusa and M. Wehar. Complexity of
#    Searching for 2 by 2 Submatrices in Boolean
#    Matrices. DLT 2020.
def searchForRectangle( rows,  cols, mat) :
 
    # Make sure that matrix is non-trivial
    if (rows < 2 or cols < 2) :
     
        return False;
     
    # Create map
    adjsList = dict();
    if (rows >= cols):
     
        # Row-wise
        num_of_keys = rows;
         
        # Convert each row into vector of col indexes
        for i in range(rows):
             
            for j in range(cols):
         
                if (mat[i][j]):
                     
                    if i not in adjsList:
                        adjsList[i] = []
                    adjsList[i].append(j);
    else :
     
        # Col-wise
        num_of_keys = cols;
         
        # Convert each col into vector of row indexes
        for i in range(rows):
             
            for j in range(cols):
         
                if (mat[i][j] == 1) :
                     
                    if j not in adjsList:
                        adjsList[j] = []
                    adjsList[j].append(i);
                 
    # Search for a rectangle whose four corners are 1's
    pairs = dict();
     
    for i in range(num_of_keys):
 
        values = adjsList[i];
        size = len(values)
         
        for j in range(size - 1):
             
            for k in range(j + 1, size):
 
                temp  = (values[j], values[k]);
                 
                if temp in pairs:
                    return True;
                  
                else:
                    pairs[temp] = i;
    return False;
 
# Driver code
mat =   [[ 1, 0, 0, 1, 0 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 0, 1, 0 ], [ 1, 1, 1, 1, 0 ]];
if (searchForRectangle(4, 5, mat)):
    print("Yes");
else:
    print("No")
     
# This code is contributed by phasing17.

Time complexity: quadratic
Space complexity: quadratic
# Python3 program for finding
# maximum area possible of
# a rectangle
 
# function for finding
# max area
def findArea(arr, n):
 
    # sort array in
    # non-increasing order
    arr.sort(reverse = True)
 
    # Initialize two
    # sides of rectangle
    dimension = [0, 0]
 
    # traverse through array
    i = 0
    j = 0
    while(i < n - 1 and j < 2):
 
        # if any element occurs twice
        # store that as dimension
        if (arr[i] == arr[i + 1]):
            dimension[j] = arr[i]
            j += 1
            i += 1
        i += 1
         
    # return the product
    # of dimensions
    return (dimension[0] *
            dimension[1])
 
# Driver code
arr = [4, 2, 1, 4, 6, 6, 2, 5]
n = len(arr)
print(findArea(arr, n))
 
# This code is contributed
# by Smitha

Time complexity: nlogn
Space complexity: constant
# Python 3 program for finding maximum
# area possible of a rectangle
 
# function for finding max area
def findArea(arr, n):
 
    s = []
 
    # traverse through array
    first = 0
    second = 0
    for i in range(n) :
 
        # If this is first occurrence of
        # arr[i], simply insert and continue
        if arr[i] not in s:
            s.append(arr[i])
            continue
 
        # If this is second (or more) occurrence,
        # update first and second maximum values.
        if (arr[i] > first) :
            second = first
            first = arr[i]
        else if (arr[i] > second):
            second = arr[i]
 
    # return the product of dimensions
    return (first * second)
 
# Driver Code
if __name__ == "__main__":
     
    arr = [ 4, 2, 1, 4, 6, 6, 2, 5 ]
    n = len(arr)
    print(findArea(arr, n))
 
# This code is contributed by ita_c

Time complexity: linear
Space complexity: linear
# Python3 implementation to find length of
# longest strict bitonic subsequence
 
# function to find length of longest
# strict bitonic subsequence
def longLenStrictBitonicSub(arr, n):
 
    # hash table to map the array element
    # with the length of the longest subsequence
    # of which it is a part of and is the
    # last/first element of that subsequence
    inc, dcr = dict(), dict()
 
    # arrays to store the length of increasing
    # and decreasing subsequences which end at
    # them or start from them
    len_inc, len_dcr = [0] * n, [0] * n
 
    # to store the length of longest strict
    # bitonic subsequence
    longLen = 0
 
    # traverse the array elements
    # from left to right
    for i in range(n):
 
        # initialize current length
        # for element arr[i] as 0
        len = 0
 
        # if 'arr[i]-1' is in 'inc'
        if inc.get(arr[i] - 1) in inc.values():
            len = inc.get(arr[i] - 1)
         
        # update arr[i] subsequence length in 'inc'    
        # and in len_inc[]
        inc[arr[i]] = len_inc[i] = len + 1
     
    # traverse the array elements
    # from right to left
    for i in range(n - 1, -1, -1):
 
        # initialize current length
        # for element arr[i] as 0
        len = 0
 
        # if 'arr[i]-1' is in 'dcr'
        if dcr.get(arr[i] - 1) in dcr.values():
            len = dcr.get(arr[i] - 1)
         
        # update arr[i] subsequence length 
        # in 'dcr' and in len_dcr[]
        dcr[arr[i]] = len_dcr[i] = len + 1
     
    # calculating the length of
    # all the strict bitonic subsequence
    for i in range(n):
        if longLen < (len_inc[i] + len_dcr[i] - 1):
            longLen = len_inc[i] + len_dcr[i] - 1
     
    # required longest length strict
    # bitonic subsequence
    return longLen
 
# Driver Code
if __name__ == "__main__":
    arr = [1, 5, 2, 3, 4, 5, 3, 2]
    n = len(arr)
    print("Longest length strict bitonic subsequence =",
           longLenStrictBitonicSub(arr, n))
 
# This code is contributed by sanjeev2552

Time complexity: linear
Space complexity: linear
# Python3 program to find last seen
# element in an array.
import sys;
 
# Returns last seen element in arr[]
def lastSeenElement(a, n):
     
    # Store last occurrence index of
    # every element
    hash = {}
     
    for i in range(n):
        hash[a[i]] = i
         
    # Find an element in hash with minimum
    # index value
    res_ind = sys.maxsize
    res = 0
     
    for x, y in hash.items():
        if y < res_ind:
            res_ind = y
            res = x
             
    return res
 
# Driver code   
if __name__=="__main__":
     
    a = [ 2, 1, 2, 2, 4, 1 ]
    n = len(a)
     
    print(lastSeenElement(a,n))
 
# This code is contributed by rutvik_56

Time complexity: linear
Space complexity: linear
# Python program to delete a node in a linked list
# at a given position
 
# Node class
 
 
class Node:
 
    # Constructor to initialize the node object
    def __init__(self, data):
        self.data = data
        self.next = None
 
 
class LinkedList:
 
    # Constructor to initialize head
    def __init__(self):
        self.head = None
 
    # Function to insert a new node at the beginning
    def push(self, new_data):
        new_node = Node(new_data)
        new_node.next = self.head
        self.head = new_node
 
    # Given a reference to the head of a list
    # and a position, delete the node at a given position
    # This delete function code is contributed by Arabin Islam
    def deleteNodeAtGivenPosition(self, position):
        if self.head is None:
            return
        index = 0
        current = self.head
        while current.next and index < position:
            previous = current
            current = current.next
            index += 1
        if index < position:
            print("\nIndex is out of range.")
        elif index == 0:
            self.head = self.head.next
        else:
            previous.next = current.next
            # current = None #Optional statement
 
    # Utility function to print the LinkedList
 
    def printList(self):
        temp = self.head
        while(temp):
            print(" %d " % (temp.data), end=" ")
            temp = temp.next
 
 
# Driver program to test above function
llist = LinkedList()
llist.push(7)
llist.push(1)
llist.push(3)
llist.push(2)
llist.push(8)
 
print("Created Linked List: ")
llist.printList()
llist.deleteNodeAtGivenPosition(4)
print("\nLinked List after Deletion at position 4: ")
llist.printList()
 
# This code is contributed by Nikhil Kumar Singh(nickzuck_007)

Time complexity: linear
Space complexity: constant
# Python3 program to delete all
# the nodes of singly linked list
 
# Node class
 
 
class Node:
 
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
 
 
# Constructor to initialize the node object
class LinkedList:
 
    # Function to initialize head
    def __init__(self):
        self.head = None
 
    def deleteList(self):
 
        # initialize the current node
        current = self.head
        while current:
            next_to_current = current.next  # move next node
 
            # delete the current node
            del current.data
 
            # set current equals prev node
            current = next_to_current
 
        # In python garbage collection happens
        # therefore, only
        # self.head = None
        # would also delete the link list
 
    # push function to add node in front of llist
    def push(self, new_data):
 
        # Allocate the Node &
        # Put in the data
        new_node = Node(new_data)
 
        # Make next of new Node as head
        new_node.next = self.head
 
        # Move the head to point to new Node
        self.head = new_node
 
 
# Use push() to construct below
# list 1-> 12-> 1-> 4-> 1
if __name__ == '__main__':
 
    llist = LinkedList()
    llist.push(1)
    llist.push(4)
    llist.push(1)
    llist.push(12)
    llist.push(1)
 
    print("Deleting linked list")
    llist.deleteList()
 
    print("Linked list deleted")
 
 
# This article is provided by Shrikant13

Time complexity: linear
Space complexity: constant
# A complete working Python program to find length of a
# Linked List iteratively
 
# Node class
 
 
class Node:
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
 
 
# Linked List class contains a Node object
class LinkedList:
 
    # Function to initialize head
    def __init__(self):
        self.head = None
 
    # This function is in LinkedList class. It inserts
    # a new node at the beginning of Linked List.
 
    def push(self, new_data):
 
        # 1 & 2: Allocate the Node &
        #     Put in the data
        new_node = Node(new_data)
 
        # 3. Make next of new Node as head
        new_node.next = self.head
 
        # 4. Move the head to point to new Node
        self.head = new_node
 
    # This function counts number of nodes in Linked List
    # iteratively, given 'node' as starting node.
 
    def getCount(self):
        temp = self.head  # Initialise temp
        count = 0  # Initialise count
 
        # Loop while end of linked list is not reached
        while (temp):
            count += 1
            temp = temp.next
        return count
 
 
# Driver code
if __name__ == '__main__':
    llist = LinkedList()
    llist.push(1)
    llist.push(3)
    llist.push(1)
    llist.push(2)
    llist.push(1)
     
    # Function call
    print("Count of nodes is :", llist.getCount())

Time complexity: linear
Space complexity: constant
# A complete working Python program to find length of a
# Linked List recursively
 
# Node class
 
 
class Node:
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
 
 
# Linked List class contains a Node object
class LinkedList:
 
    # Function to initialize head
    def __init__(self):
        self.head = None
 
    # This function is in LinkedList class. It inserts
    # a new node at the beginning of Linked List.
 
    def push(self, new_data):
 
        # 1 & 2: Allocate the Node &
        #        Put in the data
        new_node = Node(new_data)
 
        # 3. Make next of new Node as head
        new_node.next = self.head
 
        # 4. Move the head to point to new Node
        self.head = new_node
 
    # This function counts number of nodes in Linked List
    # recursively, given 'node' as starting node.
    def getCountRec(self, node):
        if (not node):  # Base case
            return 0
        else:
            return 1 + self.getCountRec(node.next)
 
    # A wrapper over getCountRec()
    def getCount(self):
        return self.getCountRec(self.head)
 
 
# Code execution starts here
if __name__ == '__main__':
    llist = LinkedList()
    llist.push(1)
    llist.push(3)
    llist.push(1)
    llist.push(2)
    llist.push(1)
    print('Count of nodes is :', llist.getCount())

Time complexity: linear
Space complexity: linear
# A complete working Python3 program to find length of a
# Linked List using Tail recursion.
 
# Node class
 
 
class Node:
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
 
 
# Linked List class contains a Node object
class LinkedList:
 
    # Function to initialize head
    def __init__(self):
        self.head = None
 
    # This function is in LinkedList class. It inserts
    # a new node at the beginning of Linked List.
 
    def push(self, new_data):
 
        # 1 & 2: Allocate the Node &
        #     Put in the data
        new_node = Node(new_data)
 
        # 3. Make next of new Node as head
        new_node.next = self.head
 
        # 4. Move the head to point to new Node
        self.head = new_node
 
    # This function counts number of nodes in Linked List
    # recursively, given 'node' as starting node using Tail Recursion.
    def getCountRec(self, node, count=0):
        if (not node):  # Base case
            return count
        else:
            return self.getCountRec(node.next, count+1)
 
    # A wrapper over getCountRec()
    def getCount(self):
        return self.getCountRec(self.head)
 
 
# Driver code
if __name__ == '__main__':
    llist = LinkedList()
    llist.push(1)
    llist.push(3)
    llist.push(1)
    llist.push(2)
    llist.push(1)
     
    # Function call
    print('Count of nodes is :', llist.getCount())
 
    # This code is contributed by garinesrija.

Time complexity: linear
Space complexity: constant
# Iterative Python3 program to search an element
# in linked list
 
# Node class
 
 
class Node:
 
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
 
# Linked List class
 
 
class LinkedList:
    def __init__(self):
        self.head = None  # Initialize head as None
 
    # This function insert a new node at the
    # beginning of the linked list
    def push(self, new_data):
 
        # Create a new Node
        new_node = Node(new_data)
 
        # 3. Make next of new Node as head
        new_node.next = self.head
 
        # 4. Move the head to point to new Node
        self.head = new_node
 
    # This Function checks whether the value
    # x present in the linked list
    def search(self, x):
 
        # Initialize current to head
        current = self.head
 
        # loop till current not equal to None
        while current != None:
            if current.data == x:
                return True  # data found
 
            current = current.next
 
        return False  # Data Not found
 
 
# Driver code
if __name__ == '__main__':
 
    # Start with the empty list
    llist = LinkedList()
 
    ''' Use push() to construct below list
        14->21->11->30->10 '''
    llist.push(10)
    llist.push(30)
    llist.push(11)
    llist.push(21)
    llist.push(14)
 
       # Function call
    if llist.search(21):
        print("Yes")
    else:
        print("No")
 
# This code is contributed by Ravi Shankar

Time complexity: linear
Space complexity: constant
# Recursive Python program to
# search an element in linked list
 
# Node class
 
 
class Node:
 
    # Function to initialise
    # the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
 
 
class LinkedList:
 
    def __init__(self):
        self.head = None  # Initialize head as None
 
    # This function insert a new node at
    # the beginning of the linked list
    def push(self, new_data):
 
        # Create a new Node
        new_node = Node(new_data)
 
        # Make next of new Node as head
        new_node.next = self.head
 
        # Move the head to
        # point to new Node
        self.head = new_node
 
    # Checks whether the value key
    # is present in linked list
 
    def search(self, li, key):
 
        # Base case
        if(not li):
            return False
 
        # If key is present in
        # current node, return true
        if(li.data == key):
            return True
 
        # Recur for remaining list
        return self.search(li.next, key)
 
 
# Driver Code
if __name__ == '__main__':
 
    li = LinkedList()
 
    li.push(1)
    li.push(2)
    li.push(3)
    li.push(4)
 
    key = 4
 
    # Function call
    if li.search(li.head, key):
        print("Yes")
    else:
        print("No")
 
# This code is contributed
# by Manoj Sharma

Time complexity: linear
Space complexity: linear
# Python3 program to find middle of linked list
# Node class
class Node:
   
    # Function to initialise the node object
    def __init__(self, data):
        self.data = data  # Assign data
        self.next = None  # Initialize next as null
   
   
# Linked List class contains a Node object
class LinkedList:
   
    # Function to initialize head
    def __init__(self):
        self.head = None
 
    # Function to insert a new node at the beginning 
    def push(self, new_data): 
        new_node = Node(new_data) 
        new_node.next = self.head 
        self.head = new_node
 
    # Print the linked list
    def printList(self):
        node = self.head
        while node:
            print(str(node.data) + "->", end="")
            node = node.next
        print("NULL")
 
    # Function that returns middle.
    def printMiddle(self):
        # Initialize two pointers, one will go one step a time (slow), another two at a time (fast)
        slow = self.head
        fast = self.head
 
        # Iterate till fast's next is null (fast reaches end)
        while fast and fast.next:
            slow = slow.next
            fast = fast.next.next
         
        # return the slow's data, which would be the middle element.
        print("The middle element is ", slow.data)
 
# Code execution starts here
if __name__=='__main__':
   
    # Start with the empty list
    llist = LinkedList()
   
    for i in range(5, 0, -1):
        llist.push(i)
        llist.printList()
        llist.printMiddle()
 
 # Code is contributed by Kumar Shivam (kshivi99)

Time complexity: linear
Space complexity: constant