Common Coding Interview Questions
Top 20 Interview Questions
20 Most Frequently Asked Programming Interview Questions
How is a bubble sort algorithm implemented?
How to print the first non-repeated character from a string?
How to find the first non repeated character of a given String?
How do you find duplicate numbers in an array if it contains multiple duplicates?
How do you remove duplicates from an array in place?
How are duplicates removed from an array without using any library?
How do you find the middle element of a singly linked list in one pass?
How do you check if a given linked list contains a cycle? How will you find initial node of the cycle?
How do you reverse a singly linked list without recursion?
How is a binary search tree implemented?
A binary search tree (BST) is a node-based binary tree data structure which has the following properties:
- The left subtree of a node contains only nodes with keys lesser than the node’s key.
- The right subtree of a node contains only nodes with keys greater than the node’s key.
- The left and right subtree each must also be a binary search tree.
How do you traverse a given binary tree in preorder without recursion?
How do you print all nodes of a given binary tree using inorder traversal without recursion?
How is a merge sort algorithm implemented?
How is a radix sort algorithm implemented?
- Radix sort is a non-comparative sorting algorithm that sorts data with integer keys by grouping the keys into buckets.
- Reference: https://www.geeksforgeeks.org/radix-sort/
How do you swap two numbers without using the third variable?
In Python, we can swap two numbers without using the third variable by using a tuple assignment.
a, b = 1, 2
a, b = b, a
How do you design a vending machine?
Write a program to find prime factors of an integer?
def prime_factors(n):
factors = []
while n % 2 == 0:
factors.append(2)
n //= 2
for i in range(3, int(n**0.5) + 1, 2):
while n % i == 0:
factors.append(i)
n //= i
return factors
What is Depth First Search Algorithm for a binary tree?
- DFS is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking.
def dfs(node):
if node is None:
return
dfs(node.left)
dfs(node.right)
Difference between a stable and unstable sorting algorithm?
- Stability is mainly essential when we have key-value pairs with duplicate keys possible (like people’s names as keys and their details as values). And we wish to sort these objects by keys.
- A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input data set
What is the difference between Comparison and Non-Comparison Sorting Algorithms?
- Comparison sorting algorithms sort data by comparing the values in the data set to each other. The most common comparison sorting algorithms include bubble sort, insertion sort, selection sort, merge sort, quick sort, heap sort.
- Non-comparison sorting algorithms sort data without comparing the values in the data set to each other. Instead, they use specific properties of the data to sort it. The most common non-comparison sorting algorithms include counting sort, radix sort, and bucket sort.
Enjoy Reading This Article?
Here are some more articles you might like to read next: