Skip to content

Commit 9de8147

Browse files
committed
Update README.md
1 parent 7b500ea commit 9de8147

File tree

1 file changed

+13
-84
lines changed

1 file changed

+13
-84
lines changed

README.md

Lines changed: 13 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,233 +2,167 @@
22
Practice problems from Amazon
33

44

5-
Questions:
5+
Questions:<br>
66
1.A string of alphanumeric is there. Find a string that starts with b and ends with 3
7-
87
characters.
98

109
2.There is a sorted array which is of very large size.In that all except one no. are
11-
1210
repeated once.How to find that non repeated no.
1311

1412
3.There are 2 linked lists.Those 2 lists are meeting at a point. How to find that
15-
1613
meeting point.
1714

1815
4. How do you convert a decimal number to its hexa-decimal equivalent.Give a C
19-
2016
code to do the same
2117

2218
5. Given an array all of whose elements are positive numbers, find the maximum
23-
2419
sum of a subsequence with the constraint that no 2 numbers in the sequence
25-
2620
should be adjacent in the array.
27-
2821
Eg.
29-
3022
i) 3 2 7 10 should return 13 (sum of 3 and 10)
31-
3223
ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)
3324

3425
6. Given a Binary Search Tree, write a program to print the kth smallest element
35-
3626
without using any static/global variable. You can pass the value k to any function
37-
3827
also.
3928

4029
7.You are given some denominations of coins in an array (intdenom[])and infinite
41-
4230
supply of all of them. Given an amount (int amount), find the minimum number of
43-
4431
coins required to get the exact amount. What is the method called?
4532

4633
8.Given an array of size n. It contains numbers in the range 1 to n. Each number is
47-
4834
present at least once except for 1 number. Find the missing number.
4935

5036
9.Given an array of size n. It contains numbers in the range 1 to n. Each number is
51-
5237
present at least once except for 2 numbers. Find the missing numbers.
5338

5439
10.Given an array of size n. It contains numbers in the range 1 to n. Find the
55-
5640
numbers which aren't present.
5741

5842
11.Given a string,find the first un-repeated character in it? Give some test cases
5943

6044
12.You are given a dictionary of all valid words. You have the following 3
61-
6245
operations permitted on a word:
63-
6446
a) Delete a character
65-
6647
b) Insert a character
67-
6848
c) Replace a character
69-
7049
Now given two words - word1 and word2 - find the minimum number of steps
71-
7250
required to convert word1 to word2. (one operation counts as 1 step.)
7351

7452
13.Given a cube of size n*n*n (i.e made up of n^3 smaller cubes), find the number
75-
7653
of smaller cubes on the surface. Extend this to k-dimension.
7754

7855
14.What is a C array and illustrate the how is it different from a list.
7956

8057
15.Write a function which takes as parameters one regular expression(only ? and
81-
8258
* are the special characters) and a string and returns whether the string matched
83-
8459
the regular expression.
8560

8661
16.Find the second largest element in an array with minimum no of comparisons
87-
8862
and give the minimum no of comparisons needed on an array of size N to do the
89-
9063
same.
9164

9265
17. Given an array of size n ,containing every element from 1 to n+1, except one.
93-
9466
Find the missing element.
9567

9668
18. Two trains enter at the opposite sides of a tunnel of length L with speeds 'V'.
97-
9869
A particle enters the tunnel at the same time with a speed 'v' and it vibrates in
99-
10070
the tunnel[i.e. if it reaches the end of the tunnel then it comes back]. What is the
101-
10271
position of the particle by the time the 2 trains meet?
10372

10473
19.Given an array of size n+1 which contains all the numbers from 1 to n.Find the
105-
10674
number which is repeated in O(n) time .How do you proceed with the same with
107-
10875
floating numbers from 0 to 1 instead of 1 to n?
10976

11077
20. Design a data structure to represent the movement of a knight on a chess
111-
11278
board
11379

11480
21. Write an algorithm to traverse a knight covering all the squares on a
115-
11681
chessboard starting at a particular point.
11782

11883
22. What is wrong with this class, assuming that this is its complete interface?
11984

