Professional Documents
Culture Documents
3Q.WriteaCprogramtocalculatepow(x,n)
2Q.Checkforbalancedparenthesesinanexpression
1Q.Printallcombinationsofbalancedparentheses
General Set 1
12Q. Count total set bits in all numbers from 1 to n
11Q. Given a function which returns true 60% time and false 40% time.
Using this function you have to write a function which returns true 50% of the time.
10Q. Given top(x,y) and bottom(x,y) of two rectangles, find if two rectangles have some common
area return 1 otherwise return 0;
9Q. Given set of coins {1, 3, 4 ,5 } find min number of coins required to get sum amount.
8Q. Get the all the possible bracket matching by k number of brackets
7Q. Fibonacci series by recursion and while loop
6Q. Given a (decimal - e.g. 21.125) number N that is passed in as a string, print the binary
5Q. Merge Overlapping Intervals
4Q. Write a C program to swap two variables without using a temporary variable
3Q. Find highest from a,b,c using ternary operator:
2Q. Write a C program to convert a decimal number into a binary number.
1Q. Write code to add two polynomials.
Questions: Array
34Q.LongestMonotonicallyIncreasingSubsequenceSize(NlogN)
33Q.Replaceeveryelementwiththenextgreatest
32Q. An array of n integers is there in which the range of elements is n, i.e., the difference between
maximum and minimum number is n. Find the repeating numbers.
31Q. Given set of coins {1, 3, 4 ,5 } find min number of coins required to get sum amount.
30Q. WAP to scan an 2D array in ZigZag order. print the values.
29Q. Find the row with maximum number of 1s
28Q. Array of numbers, jump as frog to reach the number if possible return 0 else -1
27Q. Given an array of N elements, A[0 .. N - 1], Produce an array B such that: B[i] = min (A[i],
A[i+1], ..., A[i+K-1]). (The array B will have exactly (N-k+1) elements.
26Q. Two sets (arrays) A and B are given. Find two no. a and b from A and B respectively such that
a+b=val, where val is another input. Answer: O(n lgn)
25Q. Given a sorted array and a number, find two numbers which sum to the number k . Write test
cases for same.
24Q. How to find sum of three numbers in an array is K?
23Q. How to find sum of four numbers in an array is K?
22Q. How to rotate a matrix 90 degrees without using any extra space?
21Q. Given a N*N Matrix. All rows are sorted, and all columns are sorted. Find the Kth Largest
element of the matrix. http://www.careercup.com/question?id=6335704
20Q. Given two sorted arrays A, B of size m and n respectively. Find the k-th smallest element in the
union of A and B. You can assume that there are no duplicate elements.
19Q. There are m sorted arrays of each size n. You have another array B of size m*n. Fill the array B
from the m arrays in sorted order.Give the optimal solution.
qar
Youarealsogivenacollectionofletters.E.g.,{a,e,f,f,g,i,r,q}.
Thetaskistofindthelongestwordinthedictionarythatcanbespelledwiththe
collectionofletters.Forexample,thecorrectanswerfortheexamplevaluesaboveis
giraffe.(Notethatreefisnotapossibleanswer,becausethesetofletterscontains
onlyonee.)
8.Givenastring,findthelongestsubsequencewhichcontainsonlyuniquecharacters.
7Q. Length of the longest substring without repeating characters
6Q. Suppose we want to convert one string S1 to another string S2 using only 3 types of
operations:
-Insert(pos,char) (costs 8)
-Delete(pos) (costs 6)
-Replace(pos,char) (costs 8)
Find the sequence of steps to convert S1 to S2 such that the cost to convert S1 to S2 is minimum.
Eg. 'calculate' to 'late' - the possible operations are Delete(0) Delete(1) Delete(2) Delete(3) Delete(4)
and the above sequence of operations costs 30.
5Q. There are lots of string in a file. Find the longest string that could be made from the other
strings in the file.
Eg. the
there
after
thereafter
reaf
ans: thereafter
4Q. Reverse String using XOR and without using Temporary Variable
3Q.Given a char pointer and find ith bit location. Flip that bit to 0. veveo Question Telephonic
Interview.
2Q. Write a C program to reverse a string.
1Q . Find all anagrams of a string.
Questions: linked Lists
Q . Consider the given structure:
struct node{
int data;
struct node *next; struct node *next_larger;
}
You are given a list where each node is of type defined above. Initially all the next larger pointer of
each node points to NULL. Write an algorithm to update the next larger pointer of each so that they
point to immediate next largest node in the list.
e.g.
Q. Write a C program to implement a Generic Linked List.
Q. Remove duplicates from an unsorted linked list
Q. How to compare two linked lists? Write a C program to compare two linked lists.
Q. Level order traversal and keep those in list.
17. You have given a linked list in which each node have three items, 1) data, 2) a next pointer and
3) a random pointer which is pointing to its successor in sorted order. Replicate it ? (Need to
generate a new linked list in O(n) + O(n) complexity)
17.Given a linkedlistcontaining character in each node,segregate its nodesin suchaway that all
nodes containing a vowel are moved to the start of the linked list. We will have to maintain the
order.
16. You are given two linked lists whose nodes contain a digit as data member. Both lists
representanumber.Youhavetoaddthemandreturntheresultantlist.
Input:9>9>3>4>5and8>9>1(represent99345and891)
Output:1>0>0>2>3>6
1. Given two sorted linked lists, write a function to merge them into one.
Questions: Trees
20. Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
19. Check for Children Sum Property in a Binary Tree.
18. How to find kth smallest node in a FULLY binary search tree.
17. Find no of leaves of a binary tree?
16. Convert a BT into SUM BT(each node values = sum of left and right node).
15. Given a binary tree. Write a function that takes only root node as argument and returns (sum of
values at odd height)-(sum of values at even height).
14. Print the perimeter of a binary tree?
14a. Height of a binary tree without using recursion
13. Calculate the height of a binary tree?
12. Calculate maximum width of a binary tree.
11. Calculate the mirror of a binary tree.
10. Write a algorithm to find that if two binary trees are same or not?
9. To find if there is any root to leaf path with specified sum in a binary tree.
8. How to determine if a binary tree is height-balanced?
7. A complete binary tree is given, Some of the subtree os the binary tree is BST. Find the maximum
height of the BST.
6. A program to check if a binary tree is BST or not
5. First find the max sum in tree and then search for path for max sum in the tree.
4. Given 2 trees A and B find if tree B is a subtree of Tree A or not. Provide the most optimized
solution that you can think of.
3. You have a tree with each node has link to its parent. You are given left most child node of the
tree. How will you get right most child node of the tree.
2. Lowest Common Ancestor in a Binary Search Tree.
1. How can I find the common ancestor of two nodes in a binary tree?