Sort an Array of 0s, 1s and 2s

Given an array consisting of 0s, 1s, and 2s. Write code to sort an array of 0s, 1s, and 2s without using an extra space or a sorting algorithm.

OR

Given an array of size n containing only 0s, 1s, and 2s. Write a code to sort the array in ascending order.

For example:

Input  : {0, 1, 1, 0, 1, 2, 0, 1, 2}

Output : {0, 0, 0, 1, 1, 1, 1, 2, 2}

In this example, the input array only consists of 0s, 1s, and 2s in an unsorted order.

In the output array, all the 0s, 1s and 2s are in sorted order.

Binary Tree Inorder Traversal without Recursion using Stack

In this tutorial, I am going to discuss binary tree inorder traversal without recursion.

Given a binary tree, write a code to print the Inorder traversal of a binary tree node values.

What is Binary Tree Inorder Traversal?

Traversing a tree means visiting each node of the tree exactly once. In inorder traversal, we visit the tree in following order.

i) Visit all the nodes of the left subtree.

ii) Visit root node.

iii) Visit all the nodes of the right subtree.

Find the Intersection of Two Linked Lists

In this tutorial, i am going to explain how to find the intersection of two linked lists. 

Given the heads of two singly linked lists. We have to write a code to find the intersection point of two linked lists. If no intersection point is found then return null.

You may assume there are no cycles anywhere in the entire linked structure. We have to solve this problem in O(n) time complexity and by using O(1) space.

For example:

Linked list 1:  4 -> 6 -> 2 -> 7 -> NULL

Linked list 2: 8 -> 2-> 7 -> NULL

In this example, the intersection point of two lists is at node 2.