12085
class C {
12186

122-
char *p;
87+
char *p;
12388

124-
public:
89+
public:
12590

126-
C() { p = new char[64]; strcpy(p, "Hello world"); }
91+
C() {
92+
p = new char[64];
93+
strcpy(p, "Hello world");
94+
}
12795

128-
~C() { delete p; }
96+
~C() {
97+
delete p;
98+
}
12999

130-
void foo() { cout<< "My ptr is: '" << p << "'" <<endl; }
100+
void foo() {
101+
cout<< "My ptr is: '" << p << "'" <<endl;
102+
}
131103

132104
};
133105

134106
Since this has an overtly programmed destructor, the member wise semantics for
135-
136107
destruction are not good enough; therefore, they are not good enough for copy
137-
138108
and assignment either. But, the copy ctor and op= are not programmed, so we
139-
140109
will have some serious trouble.
141-
142110
Gradual hinting: what happens when we make a copy? [correct answer: pointer is
143-
144111
copied]. Now, the original goes out of scope, what happens to the copy? [pointer
145-
146112
dangles]. How would you fix it?
147-
148113
[also, that delete p should be delete[ p since p was allocated with the array new]
149-
150114
Assuming that swap() and copy construction are part of your interface for class C,
151-
152115
what's the cookie-cutter pattern for operator= that uses them?
153-
154116
answer:
155117

156118
C& C:perator=(const C &rhs) {
157-
158119
if (this != &rhs) {
159-
160120
C tmp(rhs);
161-
162121
this->swap(tmp);
163-
164122
}
165-
166123
return *this;
167-
168124
}
169-
170125
]]
171126

172127
23. “given two lists write a function which returns a list which is the intersection
173-
174128
of the two lists.the original lists should remain same.
175-
176129
(Intersection – if first list is say,1,20 3,45 and second list is 3,24 ,45,90,68 then
177-
178130
intersection should be 3,45 )
179131

180132
24. Given two nodes of a binary tree find the closest ancestor of the two nodes.
181-
182133
Note:consider binary tree and binary search tree also.
183134

184135
25. Given an array all of whose elements are positive numbers, find the maximum
185-
186136
sum of a subsequence with the constraint that no 2 numbers in the sequence
187-
188137
should be adjacent in the array.
189-
190138
i) 3 2 7 10 should return 13 (sum of 3 and 10)
191-
192139
ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)
193140

194141
26. Given a Binary Search Tree, write a program to print the kth smallest element
195-
196142
without using any static/global variable. You can’t pass the value k to any function
197-
198143
also.
199144

200145
27.Given an array of size n. It contains numbers in the range 1 to n. Each number
201-
202146
is present at least once except for 2 numbers. Find the missing numbers.
203147

204148
28.Given an array of size n. It contains numbers in the range 1 to n. Find the
205-
206149
numbers which aren't present.
207150

208151
29. How would you find the second largest element in an array using minimum no
209-
210152
of comparisons?
211153

212154
30. Write a C program for level order traversal of a tree?
213155

214156
31. You are given: 3 types of vehicles: Motorbike, Car, and a special type of car for
215-
216157
the handicapped.
217-
218158
3 Types of parking: Motorbike parking, Car parking, handicapped car parking.
219-
220159
Motorbikes and cars can only park in their designated parkings, while the
221-
222160
handicapped cars can park either in their own parking or the regular car parking.
223-
224161
How would you model this as classes? Explain your methods.
225162

226163
32.Two tables emp(empid,name,deptid,sal) and dept(deptid,deptname) are
227-
228164
there.write a query which displays empname,correspondingdeptname also
229-
230165
display those employee names who donot belong to any dept.
231-
232166
Display the employees whose salary is less than average salary.
233167

234168
33. what is the output of the program
@@ -316,17 +250,12 @@ return ((p==null)||(p->next==null)|| (p->info<=p->next->info)&&( fun(p->next)));
316250
}
317251

318252
a)when list is empty or has one node
319-
320253
b)when the ele are sorted in non decreasing order
321-
322254
c)when the ele are sorted in non increasing order
323255

324256
39.what is x here (x&&!(x&(x-1))==1)
325-
326257
a)x is always a prime
327-
328258
b)x is a power of 2
329-
330259
c)x is even d)x is odd
331260

332261
40.what is valid in cpp char *cp; const char *cpp; 1) cpp=cp; 2) cp=cpp;

0 commit comments

Comments
 (0)