X

View By:

Reverse the adjacent nodes in a linked list If the nodes of a linked list are as follows 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 then after reverse they should be 2 -> 1 -> 4 -> 3 Here the number of entries are odd hence the last link is not reversed. If number of nodes are even then last node should also be reversed.

Q2 Print the binary tree using Breadth First Traversal but reverse the elements of every nth breadth

Imagine we have a binary tree having following structure. Please see the structure at following link

![http://mathworld.wolfram.com/images/eps-gif/CompleteBinaryTree_1000.gif]

We need to print the tree using breadth first traversal but need to reverse the elements of every nth breadth from a provided starting point. I have used additional stack with queue to get the desired functionality. It will be more easier for users to understand the problem after running the code and seeing the output.

Q3 Find the path in 2 Dimensional array which has the most 1

You have a m*n size 2 Dimensional Array filled with either 0 or 1. You have to figure out the path which contains the most 1 when starting from arr[0][0]. You can only traverse down or right.

For ex: If array has values

1 1 0 1 0 1 1 0 1 0 0 1

So here the path containing max 1 is arr[0][0], arr[0][1], arr[1][1], arr[1][2], arr[1][3] and arr[2][3]

Q4 Balanced BST

Find two elements in balanced BST which sums to a given a value. Constraints Time O(n) and space O(logn).
``````      6
3         8
``````

1 4 7 12

sum = 16 o/p should be 4 and 12

Q5 URL Detection

MS Word has the inbuilt logic to detect the url when user writes to any document. MS Word application detects the url typed by user and hyperlinks it. Write a code to:

1) Detect url assuming that MS Word engine streams the characters to your function BOOL DetectURL(UCHAR chUserCharEntry) 2) Once #1 is completed then execute the url from IE

Q6 Find position of a string in another string

Find position of a string in another string.

Q7 Find position of a string in another string.

Find position of a string in another string. For example your first string is 'careerstack' and the second string is 'stack' then the output should be 7.

Q8 Given a preorder and a postorder traversal, construct the tree.

Given a preorder and postorder traversal of a Binary Tree, construct the tree using these two traversals.

Q9 Number of occurrences of a number in a sorted array.

Given a sorted array, find the number of occurrences of an element in the array. Give a O(logn) time solution.

Q10 Find the intervals from a set of intervals in which a given point lies

Given a set of intervals such as (10,20), (15,25), (28,40), (50,70), (0,9) (60,90) and build a data structure. Query the data structure for point x, and it find out all the intervals that contain this point x.