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.

Find Longest Common Prefix in an Array of Strings

How to find longest common prefix in an array of strings.

Given an array of strings, write a method to find the longest common prefix string. If no common prefix is found, return an empty string ” “.

For example:

Example 1:

Input: [“cat”,”cable”,”camera”]
Output: “ca”

The longest common prefix is ca.

Example 2:

Input: [“rat”,”dog”,”elephant”]
Output: “”

No common prefix is found.