Professional Documents
Culture Documents
Numbers and BT
Numbers and BT
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
Page 1 of 12
FINDMIND Boot-Camp June 2014
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
20. 7 Two rectangles are given in two D space. Find if these are
overlapping or not
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.
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
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
Problem statement
Problem statement
Page 6 of 12
FINDMIND Boot-Camp June 2014
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
w | s | r | t | g | g|
a|a|c|h|i|n|
k|c|h|u|j|j|
o|h|i|n|y|q|
37. 10
In Amazon's interview, Round 2 they asked question:
Page 8 of 12
FINDMIND Boot-Camp June 2014
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?
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.
Page 10 of 12
FINDMIND Boot-Camp June 2014
}
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:
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