You are on page 1of 12

FINDMIND Boot-Camp June 2014

Boot Camp Code List


Seria Points Problem Statement
l#
1. 4 Write a function to find the next smallest palindrome number
of the given number. for example: if given number is 12345,
then the next smallest palindrome is 12421.
2. 6 Write a ‘C’ program to print the following pattern

4444444
4333334
4322234
4321234
4322234
4333334
4444444
FILL THE PATTERN
3. 6 :MsExcel columns has a pattern like
ABC…Z
AA AB AC…. AZ BA BB … ZZ
AAA AAB
A has code 1
Z has code 26
AA has code 27
AAA has code 626
given a number return a column name as string

4. 5 Write a function

isFactorialDivisible( int x, int y)


Return true if x! is divisible by y else return false
5. MS There are 25 horses and five tracks, how many matches are

Page 1 of 12
FINDMIND Boot-Camp June 2014

6 needed to find top five horse.(Only five horse is appear in one


match).
6. 8
Given only putchar (no sprintf, itoa, etc.) write a routine
putlong that prints out an unsigned long int.
7. Amazo
n Given a float number 7.64, convert it into the string WITHOUT
using any inbuilt function/library.
7 for eg:
input
float no.: 7.64
output
string: 7.64
8. 8
Given a Binary Search Tree, in-place convert it to DLL.
9. 8
Find the Kth largest integer in a Binary Search Tree. When I
told her the solution like the one given on geeks for geeks,
she asked me to do it using recursion.
10. 10 We have a huge file with braces ‘()’ [just one type..] Find if
they are balanced .. (stacks wouldn’t work here because you
will probably run out of memory storing the stack ..) When I
gave him another solution, he asked me to do it using parallel
processes. I told him to elaborate more.. (to be honest I
wasn’t familiar with parallel processes) .. Finally I told him
so ..and he asked me to think about it still ..

We discussed it for about 20 minutes. Not reaching anywhere


he moved on to ask me the next question.

11. 6
Given the numerator and denominator of a fraction, find the
quotient and the remainder without using divide and mod (‘/’,
’%’ )operators
12. 8
Find kth smallest element in a binary search tree
13. 9
Given an binary tree. Traverse it in zig-zag manner.
Page 2 of 12
FINDMIND Boot-Camp June 2014

14. 7
Find the diameter of the tree.
15. 8
Given a binary tree, replace each node value by sum of its
children value.
16. 7 Find the square root of any number (square root can be a real
number) without using any library function .
I told him an approach using Newton-Raphson method. It was
faster but he asked simple and optimal method so then i
suggested binary search method ( O(log n)) and I was asked
to code it and dictate and he ran the code on his system also.

17. 7
Delete all leaf nodes in a tree.
18. 8 Given a binary search tree of n nodes, find all the pair of
nodes whose sum is equal to a given number k in O(n) time
and constant space.(algo+code)
19. 7 Given a number N, find the smallest 3 digits number such
that product of its digits is equal to N. ( algo+ optimal code)

if(n >729)
return -1; // number does not exist
else
find all the factors of the number n
if the greatest factor is greater than 9 return -1; // number
does not exist
else
generate lowest 3 digit number using a logic

Smart question i would say by the interviewer.

20. 7 Two rectangles are given in two D space. Find if these are
overlapping or not

If the distance between center's of both rectangles is less


than (half the diagnol of rect1+ half the diag of rect2) then
overlapping.
21. 8 Program to convert sorted array to Binary Search Tree

Page 3 of 12
FINDMIND Boot-Camp June 2014

22. 6
Output nearest number greater than given number such that
output is palindrome
ex: 121:131
900:909
99:101
23. 7 Given a number design the algorithm to find the next greater
number which contains exactly same digits. e.g. n= 123 next
greater with same digits = 132
The number can be very large so its better to consider it as a
sequence of characters.

I was also asked to write the code for the same.

24. 8
Given a BST, replace each node with the sum of the values of
all the nodes that are greater than that node. Only constraint
being that I was not allowed to use any global or static
variable.
Although I panicked a bit and made few mistakes, I got
through.
25. 8 Given a binary tree, where every node value is a Digit from 1-9
.Find the sum of all the numbers which are formed from root
to leaf paths . (Algo + Code )

6
/ \
3 5
/ \ \
2 5 4
/ \
7 4
There are 4 leafs, hence 4 root to leaf paths:
Path Number
6->3->2 632
6->3->5->7 6357
6->3->5->4 6354

Page 4 of 12
FINDMIND Boot-Camp June 2014

6->5>4 654
Answer = 632 + 6375 + 6354 + 654 = 13997

26. 8
Deepest left leaf of a binary tree
27. 8
Deepest Right leaf of a binary tree
28. 8
Deepest leaf of a binary tree
29. 7
A number is given say n, find the minimum number which is
greater than n and has same no. of set bits in it.
30. 6 Given a 2D matrix, print all elements of the given matrix in
diagonal order. For example, consider the following 5 X 4
input matrix.

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20

Diagonal printing of the above matrix is

1
5 2
9 6 3
13 10 7 4
17 14 11 8
18 15 12
19 16
20

31. 8 Path in a tree is list of nodes from root to leaf. There can be
many paths in a tree, maximum length of a path can be N
nodes in worst case, in average case it would be logN.
Consider following tree:

Page 5 of 12
FINDMIND Boot-Camp June 2014

Paths is above tree are :


10,6,4
10,6,7
10,15,13
10,15,17

Problem statement

Traverse all paths of a given binary search tree

32. 9 Here problem is slightly twisted. While printing levels we


