Meta interview question

What is linked list? Bubble sort

Interview Answers

Anonymous

31 Jul 2022

import json import json_wrapper import array as arr # Best O(n) | Average def bubbleSort(array): isSorted = False counter = 0 while not isSorted: isSorted = True for i in range(len(array) - 1 - counter): if array[i] > array[i + 1]: swap(i, i + 1, array) isSorted = False counter += 1 return array def swap(i, j, array): array[i], array[j] = array[j], array[i]

Anonymous

31 Jul 2022

# node class class Node: # initialize node obj def __init__(self, data): self.data = data # assignments self.next = next # next --> null class LinkedList: def __init__(self): self.head = none def printList(self): temp = self.head while (temp): print(temp.data) temp = temp.next if __name__ == '__main__': # start == emptyL llist = LinkedList() llist.head = Node(1) second = Node(2) third = Node(3) llist.head.next = second; # link first to second second.next = third; # then second to next(third) llist.printList() # out = 1, 2, 3