Tag Archives: Programming Interview

Merge a linked list into another linked list at alternate positions

Given two linked lists, insert nodes of second list into first list at alternate positions of first list. eg. 1->5->7->3->9 6->10->2->4, the first list should become 1->6->5->10->7->2->3->4->9 and second list should become empty. The nodes of second list should only be inserted when there are positions available. If the first list is 1->2->3 and second Read More →

Root to leaf path with sum equal to given sum

Given a binary tree and a number,Write a function to find out whether there is a path from root to leaf with sum equal to given Number. In above tree, root to leaf paths exists for following sum. 7=> 1->2->4 9=> 1->3->5 10=>1->3->6 Implementation :

Remove characters from input string that are present in mask string

Write a C program that takes two strings as arguments and removes the characters from first string which are present in second string called mask string. ex: str1 “crazy for code” str2 “cod” Result: “razy e” Steps: 1) Get count array from mask string which stores count of chars from mask string. 2) Check for Read More →

Level of a given node in binary tree

Given a Binary Tree and a pointer to the Node in that tree. Write a function to find level of Node in the Tree. For Example, in the below tree            0        /   \      1      4    /  \    /  \  2   3    5    6 If the input key Read More →

Heap Data Structure

heapArray

Heap data structure is an array object that can be viewed as a nearly complete binary tree. Each node of the tree corresponds to an element of the array. The tree is completely filled on all levels except possibly the lowest , which is filled from the left up to a point. There are two Read More →

Write a program to count nodes in a tree

Approach: Traverse all the nodes in a tree. You can do any traversal and just start counting. But there is a concept called tail recursion which is handy and very easily readable. If you have a tree, if you know the number of nodes in the left and number of nodes in right +1, then, Read More →