need to make sure that one level is printed left to right and
other from right to left and then third one again from left to
right. In easier terms we need to print tree in Zig-Zag manner
or spirally.

Problem statement

Given a binary search tree, print all nodes of the tree in


zigzag manner.
For example, for following tree, output should be : 30,40,20,15,25,37,45

Page 6 of 12
FINDMIND Boot-Camp June 2014

Binary Search Tree


33. 9 Given a binary search tree and two integers min and max,
prune all nodes of binary search tree which are not in range
min and max.
That is to say remove all nodes from BST which are either
less than min or greater than max.
For example, if for following input tree min = 22 and max = 40
are given
Output will be like output tree.

Input tree

34. 9 Given a number, find out the next smallest number which can
be formed using same digits
Take some examples:
Number = 12543
What is the next smallest number? Its 13245.
Number = 123
What is the next smallest number? It's 132.
Number = 1234554321
Next smallest number will be 1235123445.

Page 7 of 12
FINDMIND Boot-Camp June 2014

35. 10 For a given binary search tree, replace each node with sum of
all node which are greater then of equal to current node.
36. 10
given a N x N matrix find the no. of times a word is present in
that matrix. constraints you can move in 3 directions from
one cell 1. forward , 2. down 3. diagonal . Find all teh
occurrence of all the word

forward means right (x+1,y)


down mean (x,y+1)
diagonal means (x+1,y+1)

it can be done with BFS. {search the no. of occurance of a


given word example "sachin" in the whole NxN matrix}

w | s | r | t | g | g|
a|a|c|h|i|n|
k|c|h|u|j|j|
o|h|i|n|y|q|

in this sachin can be found out 4 times.

37. 10
In Amazon's interview, Round 2 they asked question:

Write a program to print inorder traversal of two trees.

Both values must be printed alternatively.

e.g. if inorder traversal of tree 1 is 10, 15, 20 and tree 2 is


100, 150, 200 then it should print
10, 100, 15, 150, 20, 200.

I tried printing it recursively by calling 2 functions recursively


(f1 calls f2, then f2 calls f1 and so on).

Page 8 of 12
FINDMIND Boot-Camp June 2014

I don't know where my approach is going wrong? I know there


are other ways to do it as well but in this approach what is
the mistake?

38. 10
Write code to find the next least node in a binary search tree
given a node?

39. 8
Explain the output of the following code:

int main( )
{
int x = 10, y = 20;/.
x =!x;
y =!x&&!y;
printf(“x =%d y =%d”, x, y);
return 0;
}

40. 8
Given a number N, find the smallest 3 digits number such that
product of its digits is equal to N.For example for N=100 , 3
digits number is 455.

41. 10
Given a number N, now find the number of occurrences of
each digit 0..9 from 0 to N
Eg:
i/p: 12
o/p:
2
5
2
1
1
Page 9 of 12
FINDMIND Boot-Camp June 2014

1
1
1
1
1

42. 8
How do you write a program which produces its own source
code as output?

43. 9 Print the numbers between 30 to 3000.


CONSTRAINT:
The numbers shouldn’t contain digits either in increasing
order or decreasing order.

FOLLOWING NOT ALLOWED


##123,234,345,1234,2345##increasing order,
##32,21,321,432,3210 etc##decresing order.

FOLLOWING ALLOWED:
243,27,578,2344 etc.,
44. 7
Write a program to find whether a given number is a perfect
square or not. You can only use addition and subtraction
operation to find a solution with min. complexity.

45. 7 Is this code working fine ? if yes/no give reason ?


#include<iostream>
using namespace std;
struct node
{
int a;
int b;
};
typedef struct node Node;

Page 10 of 12
FINDMIND Boot-Camp June 2014

void swap(void *a,void *b)


{
void *temp;
temp=a;
a=b;
b=temp;
}
int main()
{
Node *a1,*b1;
a1=(Node*)malloc(sizeof(Node));
b1=(Node*)malloc(sizeof(Node));
a1->a=10;
a1->b=20;
b1->a=30;
b1->b=40;
cout<<a1->a<<" "<<a1->b<<endl;
cout<<b1->a<<" "<<b1->b<<endl;
swap(a1,b1);
cout<<a1->a<<" "<<a1->b<<endl;
cout<<b1->a<<" "<<b1->b;

}
I surprised to see the ans after compiling this code ... i think u
enjoy this code... :)
46. 10 Write a program in C to read all the characters from standard
input and output the reverse when the user presses enter
key.
47. 8 Write a program to swap odd and even bits of a 32-bit
unsigned integer with as few instructions as possible. (bit-0
and bit-1 are swapped, bit-2 and bit-3 are swapped and so on)
48. 7
Give a N*N matrix, print it out diagonally.
Follow up, if it is a M*N matrix, how to print it out.
Example:
123
456
789

Page 11 of 12
FINDMIND Boot-Camp June 2014

print:
1
24
357
68
9

49. 9
Implement a sudoku solution verifier function. The rules for
sudoku is this:

You have a 9 by 9 board. This board is divided into nine rows,


nine columns, and nine 3x3 blocks. In a solved puzzle, every
row, every column, and every 0 block has to contain each of
the digits from 1 to 9. This is an example of a solved puzzle:

248|395|716
571|628|349
936|741|582
---+---+---
682|539|174
359|174|628
714|862|953
---+---+---
863|417|295
195|286|437
427|953|861

50. 8
Generate MAX_INT (Max signed int value) using bitwise
operators. Should work in 32 and 64 bit processors

51. 8
Find numbers which are palindromic in both their decimal and
octal representations

Page 12 of 12

You might also like