Vous êtes sur la page 1sur 5

General Set 2

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.

18Q. Sort elements by frequency


17Q. Find the smallest and second smallest element in an array
16Q. Two elements whose sum is closest to zero.
15Q. An array contains two sub- sorted arrays. Give an inplace algorithm to sort two sub arrays.
for ex: I/P: 1 4 5 7 8 9 2 3 6 10 11 O/P: 1 2 3 4 5 6 7 8 9 10 11
14Q. Given a sorted array of size N and a sorted array of size M+N, merge the first array into the
second preserving order. There is enough space in the second array to hold all elements from the
first one.
13Q.Write a program to find the element in an array that is repeated more than half number of
times. Return -1 if no such element is found.
12Q. From given array of n elements find the maximum element for each consecutive sub-array of k
elements.
eg.array=[6,5,4,3,2,1] k=3
ans=6 5 4 3
explanation:- 6 from array [6,5,4] 5 from array[5,4,3]
11Q. Given a set of consecutive integersA[1....n] and an integer value x,y, need to find the list of
subset of integers in A[1....n] which has x integers and sums up to y.
Say A = [10,11,12,13,14,15,16,17,18,19,20], X = 4 and Y = 55,
it should give the values of (10,14,15,16),(10,11,15,19),(10,11,16,18),(10,12,16,17) and so on..
Write an algorithm to find all the subsets.
10Q.Sort an array of 0s, 1s and 2s
9Q. Array sort in Ascending and descending order in odd and even positions
8Q. Find a pivoted array from a sorted array. Given a sorted but rotated array and find the pivot.
Now have to search an element without pivot point by logn complexity
7Q. Program for pattern matching, pattern matching in c
6Q. How to find number of successive inversion in an array?
5Q. Dynamically Allocating Multidimensional Arrays
4Q. WAP to add two big numbers using array to store the numbers.
3Q. WAP to add two big numbers using array to store the numbers.
2Q. Given an array "a1b2c3d4" convert to "abcd1234"
1Q. Given an array to find maximum occurrence( more than ) number in linear time.
Questions: Strings
11.WriteanefficientCprogramtoprintalltheduplicatesandtheircountsintheinput
string
10.Thereisabigfileofwordswhichisdynamicallychanging.Wearecontinuously
addingsomewordsintoit.Howwouldyoukeeptrackoftop10trendingwordsateach
moment?
9.Youaregivenadictionary,intheformofafilethatcontainsonewordperline.E.g.,
abacus
deltoid
gaff
giraffe
microphone
reef

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

15. Reverse every consecutive k nodes of the given linked list


14. Clone a singly link list whose nodes contain, apart from next pointers, an extra pointer to any
random node. The random pointer of a node N could be after N, before N or the node N itself.
13. Remove intersections of two single linked list and make one linked list.....
12. Given a linked list of numbers. Swap every 2 adjacent links
11. Program to find the merging point of two linked lists
10. How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a C
program to do the same.
9.Given only a pointer to a node to be deleted in a singly linked list, how do you delete
8.How do you sort a linked list? Write a C program to sort a linked list.
7. How do you find the middle of a linked list? Write a C program to return the middle of a linked
list.
6. A singly link list and a number K, swap the Kth node from the start with the Kth node from the
last. Check all the edge cases.
5. Function to check if a singly linked list is palindrome
4. Find a link list have loop or not? A function removeLoop() if loop exists, removes the loop and
give the length of the linked list.
3.Linked list is given as below (with elements as 1, 2 and 3), sort this in one pass.
3->2->2->1->2->3->1
2. Construct Complete Binary Tree from its Linked List Representation

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?

Vous aimerez peut-être aussi