100% found this document useful (1 vote)
721 views

Amazon

The document contains a table of contents listing 49 sets of content. Each set is numbered and includes the page number and a reference to a source page. The table of contents suggests this is a compilation of various sets of content organized by subject or topic, though the specific nature or topics of each set is not provided.

Uploaded by

rohit kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
721 views

Amazon

The document contains a table of contents listing 49 sets of content. Each set is numbered and includes the page number and a reference to a source page. The table of contents suggests this is a compilation of various sets of content organized by subject or topic, though the specific nature or topics of each set is not provided.

Uploaded by

rohit kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1090

Contents

1 Set 1 29
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

2 Set 2 32
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3 Set 3 34
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

4 Set 4 36
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

5 Set 5 38
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6 Set 6 40
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

7 Set 7 42
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

8 Set 8 44
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

9 Set 9 (Answers) 48
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

10 Set 9 50
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

11 Set 10 55
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

12 Set 11 58
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

13 Set 12 60
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

1
Contents

14 Set 13 62
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

15 Set 14 64
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

16 Set 15 66
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

17 Set 16 68
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

18 Set 17 70
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

19 Set 18 72
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

20 Set 19 74
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

21 Set 20 76
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

22 Set 21 79
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

23 Set 22 83
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

24 Set 23 86
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

25 Set 24 89
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

26 Set 25 92
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

27 Set 26 95
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

28 Set 27 97
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

29 Set 28 100
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

30 Set 29 103
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

2
Contents

31 Set 30 106
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

32 Set 31 109
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

33 Set 32 111
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

34 Set 33 115
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

35 Set 34 118
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

36 Set 35 121
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

37 Set 36 123
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

38 Set 37 125
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

39 Set 38 (SDE-I) 128


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

40 Set 39 (SDE) 132


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

41 Set 40 (On-Campus Round 1) 135


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

42 Set 41 (On–campus) 137


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

43 Set 42 (On-Campus) 139


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

44 Set 43 (On-Campus) 141


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

45 Set 44 (For Internship) 143


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

46 Set 45 (For Internship) 144


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

47 Set 46 (On-campus for Internship) 146


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

3
Contents

48 Set 47 (Off-campus for SDE-1) 147


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

49 Set 48 (On-campus for SDE-1) 149


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

50 Set 49 (On-campus for SDE-1) 152


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

51 Set 50 (On-campus for SDE) 154


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

52 Set 51 (On-campus for SDET) 156


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

53 Set 52 (For Internship) 159


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

54 Set 53 (For SDE-1) 161


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

55 Set 54 (For Internship) 165


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

56 Set 54 (Off-Campus For SDE-1) 168


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

57 Set 54 (On Campus for SDE) 171


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

58 Set 55 (On-Campus) 173


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

59 Set 56 (Off-Campus) 175


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

60 Set 57 (Off-Campus for SDE-1) 177


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

61 Set 58 (On-campus for Software Development Engineer) 179


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

62 Set 59 (Off-campus for SDE-1) 181


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

63 Set 60 (For Internship) 183


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

64 Set 61 (For Internship) 185


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

4
Contents

65 Set 62 (For SDE-1) 187


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

66 Set 63 (For SDE-1) 189


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

67 Set 64 (Off-Campus for SDE) 190


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

68 Set 65 (Off-Campus for SDE-2) 192


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

69 Set 66 (For SDE) 194


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

70 Set 67 (For SDE-1) 196


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

71 Set 68 (For SDE-1) 198


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

72 Set 69 (For SDE-1) 200


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

73 Set 70 (On-Campus For Internship) 203


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

74 Set 71 (For SDE-2) 205


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

75 Set 72 (Off campus for SDE-1) 207


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

76 Set 73 (For SDE-1) 209


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

77 Set 74 211
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

78 Set 75 (For SDE-1) 213


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

79 Set 76 (For SDE-1) 215


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

80 Set 77 (Off-Campus For SDE-1 / 1.5yrs experienced) 217


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

81 Set 78 219
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

5
Contents

82 Set 79 (For SDE-1) 222


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

83 Set 80 224
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

84 Set 81 (For SDE-I) 226


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

85 Set 82 (For SDE-2) 228


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

86 Set 83 230
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

87 Set 84 232
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

88 Set 85 234
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236

89 Set 86 237
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

90 Set 87 (For SDE) 240


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

91 Set 88 244
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

92 Set 89 246
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248

93 Set 90 249
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250

94 Set 91 251
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252

95 Set 93 253
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

96 Set 95 (For SDE-I) 255


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

97 Set 96 (On-Campus for Internship) 257


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258

98 Set 97 (On-Campus for SDE1) 259


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

6
Contents

99 Set 98 (On-Campus) 261


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

100 Set 99 (On-Campus) 264


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265

101 Set 100 (On-Campus) 266


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

102 Set 101 (On-Campus) 269


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

103 Set 102 272


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

104 Set 103 (On-Campus) 275


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277

105 Set 104 278


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

106 Set 105 (On-Campus) 280


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

107 Set 106 (On Campus for Internship) 283


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

108 Set 107 (For SDE-1) 285


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

109 Set 108 (On-Campus) 287


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

110 Set 109 (On-Campus) 290


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

111 Set 110 (On-Campus) 293


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

112 Set 111 (On-Campus) 296


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298

113 Set 112 (On-Campus) 299


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

114 Set 113 (On-Campus for Internship) 301


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

115 Set 114 (On-Campus for Internship) 304


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306

7
Contents

116 Set 115 (On-Campus) 307


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

117 Set 116 (On-Campus) 309


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

118 Set 117 (On-Campus for Internship) 311


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312

119 Set 118 (On-Campus for Internship) 313


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

120 Set 119 (On-Campus for Internship) 315


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317

121 Set 120 (On-Campus for Internship) 318


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

122 Set 121 (On-Campus for SDE-1) 320


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320

123 Set 122 (On-Campus for Internship) 321


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

124 Set 123 (On-Campus for Internship) 324


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

125 Set 124 (On-Campus) 326


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328

126 Set 125 (On-Campus for Internship) 329


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331

127 Set 126 (For SDE-1) 332


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333

128 Set 127 (For Internship) 334


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335

129 Set 128 (For SDET) 336


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338

130 Set 129 (For SDE 1 Off-Campus) 339


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

131 Set 130 (For SDET 1) 342


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

132 Set 131 (For SDET 1) 344


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

8
Contents

133 Set 132 (For SDE Intern) 346


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348

134 Set 133 349


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349

135 Set 134 (Off-Campus for SDE) 350


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

136 Set 135 (On-Campus for SDE) 352


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354

137 Set 136 (For SDE-T) 355


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356

138 Set 137 (Assessment test for SDE) 357


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358

139 Set 138 (For SDE 1) 359


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360

140 Set 139 361


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362

141 Set 140 (Experienced for SDE) 363


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365

142 Set 141 (For SDE1) 366


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367

143 Set 142 (Off-Campus for SDE-1) 368


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369

144 Set 143 (Off-Campus for SDE-1) 370


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371

145 Set 144 (Off-Campus For SDE-1) 372


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373

146 Set 145 (Off-Campus) 374


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375

147 Set 146 376


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378

148 Set 147 379


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

149 Set 148 382


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383

9
Contents

150 Set 149 (On-Campus for Internship) 384


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387

151 Set 150 (SDE1 for 1 Year Experienced) 388


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389

152 Set 151 (For SDE) 390


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392

153 Set 152 (Kindle Team SDE-1 ) 393


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395

154 Set 152 396


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

155 Set 153 (For SDE1) 398


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399

156 Set 154 (For SDE2) 400


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401

157 Set 155 (On-Campus) 402


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403

158 Set 156 (On-Campus) 404


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405

159 Set 157 (On-Campus) 406


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407

160 Set 158 (Off-Campus) 408


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410

161 Set 159 (Off-Campus) 411


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413

162 Set 160 (For SDE 2) 414


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415

163 Set 161 (Off Campus for SDE-1, Bangalore) 416


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

164 Set 162 418


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419

165 Set 163 (For SDE II) 420


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421

166 Set 164 (For SDE I) 422


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424

10
Contents

167 Set 165 (For SDE I) 425


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426

168 Set 166 (For SDE I) 427


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428

169 Set 167 (SDE I for 1 year 6 months experience) 429


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431

170 Set 168 432


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433

171 Set 169 (For SDE 2) 434


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435

172 Set 170 436


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437

173 Set 171 438


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440

174 Set 173 (On-Campus) 441


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442

175 Set 174 (For SDE) 443


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445

176 Set 175 (For SDE) 446


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

177 Set 176 (For SDE 1) 448


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449

178 Set 177 (First Round in Pool Campus) 450


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451

179 Set 178 (For SDE-1) 452


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454

180 Set 179 (For SDE-1) 455


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456

181 Set 180 (Telephonic Interview ) 457


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

182 Set 181 (For SDE 1) 458


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

183 Set 182 (For SDET 1) 460


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461

11
Contents

184 Set 183 (SDE – New Grad Position) 462


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464

185 Set 184 (Off Campus for SDE1) 465


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466

186 Set 185 (For SDE1) 467


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468

187 Set 186 (For SDE1) 469


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470

188 Set 187 (For SDE1) 471


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474

189 Set 188 (For SDE1) 475


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476

190 Set 189 (For SDE-1) 477


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480

191 Set 190 (Delhi Drive) 481


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482

192 Set 191 483


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484

193 Set 192 485


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486

194 Set 193 (For SDE-1) 487


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488

195 Set 194 (For Software Support Engineer) 489


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490

196 Set 195 (On-Campus For SDE-1) 491


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492

197 Set 196 (On-Campus) 493


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493

198 Set 197 (On-Campus for Internship) 494


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497

199 Set 198 (For SDE1) 498


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

200 Set 198 (On-Campus for Internship) 502


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503

12
Contents

201 Set 199 (On-Campus for Internship) 504


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507

202 Set 200 508


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510

203 Set 201 (On-Campus for SDE-1) 511


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513

204 Set 202 514


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515

205 Set 203 (On-Campus for SDE-1) 516


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517

206 Set 204 (On-Campus for Internship) 518


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520

207 Set 205 (On-Campus for Internship) 521


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522

208 Set 206 (On-Campus for SDE-1) 523


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525

209 Set 207 (On-Campus for Internship) 526


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527

210 Set 208 (On-Campus for Internship) 528


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529

211 Set 209 (On-Campus) 530


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531

212 Set 210 (On-Campus) 532


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534

213 Set 211 (On-Campus for Internship) 535


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536

214 Set 212 (On-Campus) 537


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539

215 Set 213 (Off-Campus for SDE1) 540


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542

216 Set 214 (On-Campus) 543


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544

217 Set 215 (On-Campus for Internship) 545


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546

13
Contents

218 Set 216 (On-Campus for Internship) 547


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547

219 Set 217 (On-Campus) 548


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550

220 Set 218 (On-Campus) 551


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552

221 Set 219 (On-Campus) 553


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555

222 Set 220 (On-Campus) 556


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558

223 Set 221 559


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560

224 Set 222 561


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564

225 Set 223 (On-Campus) 565


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566

226 Set 224 567


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568

227 Set 225 (For 1 Year Experienced) 569


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571

228 Set 226 (On-Campus for SDE-1) 572


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572

229 Set 227 (On-Campus for Internship and Full-Time) 573


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576

230 Set 228 (On-Campus for Internship) 577


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579

231 Set 229 (On-Campus for SDE) 580


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581

232 Set 230 (On-Campus For SDE) 582


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583

233 Set 231 (On-Campus) 584


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586

234 Set 232 (SDE-1 for 1 Year Experienced) 587


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590

14
Contents

235 Set 233 (1 Year Experienced for SDE-1) 591


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592

236 Set 234 (For SDE-II) 593


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594

237 Set 234 595


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596

238 Set 235 (For SDE-II) 597


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599

239 Set 236 (Rounds 2 and 3) 600


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601

240 Set 237 (For Application Engineer) 602


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602

241 Set 238 (For SDE) 603


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603

242 Set 239 604


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605

243 Set 240 (1.5 Year Experienced for SDE-1) 606


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608

244 Set 241 (1.5 years experience) 609


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610

245 Set 242 (1 Year Experience) 611


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614

246 Set 243 (2.5 Years Experience) 615


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617

247 Set 244 (For SDE-1) 618


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619

248 Set 245 (For 2.5 Years Experienced) 620


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621

249 Set 246 (For SDE 2) 622


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623

250 Set 247 (For SDE 1) 624


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625

251 Set 248 (4.8 Yrs Experience for SDE II) 626
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627

15
Contents

252 Set 249 (Telephonic Interview) 628


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628

253 Set 250 629


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

254 Set 252 (For SDET) 632


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633

255 Set 253 (For SDE1I) 634


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634

256 Set 254 (Off-Campus for SDE1) 635


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636

257 Set 255 (On-Campus) 637


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639

258 Set 256 (Written Test for SDE1) 640


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

259 Set 257 (Off-Campus) 641


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642

260 Set 258 (For SDE1) 643


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644

261 Set 258 (Off-Campus for SDE-1) 645


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647

262 Set 259 (1 Yr Experienced for SDE1) 648


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650

263 Set 260 (For SDE2) 651


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652

264 Set 261 (For SDE1) 653


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655

265 Set 262 (For SDE1) 656


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657

266 Set 262 658


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658

267 Set 263 (For SDET) 659


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659

268 Set 264 (Experienced for SDE1) 660


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661

16
Contents

269 Set 265 (For Internship) 662


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664

270 Set 265 (On-Campus Internship) 665


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667

271 Set 266 (Off-Campus for SDE1) 668


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

272 Set 266 (SDE 2) 670


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671

273 Set 267 (8 Months Experienced) 672


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674

274 Set 268 (Experienced) 675


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676

275 Set 269 (1 year experienced for SDE-1) 677


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678

276 Set 272 (On-Campus) 679


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681

277 Set 273 (On-Campus) 682


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684

278 Set 274 ( On-Campus) 685


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687

279 Set 275 ( Off-Campus SDE-I Experienced) 688


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690

280 Set 276 ( On-Campus SDE-I) 691


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692

281 Set 277 (On-Campus for Internship) 693


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693

282 Set 278 (On-Campus) 694


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

283 Set 279 (On-Campus for Internship) 696


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697

284 Set 280 (Off-Campus) 698


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700

285 Set 282 (On-Campus) 701


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702

17
Contents

286 Set 283 (On-Campus) 703


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704

287 Set 285 (On-Campus for JD-SDE) 705


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706

288 Set 286 (On-Campus) 707


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710

289 Set 287 (On-Campus) 711


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713

290 Set 288 (On-Campus) 714


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715

291 Set 289 (On-Campus for Internship) 716


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717

292 Set 290 (On-Campus for Internship) 718


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719

293 Set 291 (On-Campus for SDE1) 720


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722

294 Set 292 (On-Campus for Internship) 723


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724

295 Set 293 (On-Campus) 725


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726

296 Set 294 (Experienced) 727


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728

297 Set 295 (On Campus) 729


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733

298 Set 296 (On Campus for Internship) 734


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735

299 Set 297 (On-Campus for SDE) 736


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736

300 Set 298 (On-Campus for SDE-1) 737


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738

301 Set 299 (On-Campus for Internship) 739


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740

302 Set 299 741


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742

18
Contents

303 Set 300 (On-Campus for Internship) 743


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744

304 Set 301(On-Campus for Internship+ FTE) 745


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747

305 Set 302 (On-Campus) 748


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750

306 Set 303 (On-Campus) 751


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752

307 Set 304 (On-Campus for Internship) 753


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756

308 Set 305 (On-Campus for Internship) 757


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759

309 Set 306 (On-Campus) 760


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762

310 Set 307 (Off-Campus) 763


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764

311 Set 308 (For SDE) 765


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765

312 Set 308 (On-Campus for Internship) 766


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767

313 Set 309 768


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769

314 Set 310 (For Internship) 770


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770

315 Set 311 ( On Campus for Internship and FTE) 771


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772

316 Set 312 (For SDE II) 773


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773

317 Set 312 (Off Campus) 774


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775

318 Set 313 (For SDE II) 776


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777

319 Set 314 (For FTE) 778


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779

19
Contents

320 Set 315 780


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781

321 Set 316 (Off-Campus) 782


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784

322 Set 316 (On-Campus) 785


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786

323 Set 317 (SDE-1 Off – Campus) 787


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789

324 Set 318 (For SDE Intern) 790


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791

325 Set 319 (On-Campus) 792


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793

326 Set 320 (Off-Campus) 794


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795

327 Set 321 (Online Assessment) 796


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797

328 Set 322 (Off-Campus) 798


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800

329 Set 323 (Software Development Engineer – Off-Campus) 801


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803

330 Set 324 (For SDE2) 804


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806

331 Set 325 807


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807

332 Set 326 (For Application Engineer) 808


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810

333 Set 326 (For SDE II) 811


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812

334 Set 327 (Off-Campus for SDE-1) 813


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814

335 Set 328 (For SDE-1) 815


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816

336 Set 329 (Off-Campus for SDE-1) 817


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819

20
Contents

337 Set 330 820


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821

338 Set 331 (1 Year Experienced for SE-1) 822


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826

339 Set 332 (Off-Campus) 827


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828

340 Set 333 (For Internship) 829


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832

341 Set 334 (For 4.5 Years Experienced) 833


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833

342 Set 335 834


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 834

343 Set 336 835


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836

344 Set 337 (For SDE-1) 837


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 838

345 Set 338 (1st Round for SDE-1 in Delhi) 839


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 839

346 Set 339 (For SDE 2) 840


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841

347 Set 340 (3.5 years experienced for SDE 1) 842


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843

348 Set 341 (Off-Campus for SDE-1) 844


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845

349 Set 342 (Off-Campus for SDE-1) 846


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846

350 Set 343 (For SDE-1) 847


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847

351 Set 344 (For SDE-1) 848


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849

352 Set 345 (For SDE-1) 850


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851

353 Set 346 (For SDE-1) 852


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854

21
Contents

354 Set 347 (1.8 Years Experienced for SDE1) 855


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856

355 Set 348 (For SDE II) 857


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859

356 Set 349 (For SDE I) 860


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 862

357 Set 350 (For SDE I) 863


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865

358 Set 351 (Off Campus – For SDE I) 866


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 868

359 Set 351 (Off-Campus for SDE I) 869


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869

360 Set 352 (For SDE I) 870


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871

361 Set 353 (For SDE-2) 872


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872

362 Set 354 (For SDE-2) 873


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873

363 Set 355 (For 1 Year Experienced) 874


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875

364 Set 356 (For 6 Year Experienced) 876


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876

365 Set 357 (For 2.5 Years Experienced) 877


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878

366 Set 358 (Off-Campus) 879


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879

367 Set 359 (On-Campus) 880


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883

368 Set 360 (On-Campus) 884


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885

369 Set 361 886


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886

370 Set 362 887


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888

22
Contents

371 Set 363 (On-Campus for Internship) 889


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 890

372 Set 364 (On-Campus) 891


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892

373 Set 367 (On-Campus for Internship) 893


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 894

374 Set 368 (Phone and Onsite) 895


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895

375 Set 369 (On-Campus) 896


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897

376 Set 370 (On Campus for Internship) 898


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899

377 Set 371 (For SDE-2) 900


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901

378 Set 372 (For SDE II) 902


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903

379 Set 373 (For SDE 2) 904


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905

380 Set 374 (On-Campus) 906


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908

381 Set 375 (On Campus for Internship) 909


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910

382 Set 376 (On Campus for Internship) 911


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913

383 Set 377 (On-campus for Full time) 914


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916

384 Set 378 (On-Campus) 917


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918

385 Set 379 (On-Campus for Internship) 919


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921

386 Set 380 (On-Campus) 922


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925

387 Set 381 (For SDE2) 926


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927

23
Contents

388 Set 382 (On-Campus for Full Time) 928


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930

389 Set 383 (On-Campus for Internship) 931


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931

390 Set 384 (On-Campus for FTE) 932


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 934

391 Set 385 (On Campus for Internship) 935


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936

392 Set 386 (On Campus for Internship) 937


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937

393 Set 387 (On -Campus for Full Time) 938


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940

394 Set 388 (On -Campus for Full Time) 941


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943

395 Set 389 (On -Campus for Full Time) 944


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946

396 Set 390 (On-Campus) 947


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948

397 Set 392 (For SDE 2) 949


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 950

398 Set 392 (On Campus for Internship) 951


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952

399 Set 393 (On Campus For Internship) 953


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955

400 Set 394 (On-Campus Full Time) 956


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957

401 Set 395 (On-campus for Internship) 958


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960

402 Set 396 (For SDE-2) 961


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962

403 Set 397 (On-Campus) 963


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965

404 Set 398 (On-Campus) 966


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968

24
Contents

405 Set 399 (On Campus for full time) 969


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971

406 Set 400 (For SDE 2) 972


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972

407 Set 401 (3+Years Experience for SDE II) 973


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974

408 Set 402 (Experienced for SDE 2) 975


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975

409 Set 403 (On Campus for Full Time) 976


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 977

410 Set 404 (On-Campus Internship) 978


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979

411 Set 405 (SDE-II) 980


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983

412 Set 406 (Off-Campus Internship) 984


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985

413 Set 407 (Internship) 986


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987

414 Set 408 (Internship) 988


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989

415 Set 409 (For SDE-I) 990


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991

416 Set 410 (On-Campus Internship) 992


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993

417 Set 411 (SDE-1) 994


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 995

418 Set 412 (SDE II) 996


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 998

419 Set 413 (SDET-1 On-Campus Internship) 999


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1001

420 Set 414 (For SDET-1) 1002


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1006

421 Set 415 (For SDE-2) 1007


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1008

25
Contents

422 Set 416 (On Campus for Internship) 1009


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1010

423 Set 417 (For SDE- 2) 1011


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1012

424 Set 418 (For SDE 2) 1013


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1015

425 Set 419 1016


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1016

426 Set 420 (For QAE) 1017


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1018

427 Set 421 (For Internship) 1019


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1020

428 Set 422 (For SDE II) 1021


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1022

429 Set 423 (For Cloud Support Associate) 1023


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1023

430 Set 424 (For SDE 2) 1024


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1026

431 Set 425 1027


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1028

432 Set 426 (For SDE-1) 1029


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1030

433 Set 427 (SDE-2) 1031


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1033

434 Set 428 (For SDE-2) 1034


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1036

435 Set 429 (For SDE 2) 1037


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1038

436 Set 430 (For SDE2) 1039


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1040

437 Set 431 (For SDE2) 1041


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1042

438 Set 432 (For SDE-2) 1043


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1044

26
Contents

439 Set 432 (SDET Off – Campus) 1045


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1046

440 Set 433 (SDE 2 for Experienced) 1047


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1048

441 Set 434 (For SDE-2) 1049


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1051

442 Set 435 (For SDE-2) 1052


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1053

443 Amazon Campus Drive (For Semester-Long-Internship) 1054


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1056

444 Amazon India SDE III Interview Experience 1057


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1057

445 Amazon Internship Interview Experience On-Campus 1058


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1059

446 Amazon Interview Experience 6 Months Intern for SDE-1 1060


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1062

447 Amazon Interview Experience (On Campus for 2 Month Internship) 1063
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1063

448 Amazon Interview Experience SDE2 1064


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1065

449 Amazon Interview Experience 1066


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1072

450 Amazon On-Campus – 6 months Internship (SDE) 1073


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1074

451 Amazon QA role & Support Engineer Intern interview experience 1075
Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1076

452 Amazon Recruitment Process 1077


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1079

453 Amazon SDE-2 Interview Experience 1080


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1082

454 Amazon SDE intern experience 1083


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1083

455 Amazon Web Services(AWS) Interview Experience (On-Campus) 1084


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1085

27
Contents

456 Amazon telephonic interview questions for SDE 1 1086


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1086

457 Amazon’s most asked interview questions 1087


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1088

458 Amazon’s most frequently asked interview questions | Set 2 1089


Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1090

28
Chapter 1

Set 1

Amazon Interview | Set 1 - GeeksforGeeks


Please find the details of my amazon interviews below.
Date of Interviews: 22nd August 2012
No of Rounds: 1 Written + 4 PI
Type of Interviews: Campus Interview for freshers
Written Test (Time): 90 Minutes
20 Objective Questions: Aptitude and basic C objective problems.
2 Subjective Questions:
I. To find if there is any root to leaf path with specified sum in a binary tree.
II. Some question based on sorting.
Interview Round 1(60-70 Minutes):
Technical Interview
Question 1: Check if a character link list is palindrome or not.
Question 2: A sorted array has been rotated r times to the left. Find r in least possible
time.
Question 3: 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.

Interview Round 2(50-60 Minutes):


Technical Interview
Question 1: There is a big file of words which is dynamically changing. We are continuously
adding some words into it. How would you keep track of top 10 trending words at each
moment?

29
Chapter 1. Set 1

Question 2: Write code for minHeapify() operation.


Question 3: Design a data structure for the following operations:
I. Enqueue
II. Dequeue
III. Delete a given number(if it is present in the queue, else do nothing)
IV. isNumberPresent
All these operations should take O(1) time.
Question 4: Write a function that returns the length of the longest leaf-to-leaf path in a
binary tree.
Interview Round 3(60-70 Minutes):
Technical Interview
Question 1: There is a binary tree of size N. All nodes are numbered between 1-N(inclusive).
There is a N*N integer matrix Arr[N][N], all elements are initialized to zero. So for all the
nodes A and B, put Arr[A][B] = 1 if A is an ancestor of B (NOT just the immediate
ancestor).
Question 2: Find an element in a sorted rotated integer array.
Question 3: There is a N*N integer matrix Arr[N][N]. From the row r and column c, we
can go to any of the following three indices:
I. Arr[ r+1 ][ c-1 ] (valid only if c-1>=0)
II. Arr[ r+1 ][ c ]
III. Arr[ r+1 ][ c+1 ] (valid only if c+1<=N-1)
So if we start at any column index on row 0, what is the largest sum of any of the paths till
row N-1.
Interview Round 4(40-50 Minutes):
Bar Raiser Round
Interviewer asked HR Questions Initially, then a sort of puzzle.
Two robots land with their parachutes on an infinite one-dimensional number line. They
both release their parachutes as soon as they land and start moving. They are allowed only
to make use of the following functions.
I. moveLeft() // robot moves to left by 1 unit in 1 unit time
II. moveRight() // robot moves to right by 1 unit in 1 unit time
III. noOperation() // robot does not move and takes 1 unit time
IV. onTopOfParachute() // returns true if the robot is standing on top of either
of the parachute, else false
V. didWeMeet() // returns true if the robot meets to the other robot, else false

30
Chapter 1. Set 1

Write a function in order to make the robots meet each other. Robots will be executing the
same copy of this function.
HIRED!! �
Tips / Advice:
I. Each time you write a code, check for the edge cases.
II. Do not assume anything. Keep asking questions if there are any doubts.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview/

31
Chapter 2

Set 2

Amazon Interview | Set 2 - GeeksforGeeks


Please find the details of my amazon interviews below.
Date of Interviews: 26th July 2012
No of Rounds: 1 online exam + 4 PI
Type of Interviews: Campus Interview for freshers
Online test(Time): 90 Minutes
20 Objective Questions: Aptitude and basic C objective problems.
2 Subjective Questions:
I. Given a linked list containing character in each node, segregate its nodes in
such a way that all nodes containing a vowel are moved to the end of the linked list. We
will have to maintain the order.
II. Parenthesis checker.
Interview Round 1(30-40 Minutes):
Technical Interview
Question 1: You are given a linked list and a parameter k. You will have to swap values
in a certain fashion, swap value of node 1 with node k, then node (k+1) with node 2k and
go on doing this in the similar fashion
Question 2: For the above question, do it without swapping the values. If you want a
swap to occur between two nodes, then you will have to move the nodes itself.
Interview Round 2(50-60 Minutes):
Technical Interview
Question 1: You are given many slabs each with a length and a breadth. A slab i can be
put on slab j if both dimensions of i are less than that of j. In this similar manner, you

32
Chapter 2. Set 2

can keep on putting slabs on each other. Find the maximum stack possible which you can
create out of the given slabs.
Question 2: The above question was raised to 3 dimensions.
Question 3: The above question was then raised to k dimensions.
Questions : Then there were many questions asked on compilers and dynamic memory
allocation.
Interview Round 3(50-60 Minutes):
Technical Interview
Question 1: You are given pairs of numbers. In a pair the first number is smaller with
respect to the second number. Suppose you have two sets (a, b) and (c, d), the second set
can follow the first set if b<c.So you can form a long chain in the similar fashion. Find the
longest chain which can be formed.
Question 2: Find the longest increasing subsequence in O(nlogn). Proof and full code
was required.

Question 3: You are given a linked list and an integer k. Reverse every consecutive k nodes
of the given linked list.
Question 4: You are given an array. For every element you have to replace it with the
closest number on the right side which is greater than the element itself.
Interview Round 4:
The team was highly impressed so they cancelled my 4th round � for others who appeared
for the 4th round, it was atleast an hour long.

HIRED!! �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-2/

33
Chapter 3

Set 3

Amazon Interview | Set 3 - GeeksforGeeks


Please find the details of my Amazon interviews below.
Date of Interviews: 26th July 2012
No of Rounds: 1 online exam + 4 PI
Type of Interviews: Campus Interview for freshers
Online test(Time): 90 Minutes
20 Objective Questions: Aptitude and basic C objective problems.
2 Subjective Questions:
I. Given a linked list containing character in each node, segregate its nodes in such a
way that all nodes containing a vowel are moved to the end of the linked list. We will have
to maintain the order.
II. Parenthesis checker.
Interview Round 1(50 mins)
Question 1: You are given two linked lists whose nodes contain a digit as data member.
Both lists represent a number. You have to add them and return the resultant list.
Input: 9->9->3->4->5 and 8->9->1 (represent 99345 and 891)
Output: 1->0->0->2->3->6
My Solution: Reverse the linked lists. Create the new sum list which is reversed. Finally
reverse the resultant list.
Question 2: Interviewer asked to solve the above question without changing the original
lists.
My Solution: Count number of nodes in both lists. If equal then simply add two lists
recursively. If not then advance a temp ptr which is a pointer to head of larger list by diff
of nodes and then add the list pointed by temp and list 2. Make sure to keep track of carry.
Add recursively. Propagate the carry in remaining elements of larger list. Was asked to
code. Coded it.
Interview Round 2(60 mins)

34
Chapter 3. Set 3

Question 1: Delete nth node from end of a linked list in a single scan.
Question 2: In a linked list, in addition to the next ptr, a random ptr is also present.
Clone the linked list.
Did it in O(n) but by modifying the linked list and then restoring it. Was asked to do it
without making any modifications in the original list. Did that in O(n^2)
Question 3: Two nodes of a BST are given. Print the path from 1st node to the 2nd node.
You are also provided the parent pointers in addition to normal left and right pointers.
Interview Round 3(1 hour)
Question 1: 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.
Question 2: An extension of Question 1. Was asked to find number of times each number
is repeated.
Question 3: There are n frames of m data element each. The data element in each frame
is arranged in increasing order. You are provided m*n space in which you have to arrange
all data in increasing order.
My 1st solution was to use merge sort. He modified the question as only O(n) space is there
and you need to send data in increasing order as fast as you can.
My 2nd solution was to use min heap and construct it with the 1st element of all n frames.
Min heap also contains extra field which signifies the frame number of data elements. This
data structure can do the needful.
Interview Round 4(1 hour)
Question 1: Replace each element of an array with its greatest next integer in O(n).
I couldn’t do it. I tried but it didn’t click. Not expected when you are in your last round.
Question 2: Reverse every k nodes of a linked list.
Well did that but was not finally selected……. �
This article is compiled by Vinay Khetan. We will be soon publishing Vinay’s Yahoo
and Microsoft interviews as separate posts. Vinay was selected in Microsoft. Many Many
congratulations to Vinay for his selection.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-3/

35
Chapter 4

Set 4

Amazon Interview | Set 4 - GeeksforGeeks


Please find the details of my Amazon interviews below.
Date of Interviews: 1 Sept 2012
No of Rounds: 4
Type of Interviews: Walk-in for 1 yr experienced
Round 1:
Question 1:- Given a 2D array containing only 0/1’s and each row is in sorted order. Find
the row which contains maximum number of 1s.
I was asked to code. Algo which I told was I will search position of first 1 in 1st row using
binary search. And mark it. Now note that position check in 2nd row. If there is 1 for that
position already found in 1st row, then binary search from 0 to that position else move to
row number 3. Similarly continue further.
Round 2:-
Question 1:- Given a Binary tree and two nodes. Need to find the minimum ancestor, no
parent nodes given.
Each time when I told answer, they modified question little bit or removed some extra
storage which I was taking.
Question 2:- Given a Binary tree and two nodes. Need to find smallest path between them
Round 3:-
Question 1:- Given an array of infinite size containing 0/1 only and in sorted order, find
position of first one.
My answer: first check whether 1 is present at 100th position or not if there, do binary
search between 0 and 100 else check 1 is there at 200th position, and similarly continue
further.
Question 2:- Given life time of different elephants find period when maximum number of
elephants lived. ex [5, 10], [6, 15], [2, 7] etc. year in which max no elephants exists.

36
Chapter 4. Set 4

Other questions were regarding Operating system like virtual memory etc.
Round 4:-
It was HR round. Questions related to project. Questions like why I should Hire you etc
were asked.
Result is still on wait.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-4-2/

37
Chapter 5

Set 5

Amazon Interview | Set 5 - GeeksforGeeks


I’ve attended the Amazon interview in Hyderabad, This was kindle team, I got rejected but
I’d like to share the experience, thought of giving back something to geeksforgeeks, which
was a great reference for me.
Written test
Very straight forward
1. Given a linked list, sort without extra space.
I wrote merge sort
2. Methods to serialize & deserialize a tree ,must complete the below 2 monthods. File
serialize (node *root) & node * deserialize(File f)
Cleared the written test, I was told this after 1:30 Hrs.
First round
1. Find diameter of a tree, I’ve seen the question here, But i didn’t recollect.. So solved my
self..in some primitive way which made me write code with difficulty.
2. Find a lowest common Ancestor, The variation was the tree was just a Binary Tree, Not
BST, It was interesting to solve as i know only BST variation.
Second round
1. Given an array randomize it,
2. Write all possible permutations of a array of size z.
3. Given a 2-D array of 0s and 1s, find islands in it. An Island is 1s together. E.g (below
there is U shaped island)
0100001
0100001
0100001
0100001
0111111
4. Write a method to check if a tree is BST or not. I wrote some stupid mistake in this
code, probably that gave away my interview.

38
Chapter 5. Set 5

Third round
1. So many HR like questions. Why Amazon, Why u want to leave, Why u dont want to
stay, what did you do to stay back, biggest challenge, worst mistake, etc etc.. blabbered
something.
2. Write a method that will test a function which merges 2 sorted linked lists.
3. Design a system, which can convert books from one format to another
Fourth Round
Only one design question: Design a email client.
After 4 days and lot of anticipation, I got a mail saying I got rejected, Was wondering what
they exactly look for.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-4-3/

39
Chapter 6

Set 6

Amazon Interview | Set 6 - GeeksforGeeks


Following are my interview details for senior software engineer in 2010. Thought of sharing
it, if it helps anybody
Telephonic Interview 1
1) Write your own power function in C/C++. Time complexity of your code, optimizations.
2) Given two strings, write a function to remove all characters in one string which are present
in other string
Telephonic Interview 2
1) Construct a tree from ancestor matrix. The main thing he wanted to check was use of
binary search.
2) Find the k maximum selling items at amazon site at the end of day. Given a file which
has count all sold items. Use of min heap was expected.
Face to Face 1
1) Given a Binary Search Tree, in-place convert it to DLL.
2) Find the next greater element for every element in array.
Face to Face 2
1) Median of two sorted arrays.
2) Given an XML file, how will you store it in memory. Use of tree was expected.
There were some more questions that I don’t remember.
Face to Face 3
1) Given a Binary Tree, check if every node is sum of all of its children.
2) Given any Binary Tree, convert it to a tree where every node is sum of all of its children.
3) Given an array, find three numbers a, b and c such that a^2 + b^2 = c^2
That is all I remember now.

All Practice Problems for Amazon !

40
Chapter 6. Set 6

Source

https://www.geeksforgeeks.org/amazon-interview-2/

41
Chapter 7

Set 7

Amazon Interview | Set 7 - GeeksforGeeks


Hi my name is Anandhakumar. P. I am a 2012 pass out from college of engineering guindy.
I recently underwent offcampus interview with Amazon, Chennai, India for the post of SDE.
I love geeksforgeeks and i will call it as the best site to prepare for coding interviews. Here
goes my interview experience. Hope this is useful to someone and someone gets benefitted
by it.
Written test [1 hr 15 min duration]
Three questions were asked.
1) Check whether a tree is balanced.
2) Reverse k nodes in a linked list.
eg 1->2->3->4->5->6->7->8->9->10->11 [k=3]
answer must be [3->2->1->6->5->4->9->8->7->11->10]
3) arr1 – 4, 5, 6, _, _, _
arr2 – 1, 2, 3
arr1 has enough free space to hold elements of arr2. Merge array 2 with arr1 in a sorted
manner.
Cleared this round. I felt it easy as i was preparing for it for more than 2 months and
geeksforgeeks helped me greatly.
1st face-to-face interview [1 hr 15 min ]
Short description about myself
[2 min alone. Just told my name and my most important project for which i won ipad 2]
1) An array of size n is given. The array contains digits from 0 to 9. I had to generate the
maximum number using the digits in the array such that it is divisible by 2, 3 and 5
eg: 1 array = 18760, output must be: 8160
eg: 2 array = 7776, output must be: “no number can be formed”
[discussion went for more than 35 minutes. Every time i gave a solution, he was adding the
constraints and finally i did it. he was ok with it.]

42
Chapter 7. Set 7

2) least common ancestor in a binary tree [Note : not binary search tree ] [30+ minutes]
I explained him with several methods and finally he was ok with and asked me to write the
code for and i did it. he checked my code for different test cases and finally he was ok with
it ..
Not even 5 minutes break i was asked to get ready for next face to face interview .
2nd face to face interview [1 hr 20 min ]
Short description about myself [2 min alone. just told mmy name and my most important
project for which i won ipad 2. dont tell too much. they just wanted to know a little about
u . inshort ur name and college. ]
1) zig zag traversal of a binary tree. [35+ min ].
Man i have studied this in geeksforgeeks and wrote him the code using recursion, which was
working perfectly. But he told me to use reduce the complexity by using any data structures.
I told him a logic using a stack and a queue. Another logic using 2 stacks . But he wanted
me to use only one data structures. I tried using a single queue and he to helped me a little
and finally he was ok with it .
2) A n*n matrix is given which is containing elements in which each row alone is sorted.
column is not sorted. I have to convert it into a single dimensional array which will hold all
the elements of the array in a sorted manner.
I told him many logics . actually he kept on adding constraints with whatever logic i told
him. Finally he gave me a hint and asked to use minheap property and finally he was
ok with it. I solved this question using lots of help with him. man i was in interview for
continuously more than 3 hours.
I am waiting for my result for next round. I will update if i go through the next rounds.
Overall it was a great experience with amazon and people in amazon are very smart minded.
Hope this is helpful to someone!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/microsoft-interview-set-7-2/

43
Chapter 8

Set 8

Amazon Interview | Set 8 - GeeksforGeeks


I recently interviewed with amazon for the position of SDE1 in their TRMS team. The
interview procedure was unimaginable rigorous.
Here are the details
Round 0: Written Round
Interviewstreet Test – 2 questions to be done in 2 hours
Q1: Calculate the expression (2+3)*5 .. The question just said this .. I guess we had to
make our own assumptions to solve the problem
Q2: Two trees can be called isomorphic if they have similar structure and the only difference
amongst them can be is, that their child nodes may or may not be swaped..
for example
——4
—-2—6
–1–3–5–7
and
——4
—-6—2
–1–3–7–5
are isomorphic .. the trees are similar and a few nodes have their left and right child
swapped…
Given two trees determine if they are isomorphic…
The interviewstreet people marked the solution to my first question wrong even when it
worked fine.. When I told the HR about the situation, she got it checked with some of the
amazon guys and they were ok with it.

44
Chapter 8. Set 8

I cleared the written test.


Telephonic Interview 1
Q1: 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.
Q2: Given an array of positive integers, find the max no that can be formed by any permu-
tation of the arrangement. I told her a logic. She then asked me to write just the comparison
function to choose one number to put before the other.
When I gave the interviewer straight answers, she twisted the question more.. Probably
they wanted to see how i think and approach a problem.
Telephonic Interview 2
Q1: A binary search tree is given with its two nodes interchanged. I had to find both the
nodes.
Q2: Identify all the pythagorian triplets in the given array.
I cleared this round. The HR told me I had to come over to Bangalore for in-person
interviews. (all the travel arrangements were made by amazon itself)
Personal Interview 1
Q1: Find the sum of continuous subarray within a one-dimensional array of numbers which
has the largest sum .. I didnt know a solution (kadane’s algorithm), but somehow I was
able to work it out in the interviews ..the interviewer liked my way of approaching and did
help a little
Q2: How can you best implement queues using stacks. What would be the time complexity?
was able to do this one quickly.
Personal Interview 2
Q1: Find non-unique characters in a given string. I told her one O(n^2) [brute force], one
O(n logn) [sort and then compare adjacent elements], and one O(n) [store the character
count in an array] approach. She then asked me to do it in O(n) without using array.
Clueless, she finally told me she wanted me to use BIT Vector. I wasnt well converse with
Bit Vectors and I told her so.. She still asked me think more. Finally she told me a solution
using the same which was impossible to think in the interview alone, especially when one
didnt know what BIT Vectors were. She agreed when I stated the point and accepted my
previous O(n) solution and we proceeded to the next question.
Q2: Given an array of integers, populate another array with the product of the elements
of the first array except for the current index element.
Here when I gave her a O(n) solution [find product and divide it with current element to
get the number for this index position], she asked me to do it without the divide operator.
Gave her a O(n^2) solution. But I couldn’t think better. Finally just when she began to
tell me an O(n) approach, I remembered the geeksforgeeks solution to the problem and
gave it to her. Probably she didn’t consider it. (don’t know for sure)
Personal Interview 3

45
Chapter 8. Set 8

This interview was with the hiring manager at Amazon. He first asked me a couple of HR
questions like Why Amazon? Why should we hire you? Projects, internships etc ..? How
would you handle a disagreement with your team mates? Etcetc …
Then he asked me a programming question.
Q: He drew a circle on the board and marked a few points on it. Named them X1, X2, X3
..
Then he said these are gas stations, and you have to find the correct gas station from where
a car should begin to loop in the circle such that it never runs out of gas before completing
a round. He then sat on the table.
(Sorry, but I will have to describe it in detail to tell you how it was put out to me.. and
off-course to bring in more clarity to the question itself.. )
Unclear about what I had to do exactly and what information was available, I asked him
back a few questions.
Why will car run out of gas after fuelling from lets say the first gas station?
He said each gas station has limited amount of gas (lets say X1) and after fueling from
this station it can run out of gas even before reaching the next station (anything could
happen, it may be able to cross the next gas station but run out later before completing
the round..). So I have to find a gas station the car should start the loop from such that
it never runs out of gas before completing the loop.
So can the car refuel at the next available gas station, if its able to make up to it?
Yes
Do we have the information about the amount of gas required to reach from one petrol
pump to another?
Yes
I made an assumption that the car tank was huge enough to fill as much gas as possible.
And then I drew two arrays, one holding the amount of gas each station had, and other the
amount of gas needed to go from this station to the next station..
Fuel Available: X1, X2, X3, X4, X5
Fuel Required to reach next station: Y1, Y2, Y3, Y4, Y5
He said ok, and asked me to go ahead.
I then took the difference (Y1-X1), (Y2-X2) ..and stored it in an array.. and then suddenly it
hit me that this became a simple problem of finding the maximum sum of a continuous
subarray within an array (circular). He liked my approach and asked me to program it. Did
it and showed him a dry run of the code I had written. He was ok with it.
(I felt good after the interview because in there I didn’t stumble at all ..)
Personal Interview 4
Q1: 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

46
Chapter 8. Set 8

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.
Q2: Find the smallest substring which contains all the characters of the main string. Again
I dint have a solution to this. I gave him a O(n^2) approach. He asked me to think further
because the way I was approaching it was the way to go about it and I can make use of the
last sub-solution obtained to improve my complexity. Couldn’t think of anything, we finally
moved on to the third question.
Q3: given the numerator and denominator of a fraction, find the quotient and the remainder
without using divide and mod (‘/’, ’%’ )operators. This was simple. I did it. He then
asked to write the invariant of my solution which was denominator*quotient + remainder
= numerator.
He then asked me to think about the cases when either or both of numerator and denom-
inator were negative. We were almost out of time so he didn’t give me time to think and
concluded the interview. He wanted me write an invariant that was true regardless of the
input. Now that I think of it, I should have said |denominator|*quotient + remainder =
|numerator|
Flew back home in the night.
2 Days later the HR informed me that I didn’t make it in. �
This was probably the most difficult of all the interviews I have ever had.
Hope it helps some of you ..
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-8/

47
Chapter 9

Set 9 (Answers)

Amazon Interview | Set 9 (Answers) - GeeksforGeeks


This post is about answers to the questions asked in Amazon Interview | Set 9. It contains
links to some of the solutions available on the geeksforgeeks. I have also written my answers
which I replied in the interview. I hope it would help the readers.
Online Programming Round: (5 methods, 2 hours)
3) https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/
5) https://www.geeksforgeeks.org/longest-increasing-subsequence-dp-3/

Telephonic Interview 1:
1) https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
2) https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/
3) https://www.geeksforgeeks.org/array-rotation/

Telephonic Interview 2:
3) Find the distance of every other point from P. Then use of max-heap of size K.
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/

Face-to-face Interview 1: (Hyderabad, Date: November 08, 2012)


2) I gave the following solution (with the help of the interviewer):
1. For every set, find out the number of sets it has intersection with. Also maintain those
set indices.
2. Remove the set which has maximum number of intersection. And update the remaining
numbers.

48
Chapter 9. Set 9 (Answers)

3. Repeat step 2 till we have any set which has intersection with any other set. At the end,
we will have the solution. (Still not sure about optimality).
We can relate the solution with graphs: Remove some nodes so that remaining all the nodes
are isolated nodes.
Searching: To make searching efficient, we can build trie data structure using bits for every
set. So that we can find the intersections fasters.
Face-to-face Interview 2 (with a manager):
1) I tried for some time. Then the interviewer gave me the formula. The number is
1+ceil((N-W)/S) in all the cases.
For second part of question, simple solution is to find min in every window. But we can
optimize so that we can utilize previous results/previous min.
Bit optimal: I created a min-heap of W elements. But the heap contained indices of the
array elements, not the values inside the array itself. The indices were stored in heap as
per their values in the array. Then for a new window, search the heap linearly (heap was
in form of array), replace the old indices (which are no longer in the new window) with the
new indices, and adjust that index in the heap. After adjusting all the new indices, we will
have new min for the new window at the root. (Not sure whether the complexity brought
in to the solution is worth!)

Face-to-face Interview 3:
2) I gave a solution based on trie data structure using characters of the string. But he
suggested to build trie based on the string itself. However, I was not able to think in that
way.
3) Linear search. Binary search.

Face-to-face Interview 4 (with the manager of the unit of opening):


2) I said, we can organize an online coding competition. People would register and
we will have the details. He replied, it’s too expensive. Then I said, we can postpone the
competition!
All the Best!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-9-answers/

49
Chapter 10

Set 9

Amazon Interview | Set 9 - GeeksforGeeks


How did it start?
I completed and submitted the 4 programs at the link: https://amazon.interviewstreet.com/
challenges/dashboard/#problems
Later on I came to know that the recruitment through this link is over. So I contacted a
few of HR persons at Amazon, and I got a new link for online programming test.
Online Programming Round: (5 methods, 2 hours)
1) A sentence is given which contains lowercase English letters and spaces. It may contain
multiple spaces. Get first letter of every word and return the result as a string. The result
should not contain any space. Complete the following method:
static String getFirstLetterWord(String text) { }
2) Given an array. Iterate it for the given number of times. And then return the
summation of the resultant elements.
Ex: Array is { 1,2,5,6}, N=2
After 1st iteration: {2-1, 5-2, 6-5}={1,3,1}
After 2nd : {3-1, 1-3}={2,-2}
Sum is 2 + (-2) = 0
If only one element remains in the array, the element remains the same after applying the
iteration. Complete the method.
static int iterateSequence(Vector<Integer> a, int N) { }
3) Find Nth largest element in the BST. Complete the method.
staticintnLargeBST(Node root, int N) {}
Given that

50
Chapter 10. Set 9

class Node
{
Node left, right;
int data;
Node(intnewData)
{
left = right = null;
data = newData;
}
}

4) Swap adjacent nodes in the linked list. Change the links, not the data. Complete the
method.
Ex:1, 2, 3, 4
o/P: 2, 1, 4, 3
ex: 1,2,3,4,5
op: 2, 1, 4, 3, 5

class Node {
Node next;
int val;
}

static Node swapAdjacentNodes(Node head) {}

5) Find length of the Longest-Increasing-Subsequence.


e.g.1.
i/p: 1, 2, 3
o/p: 3
explanation: the sequence is increasing
e.g.2
i/p: 4,5,6,7,8,1,2,1,2,3,5,4,6,7,8,9,0,6,7
o/p: 8
xp: 1,2,3,4,6,7,8,9
e.g.3
i/p: 1,2,9,4,5,10,7,8
o/p: 6
xp: 1,2,4,5,7,8
e.g.4
i/p: 20, 3,22, 5,50, 34, 49, 91,110
o/p:6

51
Chapter 10. Set 9

xp: 20,22,34,49,91,110
OR
3,5,34,49,91,110
Complete the method.
static int lengthLIS(Vector<Integer> sequence) {}
Telephonic Interview 1:
1) A M x N matrix, filled with 0s and followed by 1s. Find the row which contains
minimum number of 0s. E.g.
0 0000 1
0 0 1 111
0 00 1 11
The answer is 2nd row. (Row index: 1)
2) Find whether given two strings are anagrams of each other.
3) Given an array of size N, move the first d elements to its last.
e.g. {1, 2, 3, 4, 5}, d=2

• output: {3, 4, 5, 1, 2}

Telephonic Interview 2:
1) Given a BST, find the node which contains the value which is equal to (or lowest
greater than) the input value.
2) Kadane’s algorithm for 1 dimensional array.
3) Given a point P and other N points in two dimensional space, find K points out of
the N points which are nearer to P.
Face-to-face Interview 1: (Hyderabad, Date: November 08, 2012)
1) Given a Singly Linked List which contains integers, bring odd values in the beginning
and even values at the end. The relative order of odd values, and that of even values should
be maintained as it is.
e.g. 34, 45, 78, 10, 33, 5

• o/p: 45, 33, 5, 34, 78, 10

2) Given N sets of integers, remove some sets so that the remaining all sets are disjoint
with one another. Find the optimal solution so that the number of sets remaining at the
end is maximum.
Face-to-face Interview 2 (with a manager):
1) Given an array of size N, a window of size W slides over it by increment of slide S. If
the window reaches to the end, we should stop there. Find a formula in form of N, S, W so

52
Chapter 10. Set 9

that we can find the number of valid windows. Write a program to find minimum in every
window and print it. Optimize it.
e.g. {1,2,3,4,5}, W=2, S=1
first window: {1,2} min=1
second window(increment by S=1): {2,3}, min=2

last window: {4,5}, min=4
The array might not be sorted. I have taken sorted array for simplicity.
Face-to-face Interview 3:
1) Trim the Given BST by given min and max values. It means remove the nodes which
have values less than min or greater than max. Write iterative and recursive – both the
solutions.
2) Given an array of strings, find the string which is made up of maximum number of
other strings contained in the same array.
e.g. “rat”, ”cat”, “abc”, “xyz”, “abcxyz”, “ratcatabc”, “xyzcatratabc”
Answer: “xyzcatratabc”
“abcxyz” contains 2 other strings,
“ratcatabc” contains 3 other strings,
“xyzcatratabc” contains 4 other strings
3) Find integer value of sqrt(N). Do not use any library functions or any mathematical
solution.
Face-to-face Interview 4 (with the manager of the unit of opening):
1) Given a 2-dimensional array of integers, find the value 1 in the array, and set all those
rows, and columns to 1, which contains one of the values as 1.
2) Suppose you are working in companies like naukri.com. You need to collect email Ids
and contact numbers of all the Software Engineers aged between 25 to 40, in India. How
will you do that?
3) Suppose a person of the age of your grandfather works on computer. He knows little
about the computer. And he complains that it was working fine, but for last 2 days, it has
become very slow. How will you solve it? What could be the reasons?
4) Design an IVR system for a Restaurant in which customers can book their tables for
lunch and/or dinner. Advance booking for 2 or 7 days/as you wish. After the request from
user, respond to him that you will confirm the request within 5 minutes. Check availability
and send SMS confirming the same. If the SMS is delivered then assume that the customer
is genuine. If the SMS is not delivered properly, discard the user request, as it is not genuine.
i) How can you take names and email Ids of the customers during the process?
ii) What can you do for repeat customers? How will you identify the repeat customers?
iii) If there is request for a team size greater than the table size, what will you do? E.g.
request for 10 persons when table sizes are 6, 4 and 2.
All the Best!
All Practice Problems for Amazon !

53
Chapter 10. Set 9

Source

https://www.geeksforgeeks.org/amazon-interview-set-8-2/

54
Chapter 11

Set 10

Amazon Interview | Set 10 - GeeksforGeeks


Recently I got interviewed at Amazon Hyderabad. I just wanted to share my experience.
Hope someone gets little help from this.
1. Telephonic
a. In Binary Tree node, extra pointer ->next is given in the structure of node. Make linked
list at each level.
I did it with using Queue made of doubly linked list. Time complexity O(n), space O(n).
I was asked to write code as well on collabedit site.
b. Equilibrium point in array, equiPoint = ith index where Sum(Left array) = Sum(right
Array).
Did it O(n) time complextity and O(1) space. I was asked to code it as well.
2. Telephoinc
a. Find each pair in BST, which adds up to given number k.
Explained different methods for it and he asked me to code for one.
I did it as follow.
void findPairs(node *start, int k)
{
if(start == NULL)
return;
findPair(start->left, k);
if(k – start->data > start->data)
{
if(search(start->right, k – start->data)) // this search is normal BST search.

55
Chapter 11. Set 10

printf(“(%d, %d), “, start->data, k – start->data);


findpair(start->right, k);
}
}
b. There were few other simple questions. I don’t remember know.
1. Onsite: with Hiring Manager.
a. About Project, cross questioning, etc.
b. Two files containing large number, one in each. You have only fopen(), int read(fp),
fclose(), fwrite(). Add these two numbers and write in third file with the help of given
functions only.
Explained him the logic and he was okay with it.
c. Write sql query for getting direct and indirect reportees of a given employee. Lets say
Employee table(empId, ManagerId).
wrote it and he verified it and it was okay. Recursive query, CTE.
d. Oops concepts, asked to explain Static keyword with all possible example.
Explained, variable, methods, classes one by one with Static keyword.
2. Onsite: with Developer.
a. Print encoding for an Array.
Rules: consider BST made from given array. Let say number x is present in the BST
and to reach x, If you go right print 1, if left then 0.
Now you are given an index i in the array A (so x = A[i]) and print the encoding without
constructing BST to reach x
and without space with least time complexity.
I was not able to do it on the spot but after this interview, I got some free time and solved
it and handed over papers to the interviewers. I liked this problem. It was little interesting.
b. Find triplets in array so that a+b+c = k, k is given number along with array.
c. Then moved to finding all possible pair set in an array. Mind the term SET. Take care
of duplicates as well.
Reduce time complexity as much as you can.
3. Onsite: with Developer.
a. Given array, find all possible sets of elements which add up to a given integer K.
I coded it with just 4-5 lines in just couple of secs. It took little time to make him
understand the solution.
I was given an input of 6 numbers in an array and asked to run my solution till the end.
It was recursive and he asked me to keep on writing, writing, writing, till he got that okay,
it will work fine.

56
Chapter 11. Set 10

b. I was asked couple of questions which I already knew and I told him and we moved on
to next questions. I don’t remember what he asked.
c. If tree is BST or not. Coded it.
4. Onsite: with One Manager and Senior SE.
a. Discussion on my current Project. Quite a good discussion. It took quite a good time.
They asked me what more enhancements I can think of for features, I made in my project.
I explained few different things that I could think on the spot and they liked it.
b. Linked list with a “mad” pointer along with “next” pointer in it, mad can point any
where(can be null as well). Return clone of given such linked list.
I already knew the best approach for this. Then he asked me to think something else. I
mentioned Hash. He was okay with it and we moved on.
c. Replace the elements in an array with the next following greater number of it from right
side of the element.
I told him I already know this and I asked if he wants me to explain the algo. He said
so and I explained. Then we moved on.
d. Reverse each K nodes in linked list.
e.g. 1->2->3->4->5->6->7-_ given
output 3->2->1->6->5->4->7-_
e. Two strings S and S1. Remove all chars from S which are present in S1.
Explained them all possible methods for this what I could think of(with space, without
space). Finally, they were looking for BitMap solution. I explained that as well before one
mentioned it.
f. Design a Chess game.
Gave different classes and their relations, some procedures, then cross questioning and I
was able to give all answers which he mentioned quite reasonable.
They were okay with the design.
In the whole interview process I was asked like 8-10 questions which I already knew and I
mentioned the interviewers same. I was told why you read so much.
Overall, it was quite a good experience for me. I liked the way interviewers were interacting.
They were very supportive and friendly as well.
Unfortunately, I was not selected. � I have no idea what they were looking for.

All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-set-10/

57
Chapter 12

Set 11

Amazon Interview | Set 11 - GeeksforGeeks


I would like to thank geeksforgeeks team for the excellent website. I got placed in amazon
because of your website. I would like to share my experience and the interview questions.
1 round was online written technical test
There were 20 MCQ and 2 programming questions. Each correct answer carried 1 mark and
-0.25 for a wrong answer. Programming questions were:
—Write a program to find the difference between the sum of nodes at odd height and the
sum of nodes at even height
—Given an array of integers representing coin values and the sum required. find the number
of coins required to get the sum
4 technical rounds
Various programming questions related to data structures were asked. Each round was an
elimination round. Questions asked were
—Write a program to traverse the tree in spiral form in O(n) time.(Hint:use two stacks)
—Program to implement atoi function
—Program to swap the kth node from end and kth node from front
—Program to find loops in linked list
—Find the maximum length palindrome in a string
—Difference between process and thread
—Advantages and disadvantages of thread and process
—Test cases for checking binary tree
—Test case for atoi function
—Test cases for finding loops in the single linked list
Each technical round was for 60-90 minute duration. There was no HR round �

58
Chapter 12. Set 11

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-11/

59
Chapter 13

Set 12

Amazon Interview | Set 12 - GeeksforGeeks


I am very thankful to geeksforgeeks team for such a great site. I got offer from Amazon.
Written Test
It was online test on interviewstreet.
20 MCQs- basics of C & C++, OS and some aptitude question
There were 4 technical rounds each for 40-60 minutes, no HR round.
1st Round
Given two numbers and a binary tree, all elements in binary tree are distinct, write code to
determine the shortest distance between the two nodes. (unit distance between two adjacent
nodes). Nodes don’t have parent pointer.

2nd Round
1. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2. There are some glasses with equal volume 1 litre. The glasses kept as follows

1
2 3
4 5 6
7 8 9 10

You can put water to only top glass. If you put more than 1 litre water to 1st glass, water
overflow and fill equally both 2nd and 3rd glass. Glass 5 will get water from both 2nd glass
and 3rd glass and so on..
If you have X litre of water and you put that water in top glass, so tell me how much water
contained by jth glass in ith row.
Example. If you will put 2 litre on top.
1st – 1 litre

60
Chapter 13. Set 12

2nd – 1/2 litre


3rd – 1/2 litre
3rd Round
1. https://www.geeksforgeeks.org/a-program-to-check-if-a-binary-tree-is-bst-or-not/
2. Liked list is given as below (with elements as 1, 2 and 3), sort this in one pass.
3->2->2->1->2->3->1
4th Round
1. An expression is given.
[] can enclosed [], {} and ()
{} can enclosed {}, ()
() can enclosed only ()
Check that brackets in the expression are valid or not according to enclosing condition and
opening closing condition.
Follow UP:
Two arrays are given.
One array contains symbols and second one contains expressions. Symbol array contains
opening symbol at even index and closing symbols at odd index just after opening symbol.
Index is starting from 0. Opening symbol at index i can only contain symbols from i to
2n-1, If there n pairs of symbols.
Now check that expression in the expression array is valid or not.
2. 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.
I liked the way interviewers were interacting. They were very supportive and friendly as
well.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-12/

61
Chapter 14

Set 13

Amazon Interview | Set 13 - GeeksforGeeks


Round 1 (Telephonic)
Q1. For a given number, find the next greatest number which is just greater than previous
one and made up of same digits.
Q2. Find immediate ancestor of a given Node
Q3. Clone the linked list having an extra random pointer in nodes which is pointing random
node in the list.
Round 2 (F2F)
Q1 In a binary tree, a random pointer is given in each node. If this pointer pointing other
than any successor of the node then set it as NULL. Otherwise let it remain untouched.
Write code.
Q2. You will be given the number of pairs of parenthesis. Find out the total possible valid
unique combinations and there should not be any duplicity. Write code
Round 3 (F2F)
Project and some questions related to it.
Q1 Given an in-order traversal of a special binary tree having property that the node is
always greater than its left and right child. Construct the tree and write code.
Q2 Find top 10 trending words inserted by users in sites like twitter. Only algorithm.
Q3 write an efficient code to find the first occurrence of 1 in a sorted binary array. (2
minutes only)
Round 4 (Telephonic)
Q1. Remove duplicated from a string in O(n) without using hash.
Q2. Find the first occurrence of 1 in a sorted infinite binary tree.
Round 5 (F2F)
Amazon has many visitors to its site. And it tracks what pages the customers visited, etc
and other stuff.

62
Chapter 14. Set 13

Make an efficient data structure for storing 3 days of information of all those customers who
have visited site exactly two different days and searched more than 3 unique pages of the
site in those 2 days.
So whoever visited site exactly two days out of these three days and visited more then 3
unique pages should be in the contact list.
After final round got a regret mail after 3 days that I was Not selected.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-13/

63
Chapter 15

Set 14

Amazon Interview | Set 14 - GeeksforGeeks


Team : Transportation
Location :Hyderabad
Round 1 (Online Test)
Q1. Find the kth largest value in a BST
Q2. Swap the alternate nodes in a singly linked list( not the data);
Q3. Minimum no of coins required to get the given sum. Coins are given in a sorted array.
Q4. A file contains data as follows( Student name, marks in 3 subjects)
Shrikanth 20 50 60
Kiran 30 80 90
Find the student who has maximum average score
Q5. Find out given two trees are isomorphic or not
Round 2 (Telephonic Round)
Q1. Print the level order of binary tree such that each level should print in a different line
Q2. Push() and Pop() methods of stack are given. Write a function to get the minimum of
stack in O(1) time
Project related questions
Round 3 (F2F with Dev Manager)
Q1. Connect nodes at same level in a binary tree( may not be a complete binary tree)
without using recursion
Q2. Sort the linked list which contains only 1,2,3 numbers in a single pass
Round 4 (F2F with developers)
Q1. Design a snake and ladder game

64
Chapter 15. Set 14

Q2. Given a linked list contains even and odd numbers. separate the list into two lists
contains odd/even numbers.
Q3. Given a 2D matrix which contains 0’s and 1’s. Given two points of matrix whose value
is 1. Find the path(with only 1’s) between the given points
Round 5 (F2F with Senior Manager)
Project related questions
Challenging tasks done so far
Q1. Given a large file which contains m rows and n columns. Given a column no, sort the
column in such a way that corresponding rows also sorted
Round 6 (F2F with Developers)
Q1. Print all pairs(sets) of prime numbers (p,q) such that p*q <= n, where n is given
number
Q2. Given a binary tree, if parent is 0, then left child is 0 and right child is 1. if parent is
1, then left child is 1 and right child is 0. Root of the tree is 0. Find the kth node value
which is present at Nth level
Q3. Longest monotonically increasing sequence in O(NlogN)
I couldn’t make it. Hope it helps someone else.

All Practice Problems for Amazon !


Pairs of prime number
Student record

Source

https://www.geeksforgeeks.org/amazon-interview-set-14-2/

65
Chapter 16

Set 15

Amazon Interview | Set 15 - GeeksforGeeks


For the position SDE I.
I had an online test through interviewstreet and following were the questions:
https://www.geeksforgeeks.org/inorder-successor-in-binary-search-tree/
https://www.geeksforgeeks.org/print-nodes-at-k-distance-from-root/
https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
F2F Interview :
1. Generate all valid permutations using ‘(‘ and ‘)’. Valid permutation is the general
definition of valid sequence of the opening and closing brackets.
I told him a solution where we would generate a combination using a recursive solution and
prune the cases where a valid combination is no longer possible. The solution was fine and
not that difficult. But the interviewer was very interested in knowing if I can calculate the
complexity of the solution. He gave me some hints but it was just not striking me. I told
him my approximate answer. We moved on.
2. Create an ancestor matrix for a tree.
The solution would seem simple. But since the matrix is N*N, the interviewer wanted some
tricks to reduce the complexity of the write operation on the matrix.
I told him a solution where you can initialize the matrix with all zeros and only write 1 for
the ancestor cell using a modifies recursive solution and linkedlist.
He was fine with the solution
F2F 2:
1. Find the maximum weight node in a tree if each node is the sum of the weights all the
nodes under it. Obviously tree nodes can have negative weights.
2. Kadane’s algo
F2F 3:

66
Chapter 16. Set 15

1. Find the diameter of a tree.


2. Link every node of a level to the the next node at the same level

eg:
Tree is:
1
2 3
4 5 6 7
would become:
1
2-->3
4--->5--->6--->7

3. Find the first subarray which has a zero sum in an array


F2F 4:
Detailed discussion on projects I did in college and about my interests.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-13-2/

67
Chapter 17

Set 16

Amazon Interview | Set 16 - GeeksforGeeks


I recently appeared for amazon which came to our campus. Here is my experience.
Shortlisting Round.
There were 20 MCQ and 2 programming questions. Each correct answer carried 1 mark and
-0.25 for a wrong answer. Programming questions were:
a. Given a number with the number of digits in the range of 10-50, find the next higher
permutation of the number. If such a number doesn’t exist, return -1.
b. Given an array of strings, you need to find the longest running sequence of a character
among all possible permutations of the strings in the array.
INPUT:
ab
ba
aac
OUTPUT:
a,3
Then there were 4 rounds of interview.
T1
a. Given link list segregate odd elements first and even elements afterwards.
b. Given a BST of memory sizes. Find best fit for a memory block of size M.
T2.
a. Given 2 sorted arrays of size m and n+m(with n elements) , merge
them into the latter..
b. Given a character array find the first element that repeats itself.
T3.
a. Given a binary tree connect all nodes in a level through link list.
b. Some question related to share market which boiled down to find maximum difference
between two elements such that second element appears after the first one.

68
Chapter 17. Set 16

c. What is thrashing ?
d. Real world application of heaps?
e. Minimum spanning tree and topological sort .
T4.
Around half an hour HR then
Given a function node* inplacemergesort(node* n1, node* n2) which takes 2 linked lists as
input and performs in-place merge sort and returns the final list. How will you test it and
make sure it does what it claims.
I was hired � .
The interviewers were very friendly, patient and looked for optimal solution to each question
.
I am very thankful to geeksforgeeks for such a great site and the way its maintained.It really
helped me a lot for my preparation. Keep up the good work guys �
Thanks.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-16/

69
Chapter 18

Set 17

Amazon Interview | Set 17 - GeeksforGeeks


Online Written round :
5 programming questions. You have to answer within 2 hours.
1. Swap two nodes in a linked list
2. Find kth smallest element in a binary search tree
3. Longest increasing subsequence in an array
4. One DP program
Face to face interviews:
1st round :
1. Find whether given tree is BST or not
2. Boundary traversal of a tree
3. Print the border nodes of the tree
2nd round:
1. There are n number of points in a two dimensional plane. Find two nearest points
2. There are n number of points in a two dimensional plane . Given a point find k nearest
points to it.
3rd round:
1. Given a matrix with random numbers in it , If a location has 1, make all the elements of
that row and column as 1
2. Given a matrix, find whether you can form the given number in
4th round:
1. Write a program to list all the possible words from the given set of data in the same
order. ( eg : given word : nokiamobile O/P : nokia mobile : given word : samsung O/P : 1.
SAMSUNG 2.SAM SUNG(considering sam as a word) )
2. Given two trees , find whether they are from same set of dataset or not.
3. Thread pool implementation.
All Practice Problems for Amazon !

70
Chapter 18. Set 17

Source

https://www.geeksforgeeks.org/amazon-interview-set-17/

71
Chapter 19

Set 18

Amazon Interview | Set 18 - GeeksforGeeks


Amazon visited our campus on 16,17 and 18 Dec.
WRITTEN ROUND(1.5 hrs)
20 MCQ + 2 CODE
MCQ- mainly Aptitude, C-output questions, OS- unix related and DBMS
CODE-
…1) Binary complement of a number.
…2) Easy question related to bets
42 out of around 200 students were shortlisted after this round..
ROUND 1:
Around 15 min discussion on my image processing project
Finding an element in rotated sorted array..
12 students were shortlisted after this round
ROUND 2:
1) Convert postfix to infix in which the result must be having minimum number of braces
i.e apply braces whenever necessary.
2) Given a binary tree print the sum of elements on same axis (for all axis).
Elements on same axis are for e.g.: root, root->right->left, root->left->right
3) Design hash table with following operations you are given with a good hashing function..:
insert() –O(1)
find()-O(1)
delete()-O(1)
traverse()-O(n)..(where n is the number of elements in hash not the size of hash)
4) Given an array find a sub-array with sum=0
5)

for(i=0;i<n;i++)

72
Chapter 19. Set 18

 for(j=0;j<n;j++)
   cout<<a[i][j];
  
for(i=0;i<n;i++)
  for(j=0;j<n;j++)
   cout<<a[i][j];

out of these 2 which one will be better


I was asked to write the complete code for all the questions.
6 students were shortlisted after this round
ROUND 3:
1) Given memory in the form of chunks if one process is reading any chunk, then any other
process is not allowed to write but it can read, if write lock is on, then any other process is
not allowed to read or write, now process can have lock on any number of chunks (continues)
and other process requesting read or write can even request for memory that does not have
the same starting address as the process who has locked the continues chunk memory.
Now we have to design a DS for representing memory and then design isRead() and
isWrite()which will return Boolean values true-if read/write can be performed vice versa.
2) Permutation of a string with and without repetition of characters.
3) Given an array of numbers if we start deleting numbers from end of array, then we have
to tell the maximum element of the array after deletion in O(1).
I was asked to code all the questions.
4 students were shortlisted after this round.
ROUND 4:
1) Around half hour discussion on my intern project which was with an e-commerce company.
2) Given a linked list with one extra arbit pointer we I was asked to make copy of linked
list..
https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
he asked me to write the full code for method 1 in the above link.
In the end 3 students were hired and I was one of them.. �
I am very thankful to geeksforgeeks It really helped me a lot for my preparation. Keep up
the good work guys
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-18/

73
Chapter 20

Set 19

Amazon Interview | Set 19 - GeeksforGeeks


I recently had a set of interviews with Amazon.com and listing below the questions. The
day had around 15-20 of us at their office and the whole process took close to 12 hrs.
Hope, people can reap benefit from it. �
1st Round: Online Written round.
a. Determine if a matrix is a cross-matrix.
A cross-matrix is a one in which all the diagonal elements are same and not repeated
anywhere else.
b. Print the level-order in reverse order, i.e. from Bottom to top.
c. One more easy question, which I don’t remember now.
2nd Round: F2F- Developer
a. Kadane’s Algo.
However, it was hidden behind a good problem set.
Interviewer wanted to identify whether I can recognize the same.
I did not remember it instantly but was able to prove it by solving.
b. Linked-list intersection point.
Again, had to decipher the above from a different problem set.
[A tree with only parent pointer, how to find LCA?]
Was able to easily identify the same and we quickly moved onto other things.
3rd Round : Hiring Manager
a. Design a stack which can perform findMax in O(1).
Had read the answer once in some book and duly told him have heard it.
He verified and we moved on.

74
Chapter 20. Set 19

b. Set of stocks for each day have been given. Need to find the days on which I buy and
sell share to earn max profit, alongwith finding the max profit.
Had to write the code, which I was able to do well.
He was impressed and I felt I had a good chance.
4th Round : Developer
a. Find top k searched elements from a continuous stream of data.
I remember we needed to use Min Heap but his constraint was using a continuous stream.
Finally was able to do it with his help.
b. Some design question based upon his team’s problems.
Had to use a queue and a hashmap to solve it.
He was very much interested in whether I could identify the complexities correctly.
5th Round : Manager – Different Team
a. Given a linked-list and 2 integers k & m. Reverse the linked-list till k elements and then
traverse till m elements and repeat.
Write production quality code.
I am not sure what happened and why I fell off on such an easy question, but you just can
do something like that in the last round.
b. An array of elements have been given. Find for each element, first max element to its
right.
Was able to do it well, however lost it on complexity analysis.
c. Boundary traversal of a tree. Write the code.
Wrote the code, however he was not able to check the same as took a lot of time.

Before this round, I had good hope of getting selected, but no one can give such a bad last
interview and get selected and hence after 2 weeks got a rejection mail.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-19/

75
Chapter 21

Set 20

Amazon Interview | Set 20 - GeeksforGeeks


Recently got interviewed with amazon Hyderabad for SDE1.
Written
1) Given a BST, along with left and right pointer for a node, it has forward and backward
pointers, convert the tree into Doubly linked list using these extra pointers.
2) A = {5, 3, 8, 9, 16}
After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
Given an array, return sum after n iterations
3) Write a function which compress string AAACCCBBD to A3C3B2D
and other function to generate from the compressed.
First f2f)
1) Check given BT is BST
2) The cost of a stock on each day is given in an array, find the max profit that you can
make by buying and selling in those days
3) In matrix A[m][n] each row is sorted and each column is sorted, write a function which
checks whether a number exists in this matrix or not.
4) Given a string, find the longest sub sequence which contains only unique characters.
Second -f2f)
1) Convert a BT into SUM BT(each node values = sum of left and right node)
2) “I get thousands of emails daily”, find all anagrams in each email and print the count of
all anagrams in each email.
My solution was using a trie and a hash function to increase the counter at each node in
the trie.
Hash function will return the given word in a sorted manner, he asked me to code which
was tedious but gave a rough draft.

76
Chapter 21. Set 20

Initial set up cost would be big but the same trie can be used for any email by making all
counters to zero.
Third f2f)
1) He talked almost for 45 min regarding my project and asked how we implement it. I was
also working on web services in my current company, so they were more interested in asking
questions there and want to know how well I implemented there.
2) A design question of chess int board[8][8] each value in the matrix represents a character.
1-9 number represents all whites and 11-19 represents all blacks.
Given a pawn at (x,y) print all possible moves. Assume whites are index 0 and blacks are
at index 7.
Fourth f2f)
1) There is ternary tree in two dimension space(one plane). Print all elements that are
visible from right side of the plane(If you see along y axis plane)
eg) In the following answer would be (1) (5) (8)
————————(1)—————————————
—————-(2)–(3)–(4)–(5)——————————
———-(6)–(7)–(8)—————————————–
2) Print these elements in a zig zag order, first level1 and then level n, level 2 and level n-1
and so on.
In simpler words print rightmost ending element in each level of a ternary tree.
My approach was take two queues, enqueue root in Q1 and while dequeueing enqueue its
childeren in Q2, while shuffling elements from one queue to another store the last element
in doubly linked list.
While printing, use this double linked list, remove from head and then tail, till it becomes
empty.
Fifth f2f)
1) Find jth element in ith row of a pascal triangle
1
1 1
1 21
1 331
1 4 6 4 1… and son on. pascal(4,2) should return 6.

pascal(int i , int j){


if(i<0||j<0) return 0;
if(i==0 &&j==0) return 1;
if(i==0 && j!=0) return 0;
return pascal(i-1,j-1)+pascal(i-1,j);
}

complexity is bad and I am not grouping the solution once calculated of sub problems
2) Implement your own hash function with keys as strings and values is of type Object
initially I told BST with insertion deletion of order log(n), then he told me to think and
answer then I told self balancing BST and he asked me to implement,

77
Chapter 21. Set 20

3) Evaluate a mathematical expression 2*3+(5-6/2), something like this, with operator


priority.
Each f2f interview will be of 50-60 min. In each f2f round they will ask reason for change,
and about your current project. You should answer perfectly regarding your current project
and don’t blabber something and all, they will ask good questions in the current project as
well.
These questions might take up more than 15-20 min and in the rest of the time you have to
answer 2 question in DS for minimum and code them as well.
If you answer you will get one more question which is an advantage �
First he will explain the question and gives you sometime.
You need to explain the solution first, if he likes it, then he will asks you to write production
code and takes the paper.
Each interview is not like a level in amazon, they won’t share feedback neither with you nor
with other interviewers.
After the interview process is done all those who took your interview will sit and judge
(That’s what HR told me � )
All the interviewers were friendly, finally I got a call from HR saying that I was selected �
Thanks to Geek4Geeks �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-20/

78
Chapter 22

Set 21

Amazon Interview | Set 21 - GeeksforGeeks


Recently I have gone through 10 rounds of interviews of my dream company Amazon for
SDE1 and I got selected. My only resource and library for preparation was GeeksforGeeks,
which is the best website for tech preparation, if you aim for big shots like Amazon, Microsoft,
etc. I was not too confident to attend interviews. The interview experiences blog gave me
courage and coding experience to crack all rounds. Please do follow this site for every
update, and suggest your friends to follow if they try for job change and if they aim for big
companies.
I am sharing my interview experience, which will help others.
Total rounds : 10
1 online written test + 4 telephonic + 5 F2F screening rounds.
In F2F rounds, for every problem complete executable code + algorithm will be expected.
In all rounds , best solution will be expected (with less complexity)
Online Written Test:
1. Find maximum frequent numbers in an array. If there are more numbers with maximum
frequency, they display all numbers in ascending order. Ascending order is important.
2. Two numbers represented as linked lists. (Bigger than integers). Return a linked list
which is the product of the given two linked lists.
1->2->3->Null (123)
2->3-Null (23)
O/P: 2->8->2->9->Null
1st Phone Screening (45min):
1. Find a linked list has circle in it, If it has loop, find origin of the loop.
2. In Linked list, Node has two pointers, one points to next node, other points to arbitrary
node in the linked list. Write a function to return a new list which is clone of the given
linked list.
3. An array is sorted and rotated by k times. Find an element in an array. (efficient and
logarithmic time solution is expected)

79
Chapter 22. Set 21

2nd Phone Screening(45min):


1. Two strings s1,s2 are given as input. Remove characters present in s1 which are there in
s2.
2. How to find number of subsets in a set.
3. Searching an element in 2D matrix which is sorted in row wise and column wise.
1234
2345
3456
4567
5 6 7 8 Find an element in it.
4. Difference between merge sort and quick sort. How do you improve quicksort (think
about in selecting pivot element).
5. Give a scenario for quick sort in worst case.
6. How to store a set in memory, what ADTs do we use and what are tradeoffs for each
ADT.
3rd Phone Screening(35min):
1. N-Petrol bunk problem: There are n petrol bunks located in a circle. We have a truck
which runs 1 km per 1 liter (mileage 1kmpl). Two arrays are given. The distances between
petrol bunks are given in one array. Other array contains the no of liters available at each
petrol bunk. We have to find the starting point such that if we start at that point , you we
would able to visit entire circle without running out of fuel. Initially truck has no fuel.
2. Reverse linked list in groups of size k.
I/P: 1->2->3->4->5->6->7->8->Null k = 3
O/P: 3->2->1->6->5->4->8->7->Null
4th Round(35min):
1. Algorithm to construct a tree given Pre and In order traversals.
2. Inorder successor of a tree.
3. Threaded binary tree(inorder without recursion)
F2F Round 1 (with Hiring manager 60+ min):
1. Tell me about yourself and Projects you worked.
2. About the most critical situation in the project you went through. How you did it. ( he
needs complete explanation of the scenario)
3. If he gives the same scenario as an interview question, how will you improve code quality
and its complexity.
4. About SDLC you followed. Which one do you like and why.
5. Do you have any questions to ask ( very important one- ask something about projects
they work, etc. Good sign )
F2F Round 2 (with Developer 60 min):
1. Tell me about yourself.

80
Chapter 22. Set 21

2. Zigzag traversal of binary tree. (more optimal solution is expected from you).Complete
code should be written and they will check later.
3. A robot is there in 2D space, which can move to its left direction. You are given with an
array which are moves of robot, which starts from origin(0,0). Find the rectangle covered
by it.
I/P: { 2,3,4,5,6,1,3,5,5} starts at (0,0)
O/P: rectangle points: ( -4,4 ) to (4,-2)
4. Casual discussion about hiring process.
F2F Round 3 (with Developer 50min):
1. Data structure which does insertion, deleting latest item, find min, find max in O(1) time.
(Gave hash, 2-D, linked list, many .. He impressed lot here)
2. Vertical sum of a tree. (Column wise sum – can find same one in geeksforgeeks)
3. Find n-th digit in the continues sorted stream of data.
I/P: {1,2,3,4,5,6,7,8,9,1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8……… infinite} n =28
O/P: 28th digit
Complexity analysis of all the above.
F2F Round 4 (with Developer 45 min):
1. Print matrix spirally.
12345
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
O/P: 1 2 3 4 5 10 15 20 25 24 23 22 21 16 11 6 6 8 9 14 19 18 17 12 13 18
2. Write a function to check syntax of opening and closing braces whether they are proper
or not.
3. Same question if you have k types of braces( ‘(‘ ‘[‘ ‘{‘ ,…. K types) All are of same
priority.
4. Same question if you have k types of braces( ‘(‘ ‘[‘ ‘{‘ ,…. K types) All are of diff priority.
5. Print all valid combinations of k number of pairs of braces.
6. Return count of above combinations without using algorithm for printing them.
7. Memoziation –do you know about it. Explain me.
F2F Round5 (Bar Raiser round) 60min:
1. Leader ship principles followed by Amazon
2. About project.
3. Why you are leaving prev company, What will stop you there.
4. Set of strings are given in a dictionary order. The problem here is order is not as our
alphabetical. It may be different. C may come before a,b, x may come before d,c. etc. You
will have to find the order of characters by using given input. (topological sort – complete
code is required to write)

81
Chapter 22. Set 21

5. Binary search tree into Sorted doubly linked list (Expected Inplace algorithm)
Things to keep in mind:
1.For every problem, give one simple solution first (may have more time complexity) and
think for optimal solution.
2.Write a code in clear manner. It should be understandable without your explanation.
3.In a position to tell complexity for code you are going to write.
4.First tell the algorithm or approach and proceed with writing code.
5.Do not hesitate to ask for clarification. They will impress.
That’s all from my side. Best of luck.
Thanks again for GeeksforGeeks, a lovable website for techies.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-21/

82
Chapter 23

Set 22

Amazon Interview | Set 22 - GeeksforGeeks


I was recently interviewed for SDE1 position in Amazon Bangalore. 1 online
coding test followed by 5 rounds of F2F onsite interviews.
Online Coding Test (4 Problems, 2 hours) From Interviewstreet
All below problems had multiple test cases for which the code was validated against.
1. Code for converting floating point decimal number to binary numbers. If the number
cannot be converted, state so.
2. Given an integer array A of size n. Given an integer k < n. Construct an array B, such
that B[i] = min{A[i], A[i+1], A[i+2], A[i+3], ……., A[i+k]} Solve in time complexity better
than O(nk). Hint: use min Heaps 3. A singly liked list. Can have a loop. Detect it and
find the size of list.
4. 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.
Sample Input: 1->2->3->4->5->6->7->8 and K = 3
Sample Output : 1->2->6->4->5->3->7->8
Sample Input: 1->2->3->4->5->6->7->8 and K = 10
Sample Output: print error “LIST IS OF LESSER SIZE”.
Face to face: Round 1(Technical, 1 hour):
1. Given a binary search tree. Find two numbers in the tree whose sum is k. If there are
no such elements, state so. Assume that the tree is balanced.
O(n) solution with O(logn) space was expected. Solved using two stacks. Code was required.
2. Copy a linked list with next and random pointer. Not allowed to modify the given list
at any time. Only read privilege on the given list.
Face to face: Round 2(Technical, 1 hour):
1. Given a matrix mxn containing integers. Find a kxk submatrix which has the largest
sum.
Solved using prefix sum matrix.
2. Given an n-ary tree. Traverse it in zig-zag manner. Code was required.
Solved using a Queue and a dummy node for level info.

83
Chapter 23. Set 22

Face to face: Round 3(Technical, 1 hour 20 minutes):


1. Given N buckets each of capacity 1L numbered from 1 to N. Buckets are arranged in a
form of a 2D Pyramid shown below.

1
2 3
4 5 6
7 8 9 10

No each bucket is resting on 2 buckets. I will add water in the top bucket(number 1), after
filling the bucket completely access of water will spill to the left and right bucket. Need to
write a function which will return water in nth bucket after I will add x L of water in bucket
number 1.
float getWaterInBucket(float x, int n);
2. Given an mxn matrix. Each entry is a room. Rooms containing “L” are locked. No one
can enter a locked room. Rooms with “G” are guarded rooms. Distance of a room from a
Guard is defined as the minimum number of rooms that are encountered for the Guard to
reach that room (Guard can move in all allowed 4 directions at max). Find the room that
is farthest from all guards. Expected time was O(mn). (Hint: BFS)

Face to face: Round 4(Manager, 1 hour 20 minutes):


1. Tell me about yourself.
2. Why do you wish to move out of current job?
3. Explain in detail the current project. Intention was to understand whether I had good
depth of knowledge of the project and team I was working in.(Nearly 30-40 minutes of
discussion)
4. How big is the team & what is your role?
5. Proudest project that I have worked in my current company. Details.
6. Any instances where you are not satisfied with what you did?
7. Any instances that you felt the need for improvement in some areas, which could have
helped you technically and professionally. Any negative feedbacks.
8. What happens when you type in a URL on browser?

84
Chapter 23. Set 22

9. Given a binary tree with parent pointer only. Given pointers to two nodes in the tree,
find the LCS(Least Common Ancestor). Quality Code was required with proper handling
of boundary cases.
10. Object oriented design of ‘Snake and Ladder Game’. Was asked to propose classes,
inheritance and reasoning behind it.
Face to face: Round 5(Manager, 1 hour 10 minutes):
1. Tell me about yourself. It starts with a basic intro round, where your communication
skills are judged.
2. Why changing the job?
3. Explain in detail the current project. In depth information.
4. Given a binary tree. Tell if all the leaves are at the same level. Code was required with
proper handling of boundary cases.
5. Discussed how the stock market works. Reached to:
Design a data structure for storing the stock prices of various stocks. Make design such that
update (new entry addition) of prices can be done efficiently. Also, it should be efficient
to answer the queries like, “Maximum/minimum of stock prices of stocks s1, s2, s3 in the
month of November 2012 etc.”
Four days later I was informed that I was selected �
Following materials I used for preparation.
1. GeeksforGeeks
2. Careercup
3. Introduction to Algorithms(Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest,
and Clifford Stein)
4. Algorithm Design [Jon Kleinberg, Éva Tardos]
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-22/

85
Chapter 24

Set 23

Amazon Interview | Set 23 - GeeksforGeeks


I was recently interviewed for SDE1 position in Amazon Bangalore. 1 online
coding test followed by 5 rounds of F2F onsite interviews.
Online Coding Test (4 Problems, 2 hours) From Interviewstreet
All below problems had multiple test cases for which the code was validated against.
1. Code for converting floating point decimal number to binary numbers. If the number
cannot be converted, state so.
2. Given an integer array A of size n. Given an integer k < n. Construct an array B, such
that
B[i] = min{A[i], A[i+1], A[i+2], A[i+3], ……., A[i+k]}
Solve in time complexity better than O(nk).
Hint: use min Heaps
3. A singly liked list. Can have a loop. Detect it and find the size of list.
4. 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.
Sample Input: 1->2->3->4->5->6->7->8 and K = 3
Sample Output : 1->2->6->4->5->3->7->8
Sample Input: 1->2->3->4->5->6->7->8 and K = 10
Sample Output: print error “LIST IS OF LESSER SIZE”.
Face to face: Round 1(Technical, 1 hour):
1. Given a K sorted array. Sort it with minimum time complexity.
O(nlogk) solution was expected. Code was required.
2. Given a file with many product name of an company. You have to find out unique name
in the file. Suppose mobile,laptop,notepad,desktop,pen,mobile,pen .. etc is given we have to
print laptop,notepad,desktop. Pen and mobile should be remove due to duplicity.
Code was required.I gave o(n) time complexity solution for it using 1 hash table and Doubly
Link List.
Face to face: Round 2(Technical, 1 hour):
1. Given a Sorted array with one missing number. I have to find first missing number.Code

86
Chapter 24. Set 23

was required. I gave solution with o(logn) time complexity.


2. Give a Building with n floor. A person can take 1 step or 2 step to climb. Find the
number of ways to reach nth floor. Code was required
Face to face: Round 3(Technical, 1 hour 20 minutes):
1. Given an Sorted Array with duplicates I have to find first index of any duplicates. Suppose
12222333355578999 first Index of 2 in 1. Code was required.I gave O(logn) Solution.
2. Given an binary tree. Traverse it in zig-zag manner. Code was required.Solved using a
2 stack.
3. In a snake ladder game without snake and ladder :). If some one is playing then we have
to find probability to win the game of any player. Condition of winning is if you are on 96
and 5 comes in dice then you loose the game and If you are at 96 and 4 comes then only
you will win the game. But you cant use dice more than Y time.
I gave o(XY) Solution through DP. Where X is sum.
Interviewer was very happy after that.
Face to face: Round 4(Manager, 1 hour 20 minutes):
1. Tell me about yourself.
2. Why do you wish to move out of current job?
3. Explain in detail the current project. Intention was to understand whether I had good
depth of knowledge of the project and team I was working in.
4. How big is the team & what is your role?
5. Proudest project that I have worked in my current company. Details.
6. Any instances where you are not satisfied with what you did?
7. Any instances that you felt the need for improvement in some areas, which could have
helped you technically and professionally. Any negative feedbacks.
9. Write the code to store Binary Search Tree in Doubly Link list. Code was required.
10. Petrol and distance problem given in Geeks for Geeks. http://www.geeksforgeeks.org/find-
a-tour-that-visits-all-stations/
Face to face: Round 5(Manager, 1 hour 10 minutes):
1. Tell me about yourself. It starts with a basic intro round, where your communication
skills are judged.
2. Why changing the job?
3. Explain in detail the current project. In depth information.
4. What will you do if your module is dependent on some one else and you are stuck due
to him. I told him to that I will create stub ( Template of desire data using edge case
conditions)
5. Write the full code of finding a Name and phone in simple phone(In which abc all come
on 1 using pressing speed and time duration) using sub string of name. I gave 2 solution
1 using suffix tree and 2 using hash table and KMP Algorithm. He told me to write full
code of this problem using hash table and KMP Algorithm. I wrote the full and Manager
was satisfied with my answer.
Three days later I was informed that I was not selected. With below mail :-
Thanks for your interest in Amazon. We appreciate you sparing time towards discussions
with us. After the detailed discussions with you and internal discussions thereafter, we regret

87
Chapter 24. Set 23

that we do not have a suitable opening at present that does justice to your aspirations and
capabilities. Hence we would not be able to take it forward at this juncture.
With your permission, we will retain your details in our database and would get in touch
with you, should there be a suitable opening in future.
Wish you all the best in your endeavors.
I am still not able to find the correct reason behind it. And Now I am frustrated.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-23/

88
Chapter 25

Set 24

Amazon Interview | Set 24 - GeeksforGeeks


Hello Guys, I had 6 rounds(written + telephonic+ 4f2f interviews) in hyderabad centre of
Amazon.
I was 90% sure that I would clear the interview but I got rejected. The only reason I felt
I was rejected was that the interview process was immature. The interviewer interviewing
was a guy with 1yr of work ex expecting solution in the manner he wanted, which was pretty
unexpected from a technology giant like amazon.
Every round of Amazon would have basic question like what you do etc. But all that is just
formality, it doesn’t count since one interviewer stopped me in between and said we have
less time lets talk about problem solving(Which was again not expected from technology
giant)
Also, for those writing written this month, the written round would have the same questions
as I have listed below. So please solve this, before going for written
Anyways, these were my questions:
Written(Interview street) – 3 Questions:
a) General code for coin denomination problem where the input was an array containing
the coin denomination and the sum we want.
b) Rectangle overlap problem(Can be found in geeksforgeeks)
c) String Matching Problem(Wrote KMP)
Telephonic Interview:
a) Convert BST in place into doubly linked list
b) Given a Binary Tree is it a BST
If you miss one edge case, you are out of the interview. This is what they check and nothing
else. They don’t check your logic, they only see if you write proper code. So always start
with brute force and write proper code.

89
Chapter 25. Set 24

F2f interview(1st round) – Very easy


a) Given a number is it divisible by 3 and 5
– Only catch here were the edge cases and nothing else
b) angle between hour hand and minute hand
c) Revere bits in a binary
d) Get the kth node from end of linked list
F2f inteview(round2)
a) It was basically on writing multi-threading code(Write multi-threaded code for Enqueue
of Queue using linked list)
b) Asked about basic complexities in Queue, hash and tree
c) Window Problem(In an array, find the minimum of the set in a given window). There are
many solutions using hash, brute force. But the dequeue answer is what he was expecting.
I gave the deque answer
Any other answer to this problem was a reject
F2F Interview(Round -3)
a) Given a doubly linked linked, delete the occurrences of duplicate element from it. ( One
miss of edge case and out again)
(for eg) If you write, temp->prev->next = temp->next without actually adding the condi-
tion, if(temp->prev) then temp->prev->next = temp->next
b) Given a matrix with ordered rows and columns(Rows are sorted 0’s followed by 1’s). Find
the row with maximum 0?s(linear time)
I answered it
c) DataStructure with Insert O(1), Deletion O(1) Search O(1) and ReturnAnyElement O(1)
Again answered this using augment of hash and doubly linked list
d) Given a tree with negative and positive numbers, return the root with maximum sum in
its sub-tree
F2f interview(round-4)
a) It was basically a design interview where I was told to some OOPS design
b) Given a stream of 0’s and 1’s(You Tube). Find the first occurrence of 1 in it. Then the
question was changed to a string instead of a stream.
Finally, after giving 100% it was reject. So according to my experience, if you dont give
100% you are out or else it is ur luck that you get through amazon’s process.
Moreover, currently they have started exploring candidates by sending two interviewers
which actually means that the one is new to interviewing and other is experienced. Hence,
basically they are playing with interviewers.
If you want the answers for questions, please comment I will post it.
All Practice Problems for Amazon !

90
Chapter 25. Set 24

Source

https://www.geeksforgeeks.org/amazon-interview-set-24/

91
Chapter 26

Set 25

Amazon Interview | Set 25 - GeeksforGeeks


Hi, This is Pandu. About 1 month back I had attended Amazon Interview In hyderabad, it
was total of 8 rounds which includes 2 telephonic and 6 face to face and the whole process
was lasted about 25 days because of unavailability of all the interviewers. The whole was
very painful for me as before and after attending interviews on each interviewing day, I had
to spend with some tension & anxiety. I was interviewed for SDE 2 position
The following are the questions:( For all the algorithmic questions , working code is required,
they would take those papers and discuss in their internal meeting after all the rounds)
Telephonic Round 1(with Lead developer):
Q1)Given a snake and ladder game, write a function that returns the minimum number of
jumps to take top or destination position.
You can assume the die you throws results in always favor of you.
Telephonic Round 2(with SDE 1): ( after 5 days of 1st telephonic)
Q1)Given an integer array and an integer value X, return two elements in that array such
that sum of them equals to X.
– Here he asked about different ways to solve it and pros and cons of each solution.
(For Hash map solution , He was looking for getting solution in only one pass)
Q2)discussion about my project details and challenging task
Q3) suddenly you web application has become very slow on clicking particular URL. How
would you debug it and solve the problem
Face to Face round 1(with SDE 1): (after 4 days of 2nd telephonic. 3 faces to face
rounds were taken on same day and lasted about 5 hours)
Q1) Given a sorted array and a number write a method that returns the number of occu-
rances of given number
Q2) You have given a dictionary of an alien language in which letters are same as English
letters but their order is different.
Your task is sort the letters or give relationship b/w letters using that disctionary. note:
the dictions may conatain 1 to n words.

92
Chapter 26. Set 25

Face to Face Round 2(with SDE 2):


Q1) In our project we are using Java Spring framework. He asked to implement spring
container.
Q2) Implement LRU caching. After that asked me two different cases (1) required element
is already in chase , 2) required element in not in cache and cache is full)
Had to explain those two cases by walking through your code.
Q3) You are given a faulty binary serach tree in which only 2 nodes are misplaced(swapped
their positions with each other). write a method
that takes root of that BST and return the root of the corrected binary tree.
Face to Face Round 3 (With Lead Developer) : (Design question)
Q1) Given an URL you need to analyze all the images( they may be in 1000’s of number)
and return the cumulative quality of images present in that url.
lets say: you can configure image quality as very good,good, average, poor..etc, so you have
to return one value among them. The given URL may conatain several othe URLs and they
also conatain lot of images . you need to consider all of them. lot of questions like how to
avoid visiting same url again,
how would you determine the quality of an image if you encounter an url that contains only
an image..etc.
Q2) Design Elevator system. And then write an algorithm for that Design such that, the
user request should be completed in logN time in a N story building with M elevators,
This round was lasted more than 2 hours.
Face to Face Round 4 ( With Hiring Manager): ( after 5 days of last 3 f2f
rounds)
Q1)Discussion about my project details
Q2) Design Question: Design Clustered caching system for an web site like Amazon.com.
In which millions of web servers deployed over the globe and only one inventory Database
system
Q3) Design question: Design only Train search functionality of IRCTC
Face to Face Round 5 (With Bar Raiser): ( same day following Hiring manager
interview)
Q1) Discussion about my project and Challenging task
Q2) Design Question: In an online teaching system,there are n number of teachers and each
one teaches only one subject to any number of students.
And a student can join to any number of teachers to learn those subjects.
And each student can give one preference throuch which he can get updates about the
subject or class timings etc.
Those preferences can be through SMS or twitter/facebook or email..etc.
Design above system and draw the diagram for above.
Q3) coding and algorithm: There is a N-ary tree in the 3d Space. and you are standing on
right side of that tree . Print the only
those nodes when you looked at that tree.
( which is like printing rightmost node in each level of that tree. He would not tell this, you
have to conclude this by drawing a tree like that).
After writing the code for above one, he was asked me to print them in an order in which
1st one followed be last one followed by 2nd first one followed by snd last one..etc.)
Face to Face Round 6(some one who is in very high level, guess director to a

93
Chapter 26. Set 25

technology):
(After 1 week of last interview)
Q1) Lots of discussion on my current project. Different behavioral questions were asked
during the discussion.( about half n hour discussion)
Q2) Given a cube of size N. which was constructed by N^3 number of 1 unit smaller white
cubes. Now you dipped that cube in a black color paint and taken out.
after that how many cubes are still in white color. Prove your answer( by writing mathe-
matical equations)
Q3) There are N bolts each of which different size and N nuts, they are also with different
sizes. and each bolt fits with exactly 1 nut.
Give an algorithm that combines those N bolts and nuts into N pairs of Matched bolt and
nut.
HR told me on last interview day that I would be notified by the result within two working
days as already the whole process was delayed for so many days. I had waited for almost 1
week and send them mails & called them about my candidature but did not get any response.
I was almost lost hope. But, Finally after 8 days of last interview, got a call that I was
offered SDE1..( I guess, They were not completely satisfied by in design part but I did better
in algos, problem solving and coding part and as a result I was offered SDE 1). In the end
I rejected to join at Amazon as I got another competitive offer.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-25/

94
Chapter 27

Set 26

Amazon Interview | Set 26 - GeeksforGeeks


Hi, I am Mayur Kale,I was recently interviewed for SDE1 position for Amazon in our campus
and got selected. Geeksforgeeks helped me lot. I prepared only from Geeksforgeeks.org. I
am very thankful to Geeksforgeeks team.
Onw online coding test followed by 4 rounds of F2F interviews.
Online Coding Test (2 Problems,20 MCQs, 1:30 hours) From Interviewstreet
All problems had multiple test cases for which the code was validated against.
1. from input string we have to print character which occurs maximum number of times.
Face to face: Round 1(Technical, 1 hour):
1. Given a boolean matrix mat[M][N] of size M X N, modify it such that if a matrix cell
mat[i][j] is 1 (or true) then make all the cells of ith row and jth column as 1 (time complexity
expected was O(M*N) and space O(1))
Solution: https://www.geeksforgeeks.org/a-boolean-matrix-question/
2. Given binary tree, if we draw a line from root then we have to print all nodes on that
line.
Code for both questions was required and some other discussion happened..
Face to face: Round 2(Technical, 1 hour):
1. Given string we have insert %20 on each space and input string has enough memory to
contain output string.
(time complexity expected was O(n) and space was O(1).
2.merge point of linked list.
(I told I know this question so he moved ahead..)
3.Given binary search tree in array form and we have to check whether it is fully binary tree
or not..
(I gave O(n^2) solution but He was expecting O(n) solution after some discussion I managed
to give answer in O(n) complexity…)
4. Given that integers are read from a data stream. We have to find k maximum elements

95
Chapter 27. Set 26

from that stream…


(I gave solution of insertion sort,then come to heap)
code for all questions required and nice discussion was there…
He was very impressed with my answers…
Face to face: Round 3(Technical, 1 hour 20 minutes):
-He asked me to choose topic on which questions should ask..
I chose OS…
-some questions on paging and virtual memory.
-If we use 8 GB RAM for 32 bit machine what will happen?
It was nice question..
He was very impressed with answer.
-Some discussion on Networking(DHCP and DNS).
-Some discussion on Linker and Loader.
-Some discussion on JAVA.
-Some discussion on DBMS.
-one puzzle
A champagne pyramid is a pyramid made of champagne glasses , each of equal capacity say
, n. The pyramid begins with one glass at the top level , two glasses at the second level ,
then three below that and so on up to infinite levels. A level x of the pyramid thus has x
no. of champagne glasses.
A steady stream of champagne is poured down from the top level,which trickles down to the
lower levels. What is the distribution of champagne in the glasses at a given level i.
(I told I know this puzzle then he moved ahead..)
-Give a Building with n floor. A person can take 1 step or 2 step to climb. Find the number
of ways to reach nth floor. Code was required
Interviewer was very happy after that.
Face to face: Round 4(Technical, 1 hour 20 minutes):
It was like semi HR round.
1. Why Computer science?
2. Given an array of integers which is initially increasing and then decreasing, find the
maximum value in the array.
https://www.geeksforgeeks.org/find-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasin
3. Modified k heavy path in binary tree problem.
In evening they told me result and I got selected in amazon. It was very nice experience for
me.

All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-set-26/

96
Chapter 28

Set 27

Amazon Interview | Set 27 - GeeksforGeeks


Hi, I was recently interviewed for SDE1 position for Amazon and got selected. I have 1.5
year experience in java. Geeksforgeeks helped me lot. I am very thankful to Geeksforgeeks
team. Following were interview questions-
Two telephonic rounds followed by 5 F2F interviews.
Round 1 (Telephonic):
1. There is a dictionary already implemented. Write a method, which takes input String
without space, to prints all subsets of the input string which is present in dictionary.
Example: Dictionary – a*
………….Input- aaabaa
………….Output- a,a,a,aa,aa,aaa,a,a,aa
2. There is a dictionary already implemented. Write a method , which takes input String
without space, to replace the characters from the strings which are not present in dictionary
with –
Example: Dictionary – a*
………….Input- aaabaa
………….Output- aaa_aa
Interviewer was cool. Did not code properly (lots of bugs were in code), but gave good
approach for first question. For second question solution sent in a mail.
Round 2 (Telephonic):
1. Write a program to remove duplicates from array of prime numbers.
2. Write a program to return nearest elements from a binary search tree for input element.
This round was very good. Interviewer was very happy with my approach for both questions.
Code did not have big bug.
Round 1 (F2F- Problem Solving and coding):
1. Tell me about yourself.

97
Chapter 28. Set 27

2. Write a program to find top 10 elements on an array of integers.


Don’t remember much. Questions were easy. This round was very good. Interviewer was
happy with solution.
3. Write a program to calculate a^b and store it in floating point representation.
Round 2 (F2F- Computer Fundamental):
1. Tell me about experience in past job.
2. OOPS concepts- Polymorphism, Inheritance, Encapsulation, Abstraction.
3. Aggregation and Composition.
4. Design patterns which you have implemented.
5. Write code to implement Singleton design pattern.
6. Design a system to implement options in Pack of cards.
7. Difference between Windows and Unix.
8. Threads, Synchronization, Deadlock.
9. Other subjects which you studied in your academics.
10. Most challenging work you ever faced.
11. Discussed about current project, role.
This round was fair enough. I was not able to discuss questions on subjects which I studied
in academics.
Round 3 (F2F- Data Structures and Algorithms):
1. Tell me about yourself.
2. There is a 2d array. Write code to find the path with maximum sum. You can only
traverse i+1 or j+1.if i is row number and j is column number.
I solved it using dynamic programming
3. In a binary tree find the least common ancestor for two nodes. (Write code)
4. Similar to 3rd question. Write a program to find least common ancestor in binary search
tree.
This round was very good. Finished it only 40 mins.
Round 4 (F2F- Managerial round):
1. Tell me about yourself.
2. Copy Linked list with orbit pointer.
3. Write a code to find top hundred elements in a data set which cannot be loaded in RAM.
4. Typical parenthesis checking problem.
5. Most challenging work you ever faced.
6. What will do if you get task which is ambiguous.
7. At what extend you will be frustrated if you always get ambiguous problems.
8. How many members in your team in current organization. What’s your role? Questions
on current project.
Interviewer was very cool and friendly.
Round 5 (F2F- Bar raiser round):
1. Tell me about yourself.
2. Discussed about current project.
3. Write a program to find number of inversions in an array.
Example- Array 2, 5, 3, 1,10
Inversions (2,1) , (5,1), (3,1), (5,3)
Answer will be – 4
Gave solution of complexity o(nlogn) . Interviewer gave me hint for that.

98
Chapter 28. Set 27

Hint- Divide and conquer approach.


He asked me to write code which doesn’t have any bug.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-27/

99
Chapter 29

Set 28

Amazon Interview | Set 28 - GeeksforGeeks


Hi, I was recently interviewed for SDE1 position for Amazon, Hyderabad but was not able to
make it through. Although I wasn’t selected but it was a good experience and GeeksforGeeks
has been very helpful.
Following were interview questions-
I had one written round and one telephonic round before 4 in-face interviews in Hyderabad.
Round 1 (Written):
There were four questions which had to be submitted in a time span of two hours. Questions
were:
1. Given a character string, display the characters that appear more than once in that
string.
2. Rotate a matrix 90 degrees to right
3. Convert a BST to DLL.
4. Find kth largest element in a given BST.
Round 2 (Telephonic):
1. First question was to get two numbers fro a BST whose sum was equal to k. I answered
it using a preorder traversal to get a sorted array and than starting two index from both
ends to find if two elements with sum as k exist or not. He than asked if it can be solved
without using an array or extra space. I tried solving it by traversing from two ends of the
tree in preoder and reverse preorder fashion and it took some time to code. Dry run of the
code seemed to be right but I wasnt sure. Anyways the best way of not using extra space
can be to convert tree to DLL (in space) and use the same technique as used on array.
2. For second question I was asked if I had heard the question before or not. Question was
that a a matrix is given with its rows and columns sorted and an element is to be searched
in that matrix. I had heard the question before but had not solved it and told the same to
the interviewer. After thinking for a while I could get an algo by starting at the rightmost
element of the first row. If element if bigger we move down or else we move right. The
solution was fine but he doubted that I had solved it earlier.
3. He asked to write a program of finding the square root of a number without using library

100
Chapter 29. Set 28

functions. I had done it before and told him the same. I used Newton-rapson method to get
the solution but he wanted it through something on the lines of binary search. I almost got
the solution but may be I was running out of time so he dropped the question there only
and asked me to dictate the solution of 2nd problem.
Two days later I got a call that I have cleared my telephonic round and have to be present
in Hyderabad for further rounds(four). Arrangements done my Amazon and I appeared for
the further rounds on 27/4/2013 in their Hyderabad office.
Onsite:
Round 1 (Technical):
1. First question was to find the vertical sum of a binary tree. I told him the solution using
and array/hash. Whenever we move left we decremented the index while moving right we
increment the index. The solution looked fine to him but he wasn’t very comfortable with
negative indexing. So he asked for another solution using doubly linked list. Initially I
wasn’t getting it but when he gave some hint I was bale to solve it but it took some time to
cover edge cases. With the final solution he looked convinced.
2. Next question was to have Stack operations of Push, Pop, and FindMax in O(1) time. I
started doing this using only one index of max variable but than I realised I needed max
index at all levels so gave him a solution using two stacks. One having the element and the
other having the corresponding max index. He looked convinced with the solution.
Round 2 (Technical):
1. In second round there were two interviewers and coincidentally one of them was the
same guy who took my telephonic interview. First question was related on how to chose
the ‘related’ items list whenever a product is displayed on Amazon website. the problem
was to find the least related product for a given product. Initially I answered using n-ary
tree but told him that we would have duplicate entries. He asked for optimized solution so
I suggested using adjancy-list nut finally realized that it can be solved using graphs. They
were convinced and asked to code. I solved it using a Queue so while traversing a matrix
we pushed in the elements in the queue with their level of relation. They were convinced
with the solution.
2. Second question was to delete an element from doubly linked list. I solved it but missed
out on and edge case where the element to be deleted is not present in the list. I added that
check later.
3. Third was that for a given BST invert the signs of the elements and finally have a new
BST. It clicked my mind that after sign inversion it will be a mirror tree and gave the
solution for the same.
Till this time feedback looked fine.
Round 3 (Technical-Managerial):
1. The next interviewer was senior guy and asked me about my work. Explained him in
detail.
2. Later he asked me that for a given binary tree having three address fields i.e. left, right
and bfs successor, left and right fields are filled and the successor field is to be filled. I solved
it using level order traversal with a queue but he wanted solution without using extra space.
I was taking time to solve it when he gave hint about keeping track of the parent. After
this hint I was able to solve it with few conditions missing but with his intervention I was
able to give a working code (as looked to him and me).

101
Chapter 29. Set 28

Round 4 (Technical-Managerial):
1. There were two interviewers. First question was tell me about yourself and your work.
2. Given a m*n matrix, we need to find the number of ways by which a bot can reach the
(m-1,n-1) block if bot can move only right and down while starting from (0,0). I gave him
a solution using DP. Build the recursion tree showing the final solution. He didn’t ask to
code but asked to finds the recurrence relation. I got stuck I don’t know why. I guess this
was the start of decline. he gave some hints and I was finally able to write it, still.
3. For a given binary tree and a key, prune the tree with all the paths (root to leaf) that
have sum less than or equal to k. I was able to solve it with some hint. The solution looked
convincing.
Four days later I got a mail stating that “Unfortunately, we are unable to take your can-
didature further, at the moment. However, your credentials are extremely impressive and
we wish to retain your details on our active database. We shall get back to you as soon as
another similar opportunity opens up.”

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-3/

102
Chapter 30

Set 29

Amazon Interview | Set 29 - GeeksforGeeks


I am very much excited for sharing my experience for Amazon, i went through 6 rounds
and really enjoyed a lot for facing all of them and i feels like in each round that GEEKS-
FORGEEKS is the one the best site which gave me lot of ideas for solving the problems,
This is THE BEST site for coding for getting good questions and also for improving our
skills and creating our base SOLID.
1st round >> ONLINE test
1) Convert a BST to Double Linked List
2) Count the number words words + spaces + special chars in a given string
3) Print kth Lasgest node of the given tree.
4) Write the complete code for rotating the given matrix.
Solved three successfully with all cases but for one some cases was missing because of network
issue i was facing time problem.
2nd round >> Telephonic
1) Level order traversal (Both approach recursion && Queue)
2) In O(1) – getMin, getMax, getTop,push,pop
3) Find the least positive missing number in an array.
4) Print all permutations of the given string
For all i need to write the code, and i was feeling like i was doing fast and being on
expectations of the interviewer, he was so happy with me.
3rd Round >> FACE TO FACE (It was nice, it went thru 1hr)
1) Write a code for inverting the values of BST and return the new tree’s root
(In place i have to do this, first i have given solu. with O(n) space with O(n) complexity )

103
Chapter 30. Set 29

2) Finding the element in O(m+n), in a sorted matrix which is sorted in row as well as in
column.
(I said i know this, so i just told the approach and we skip that !!)
3) Project questions, infact in all rounds it was there!!
4) Rope Puzzle :: 2 ropes are there and u need to find the 45 mins(Very generic Google
Puzzle)
4th Round >> FACE TO FACE (It was Amazing, it went thru 1hr 30 mins)
1) Find a median in running stream of numbers.
2) Find a k best or max values in the running stream of numbers.
3) Project Questions !! i Love that !!
4) State machine questions !! Gaming Questions (Bcoz m a game developer)
Questions on garbage Collection, Virtual machine (Bcoz i did project on it)
Anyway i love all those part.
5) One very nice question, i need to calculate the area for rain drop which will be holded
for bar graph(Its basically a very real world problem, i love to do that, even i did mistakes
but they guys are really awesome they helped me out to get rid of my problems)
5th Round >> FACE TO FACE (It was Damm Amazing, it went thru 1hr 15 mins)
1) I need to write recursion function for a robot which has to move from one location to
other location in a grid.
In recursion i took time to write the base cases, but finally with some hints i was able to
make it.
2) I need to code for k-heavy path approach and also need to write its recursion.
There also i was continue taking to the interviewer and clearing my doubts and using the
hints given by him. Finally i was able to code it and do the recursion also.
Every time i need to write the recursion in mathematical form and calculate the Complexity
also like we have to do normally for detecting the complexity.
I love the mathematical part and coding, its in my blood !!
3) Project Question !! Scalable problems !! Dealing with N dimension study and mathemat-
ical problems, even covering my whole resume.
Finally he was very happy and said to me that you need to think proper then code or design,
rest is awesome !!
6th Round >> FACE TO FACE (It was with the Hiring Manager,i guess, it went thru
45mins)
1) He asked me about my whole projects and lots of about my resume and my challenges
faced till now, it was good to explain all those.
2) He asked me to design an approach which will search all the valid combinations of a given
string.

104
Chapter 30. Set 29

I have given some approaches like implementing TRIE, and explained the pros and cons for
it and also the complexity of it.
Then i modified it and explained the Other approach which is better than the above by
using HASH MAP and INDEXING with buckets if valid words.
We had lots of discussion on it. and Finally he said we are looking for guys like you.
Finally i have the offer Letter From Amazon and He asked me for Coffee Or Cold Drink. I
Have taken Coffee.
NICE EXPERIENCE !! I LOVED ALL THE INTERVIEWS AND ENJOYED A LOT !!
Finally a Gold Medalist 2yr Exp. guy who is doing a very nominal job, got a Right place
to work which is AMAZON !!
Heartly Thanks To GeeksForGeeks Community And Their Coding Stuff Which is available
in Site !!

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-29/

105
Chapter 31

Set 30

Amazon Interview | Set 30 - GeeksforGeeks


I have attended the interview for Software Development Engineer position and got the offer
from Amazon.
I spent a lot of time in GeeksforGeeks going through the precise and simple explanations of
complex problems, which helped me to sharpen my mind. Really, its a great work by the
geeks and I am happy that I am a part of it.
The following were the questions.
Round 1 : Write a program to solve the below problems. (Time 1.30 hrs)(Written Test)
1. Given a string in the form of a Linked List, check whether the string is palindrome or
not. Don’t use extra memory. Give the time complexity. The node structure is

Class Node {
Char data;
Node next;
}

2. Given a Binary Search tree along with the parent pointer, find the next largest node for
the given node. Give the time and space complexity. The node Structure is

class Node {
Int data;
Node left;
Node right;
Node parent;
}

3. Given a sorted array which is rotated n number of times. Find out how many times the
array is rotated. Time complexity should be less than O(n).

106
Chapter 31. Set 30

Round 2 : With Team Member


1. Tell me about yourself.
2. Explain your project.
3. Given a Binary tree, find the vertical sum.
….a. I gave a solution using hashmap. There were discussion about the problems (time and
space complexity) in using hash map. Then due to its cons, he told me to use some other
DS to solve the problem.
….b. Then I gave a solution using Array. There were discussion about how it can be used,
time and space complexity and its pros and cons.
….c. Code using Array.
4. Given a matrix mxn, where all the rows were sorted, print the elements in the matrix in
a sorted order.
….a. I gave a solution with O(mxmxn) time complexity.
….b. He wanted a solution in O(mnlog(m)) time complexity and gave a hint to use heap.
….c. Code for the same.
Round 3: With 3rd Level Manager (culture Fit)
1. Tell me about yourself.
2. Explain Your accomplishments.
3. What you are proud of yourself?
4. How you will handle the conflict with the team member?
5. Lot of behavior oriented questions.
6. Given a String, remove the duplicates in the string.
….a. Lot of variations from the same problem.
….b. Asked for a solution in different time and space complexities and the complications
involved.
….c. I guess the communication skill might have been tested here.
7. Given a floating point number, write a program to convert it into a string. The number
of digits after decimal point can be more than 1000.
Round 4 : With Manager
1. Can you tell me about yourself?
2. Explain the projects you worked on?
3. Given a Binary tree, connect all the leaf nodes in the form of a doubly linked list. Don’t
use extra space.
4. A scenario was given about two robots and its functionality. Write a program which will
be running in both the robots which will perform the specified functionality.
5. Given an integer, find the next largest integer using the same digits as in the given
integer. For example, if 12345 was given, the program should return 12354.
Round 5 :
1. Tell me about yourself.
2. Explain what you have done in your previous company.

107
Chapter 31. Set 30

3. As I have worked on a product and they told to explain the product


4. What are the developments you have done and what impact it will be having?
5. What will happen to your development, if the product Is migrated?
6. Questions on threading.
7. What is a thread safe code? Explain.
8. What is a process and thread? Differences?
9. Given a binary tree print the elements in a zig zag order.
Thanks a lot for Geeks team.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-30/

108
Chapter 32

Set 31

Amazon Interview | Set 31 - GeeksforGeeks


Recently I attended the Amazon walk-in and got selected for the position of SDE I.
Written test:
1. Write a code to convert tree to DDL(assume tree node contains pre, next pointers and
set as null intially.)
2. WAP to encode and decode string.
aabbbbcccd a2b4c3d1
3. Find the sum of elements in after nth iteration for below operation on array.

original array 4 6 8 3 6 sum = 27


iteration1 -2 -2 5 -3 sum = -2 (a1= a2-a1)

iteration2: 0 -7 8 sum= 1

iteration3: 7 -15 sum =-8

Hiring Manager:
1. Find the nearest leaf node from given node in binary tree..
use post order traversal.. like LCA in binary tree
2. Find the first k largest numbers from large file size. Explain solution for
1. When we have space to store K elements in RAM
2. When we didn’t have space to store K elements in RAM
Tech:
1. Design N-ary tree, to make sure that lock and unlock operations can be done with
minimum complexity (height of tree)

109
Chapter 32. Set 31

a node can be locked when its ancestors or successor are not locked.
we can a unlock a node a any time.
2. a[] = {a,b,c,d,e} b[]={f,g,h} result should be = af+bg+ch+df+eg
Tech:
1. Find maximum product of subarray in given array of integers
2. Design T9 dictionary
Bar Riser:
1. Design a tree, in which a root can have unlimited children and write a code to print each
level in separate level
2. Print the anagrams present in a huge file (each line in file contains one word and you
didn’t have any constraints like limited memory etc..) for a give string
use trie or hashmap
Like all Amazon interviews in GFG, here interviewer more concerned about edge cases and
perf perf perf perfect code.
Thanks a lot GEEKS FOR GEEKS and my dear friends Ramesh, Purush, Jhadey for helping
me in preparation.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-31/

110
Chapter 33

Set 32

Amazon Interview | Set 32 - GeeksforGeeks


I would like to contribute for GeeksForGeeks by sharing my experience of Amazon Interview
process. This was for a SDE position in Hyderabad. I have almost 2 years of work experience
in Samsung.
1st Round: Written
Test was on Interview Street Platform.
Qs-1) A function printMostFrequentWords, which takes in an array of strings, was given.
It is required to print a list of all the letters that occurred with the highest frequency in
each line of the array, followed by the frequency.
The list of letters should be an alphabetical list of upper case letters followed by an alpha-
betical list of lower case letters.
Sample Test Cases:
Input #00:
When riding your bicycle backwards down a one-way street, if the wheel falls of a canoe,
how many ball bearings does it take to fill
up a water buffalo?
Hello Howard.
Output #00:
e6
al 7
a3
Hlo 2
Qs-2) https://www.geeksforgeeks.org/construct-a-special-tree-from-given-preorder-traversal/
–Variation of this one
Qs-3) http://www.careercup.com/question?id=12998667

111
Chapter 33. Set 32

Third case was a bit tricky.


Qs-4) Rotate an M*N matrix by 90 degrees. There was no function given in this case.
Everything should be assumed by you only.
Qs-5) Delete the Kth Node from a linked list.
I solved 4 questions with all test cases while for another 1 only 10/15 test cases passed.
2nd Round: Telephonic
Qs-1) Spiral level order traversal of a tree. (Use two stacks)
Qs-2) A person can jump 1 or 2 steps. No of ways of reaching the top of n stairs. (Try for
O(1) space.)
Qs-3) Find the longest substring in a string with exactly 2 unique characters. The substring
should not contain more than two different chars.
So, aaaaabbaaa is a valid substring
Also, ccaccccaccaca is a valid substring.
Need to write code for the 3rd qs.
Expected = O(n)
I answered all the 3 questions and was confident of receiving the call for onsite which I did.
F2F ROUND 1:
Qs-1) The question was to print a tree vertically. Please note it was not asked to get the
sum at each vertical level. We have to print nodes at various vertical levels starting from
the leftmost vertical level to the rightmost vertical level.
I suggested array of vector then a hashing. Finally I gave a solution based on DLL.
Code was written using DLL only.
Qs-2 ) Only approach was asked on how will you save a binary tree in a file( Not a BST)
There are no assumptions on Binary tree.
This round went well for me.
F2F ROUND 2:
Qs-1) First I was asked to design a Data structure with O(1) insertion and O(1) search.
I told about hashing. Then he told me to get a random number from the current list of
numbers which have been inserted into my Ds. So I maintained an array storing pointers
to the hash table.(Assume no Collision, he told so).Then he said O(1) deletion also. I was
stuck on this I was not able to make both deletion and getRandom in O(1).After Some
Discussion he moved on.
Qs-2) He told there is a range, defined by a min val and a max val. In a given array I had
to find all elements within the range. I told him its only possible in O(n).We have to look
at each element. Then he told me to assume array as sorted. Then I used Binary search for
finding indexes of ceil of min and floor of max to find the elements in the range.

112
Chapter 33. Set 32

This round went ok for me.2nd question i wrote proper code with all edge cases, but in first
I got stuck a bit.
F2F ROUND 3:
Qs-1) In a binary tree, a complete path is defined as a path from root to a leaf. The sum
of all nodes on that path is defined as the sum of that path. Given a number K, we have to
remove (prune the tree) nodes from the tree which lie on a path having sum less than K.
Note: A node can be part of multiple paths. So we have to delete it only in case when all
paths from it have sum less than K.
I was able to solve the problem and write correct working code for this.
(Hint : Think of a bottom up approach.)
Note: Values in tree can be -ve also.
Qs-2) A robot problem: No. of ways to reach from 0,0 to m,n in a m*n grid. I had to tell
recursive function only. No code required.
This round went very good for me. The first question was a bit tricky but solving it raised
my confidence.
F2F Round 4 with Hiring Manager:
Qs-1) This was mostly a HR Based round. A lot of questions about my previous work, my
initiatives, challenges I faced and many other questions.
A simple question on matrix was also there. Fill rows and cols with ones if a 1 is present in
that row or a col. Code also required.
Question based on shipment and orders etc. Eg: What all things to take care in b/w of
order placed and item shipped. What all factors and things you will consider.
I was being interviewed for transportation team. So questions based on it.
Overall, the round went well
I returned to Bangalore that night.
Few days later, I got a call from HR saying I am very close and I need to appear for another
round in Bangalore office.
F2f Round 5:
About half an hour Hr based discussion.
Then two Technical questions with code:
Qs-1) In a binary tree, return true if all leaves are at same level and return false if all leaves
are not at the same level.
Qs-2) An array is given which is first increasing and then decreasing. Find the pivot element.
Need to take care of all the edge cases.
This round went well for me. Mostly this round was on soft skills. I did well in coding
questions and wrote proper code for both.
In the evening I got a call from HR that I was selected. �
I would like to thank GeeksForGeeks Team for being a great help for me.

113
Chapter 33. Set 32

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-32/

114
Chapter 34

Set 33

Amazon Interview | Set 33 - GeeksforGeeks


I recently attended a walk-in for Software development Engineer (SDE- 1) at Amazon,
Bangalore.
Here is my experience of Amazon interview.
As I was from the same city, there was no phone interview. I have listed down all questions
that I remember.
Round 1: Data Structures, Algorithms and coding (1 hour)
Interviewer just started off with questions without introduction and stuff.
1) Given a singly linked list, swap every 2 nodes, for odd number of input; retain the last
node as it is.
Eg: Input: 5 13 15 18 20 11 6 7
Output: 13 5 18 15 11 20 7 6
I was asked to write the code straight-away.
Wrote the same, verified boundary cases and discussed.
2) Given a binary tree, find the number of pairs where sum of 2 nodes’ values equal to k
Eg:

1
2 3
4 5 7

Say k=7, output =2 ( 2+5, 3+4)


Suggested an approach where I’d use inorder traversal of this,
Then interviewer asked me to solve the simplified problem, find k in sorted array instead of
tree.
Got solution for this one, to have 2 pointers at each end, and traverse accordingly.

115
Chapter 34. Set 33

I was asked the approach for extending same to BST.


Then, I implemented the same for BST using stack.
Round 2: Data Structures, Algorithms and coding (1 hour)
1) Given input as k sorted arrays, generate a single sorted list as output.
Eg:
Array1: 1 5 8 9 11 ….
Array2: 2 12 24 44 …..
.
.
Arrayk: 3 15 79 115 ….
Output: Array1: 1 2 3 5 8 9 11 12 15 ….
Discussed the approach, and complexity, then wrote the code for the same.
2) Given a function isGreater, compare user defined objects and then return the object that
is greater than all other objects.
Twist: obj1 > obj2 and obj2 > obj3 does not mean obj1>obj3
I asked for the use case for the same, as I was not convinced with the problem.
He gave an example of games/ 1 team winning another.
Discussed the approach and then wrote the code.
3) Given an input sentence, output the non repeated words in the sentence.
4) How are maps implemented?
Interviewer then clarified my questions about Amazon.
Both first and second rounds were at similar difficulty level.
If the interview feedback was bad for any of these, the candidate was eliminated. If at least
1 of these went well and other “not sure”, then too candidate is called for next rounds.
Round 3: Hiring Manager round (1 hour 40 minutes)
Discussed on my current roles and responsibilities
why do you want to join to Amazon?
What are your accomplishments in your role so far?
What are the things that you’re not good at and need to improve?
Serialization of Binary tree. Given 1 traversal is it possible to re-construct the binary tree.
Write code to reconstruct the tree given any 2 traversals.
I took in-order and post-order traversal, discussed the approach and wrote recursive solution.
Was then asked the approach for iterative.
Round 4: Culture Fit Round
This surprisingly had a data structure question first.
1) Given a n (large number) lists of customers who visited n webpages on n (large number)
days, design a data structure to get customers who have visited the website on exactly “k”
days and should have visited at least “m” distinct pages altogether.
Was then asked to improvise the solution as much as possible
2) Details on my previous project and job profile

116
Chapter 34. Set 33

3) Challenging situation faced


4) Why should we hire you?
Then, he answered some of my questions.
Round 5: Coding, Algorithm and data structures (Technical round with a senior
developer)
Started with questions straight away
1) Least common ancestor of a binary tree (Solution and Code)
2) Given a 2 dimensional array sorted vertically and horizontally, search for an element and
return true if the element is present. (Algorithm, Code and Complexity)
Example

1 5 13 29

11 16 25 38

45 49 52 57

51 54 59 66

3) Something on count sort.


4) Print binary tree in zig-zag order..
5) Gold box problem (Approach)
There are ‘n’ gold boxes placed in a row, each having different number of gold coins.
2 players play a game, where the motive is to collect the maximum number of gold coins.
Each player can see how many coins are present in each box, but can get a box from either
end only, on his turn.
Design a strategy such that Player1 wins (Assuming both players play smartly)
I got the hiring call after couple of days, after my last round of interview. They said feedback
was very positive and they’re happy to hire me.
Was so happy � � Thank you..

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-33-2/

117
Chapter 35

Set 34

Amazon Interview | Set 34 - GeeksforGeeks


First of all, a very very big thanks to whole team of geeks for geeks. It is because of them
only that I was able to crack the interview process of amazon and get a job in my dream
company.
No of Rounds: 1 MCQ round + 2 online test round + 4 PI
Type of Interviews: Campus Interview for freshers
MCQ round(Time) : 45 minutes 20 Objective Questions:
5 question on maths which included 3 on probability
Some c output questions easily available on geeks quiz
Questions on heap, hashing, time complexity of recursive functions
One sql query, one question on fcfs and round robin scheduling, page fault in demand paging,
dining-philosopher problem,one on propositional logic, one based on Huffman code.
Online test 1 (Time): 45 Minutes
2 Questions:
1. Given three linked lists,where each linked list represents a number, add the three lists
and return the resultant list.
5->1->2->NULL
9->1->NULL
7->2->2->NULL
Output :: 1->3->2->5->NULL
2. Given an array and two numbers x and y, find minimum distance between two numbers
x and y. assume that x and y always exist in array and it may be that x and y are same
also…

Online test 2 (Time): 45 Minutes


1. Convert a given binary tree to sum tree.

118
Chapter 35. Set 34

2. Given an array consisting of both positive and negative numbers, 0 is considered as


positive, rearrange the elements such that positive and negative numbers are placed alter-
natively, constraints are that it should be in-place and order of elements should not change.

Interview Round 1(75 Minutes):


Technical Interview
Asked to give a brief idea about my project.
Question 1: Given a linked list,reverse every k nodes of the linked list.
Question 2: given a matrix of size m * n, place k students in such a way so that cheating
in an exam could be minimized…. Was asked to just explain the approach, no code required.
Question 3: suppose a online chat between customer and serviceman, serviceman wants
to reply to customer as soon as possible…suppose text which is to be sent as reply takes 10
sec for being typed. How can he make typing faster ?
My answer was using autoprediction feature, by which he will need to type less number of
characters, so typing will become faster..
Then question was extended to how to store the words for being used in prediction…
I answered a trie data structure which allows prefix matching..
Then question was further extended to write a code to traverse all the words stored in
dictionary in lexicographic order..

Interview Round 2(50-60 Minutes):


Technical Interview
First of all was asked to tell something about myself.
Then a detailed discussion about the project, conversation continued nearly for 20 minutes,
he wanted me to explain him everything from the scratch.. I used genetic algorithm in my
project..so he wanted to explain him the concept of genetic algorithm..
Then a coding question:: stable stock problem.
You are given prices of stock of a company at consecutive days in an array..write a code to
find the maximum profit one can make by keeping a stock value for as long as possible..that
value of a stock is called a stable stock value.
Example::
65983
So maximum profit is 15, because stock of value 5 would be hold for 3 days. So max profit
is 15.
The problem basically was a variation of finding index of next smaller element.
I solved it using the concept of largest rectangular area in a histogram where need to keep
track of previous smaller will not be required.

Interview Round 3(60-75 Minutes): (Bar Raiser Round)


Technical Interview
Interviewer was very cool.. he first asked about me, did some casual talk to do away with
my nervousness.
Infact, he told me that it looks like that you all have studied geeks for geeks very thoroughly
so I am going to ask you a question that is not present in geeks for geeks. He challenged

119
Chapter 35. Set 34

me it will be a question you have not heard of before. At the end of round, he showed me it
was a question from top coder, but I had never heard of anything called top coder before.
Question 1: Given a string, find the longest sinusoidal sequence in it. If there are multiple
such sequences of same maximum length, return the one which comes first in lexicographic
order in a dictionary..
Sinusoidal means increasing then decreasing then increasing and so on.
Example ::
a r u n ::
a u n , a r n , r u n are three such sequences of length 3…. But, a r n is output since it
comes first in lexicographic order.
Interviewer gave me hints that if I had to found the sequence in which all elements were
increasing, then I answered LIS will give me the solution , this was the hint. So, basically,
it was a variation of LIS. I answered it in O(n2) and 2n space….
Then was asked to do it in (n) space and o(n).
Question 2: Suppose a student needs to implement a bst structure to solve a problem,
but instead he used a linked list…. Then give an example of input sequence, in which his
implementation works… new value will always be added at beginning of a linked list.. so.
Basically at each step after insertion , root of bst and head of link list should point to same
node. I was asked to provide the sequence.

Interview Round 4( 35 Minutes)


This round started of with some nontechnical questions.. what will I do in different situa-
tions?
They seemed to have found out every detail of terms involved in my project..so, there was
a detailed discussion on project… my project involved concepts of statistics, so he asked me
questions regarding stats…. This discussion went nearly for half an hour…. In the end, he
told me lets see whether your project could bring you to amazon….
After the 4th round, I nearly have to wait for 4 hours before the result were announced.
Finally, the interviewer said they were highly impressed by me and I was hired.
In total 7 students were selected among us.
Once again a big thanks to whole geeksforgeeks team.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-34/

120
Chapter 36

Set 35

Amazon Interview | Set 35 - GeeksforGeeks


On-campus, 1 MCQ round, 2 coding rounds, 4 face-to-face rounds.
MCQ round(45 min)
– 5 questions on mathematics, one was from probability, all easy 15 questions technical, from
each-demand paging, dining-philosopher, humming codes, 3-4 C programs output, etc
1st Coding round–2 questions(45 min)
1. Given an array,find minimum distance between two given integers in the arrays. Note
that the two given integers may be same.
2. Given three linked lists, each representing an integer, add them
eg
3-7-0-8
2-1
5-4-2
ans– 4-2-7-1
explanation- 3708+21+542=4271
2nd coding round(45 min)
1. Given an array containing both positive and negative elements, arrange in such a manner
— 1 positive number, then 1 negative,then 1 positive and so on. If number of negative
numbers are more,extra numbers should be kept in end and vice versa. Note the order of
negative and positive elements should be same in the modified array and you are not allowed
to use any extra space
2. Given a binary tree, replace each node value by sum of its children value.
Face to Face rounds–
Round 1
1. Level order traversal and then level order traversal in spiral form. Only algo, no code

121
Chapter 36. Set 35

2. Given a dl representing the spiral level order traversal of a binary tree,convert it to a


binary tree inplace. In Last level, nodes will be either to the right or left only. complete
code in C

eg 1-2-3-4-5-6-7-8
o/p--
1
/ \
3 2
/ \ / \
4 5 6 7
\
8

3. Glass pyramid problem.Measure amount of water in j’th glass of i’th row.(algo+code)


Round 2-
very few technical questions
1. Given an array which is first increasing and then decreasing,how will you search an
element?(only algo)
2. Convert a n-byte integer from little endian to big endian.(code was required)
3. Find k max elements from a large file.(only algos)
Round 3
no technical questions at all
Round 4
After some personal questions, the interviewer asked some technical questions as well
1. Suppose we receive requests for a page, but we want to ensure that max no of request
per sec is ‘x’. If there are more than x requests,what will you do?
We want a continuous flow. How will you do that?
2. Suppose in a system, some processes are already running. Now when an user will give
new task(or process), he will give a list of processes his process is dependent upon. Some of
those may be running, some may not be running right now. You have to ensure that there
is no contention, i.e., If a process, Pj is dependent on process Pi,
Pj should not execute along with Pi. How will you ensure that? Complete algorithm with
code was required. The interviewer went on complicating the problem.
At last I used graph and 3 hashmaps to solve the problem. He was ok with it.
That’s it. My last round completed and I was selected.
All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-set-35/

122
Chapter 37

Set 36

Amazon Interview | Set 36 - GeeksforGeeks


1 round (20 MCQ + 2 coding question)
3 face to face round, 1 telephonic interview.
1st coding question
—————————–
Find the diameter of the tree.
2nd coding question
—————————–
check the validity of sudoku.
1st face to face Round
————————————-
Qs-1) In a binary tree, a complete path is defined as a path from root to a leaf. The sum
of all nodes on that path is defined as the sum of that path. Given a number K, we have
to remove (prune the tree) nodes from the tree which lie on a path having sum less than K.
A node can be part of multiple paths. So we have to delete it only in case when all paths
from it have sum less than K.
I was able to solve the problem with bottom up approach, and able to write a working code
of it.
Q-2) Given an array of positive numbers, find the maximum sum of a subsequence with the
constraint that no 2 numbers in the sequence should be adjacent in the array. So 3 2 7 10
should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7).
I was able to give him a DP solution with a Parent array which stores thee index of the
parent of every element,i hd put -1 for the first element,at the end I backtrack the array to
find the all the elements.
2nd face to face Round
————————————-
After some personal questions, the interviewer asked 1 coding question

123
Chapter 37. Set 36

Q-1)
n1 pairs of “{} ” brackets
n2 pairs of “[] ” brackets
n3 pairs of “() ” brackets
I have to find the all valid combinations of all the pairs. I have to write the working code
of it.
I gave him the solution with recursion and stack.
3rd face to face round
————————————-
Interviewer asked some basics Questions on Design patterns, OOPS and OS,after the big
Discussions of all the Questions he asked 1 coding questions.
1st Question
————
There is a string, in which all the spaces are removed, we have to find the original string
with the help of a machine which takes input a word checks that it is valid or not.
Telephonic Interview
————————————-
The Interviewer asked to give a brief idea about my project.
After some questions on my Project, the interviewer asked 2 coding question
Q-1) tree to doubly link list. O(n) and in-place solution is required.
Q-2) A array of N elements, we have to replace all the elements with nearest greater which
is present on the right side of that elements. O(n) is required.
After 2 days, they inform me that I am selected for the job. �

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-36/

124
Chapter 38

Set 37

Amazon Interview | Set 37 - GeeksforGeeks


Interview Experience for placements at AMAZON.
It consists of 1 online round (20 MCQ + 2 coding question) and 4 F2F interviews.
Online Round 1:
20 MCQ 1 question each from OS, pigeon hole principle, probability, DBMS, networks, NP
problem and other questions from C/C++ input output and logical question
22 from batch out of 300 students were selected for F2F interviews
Interview Round 1:
As they were short in time as it was 9 at night so they asked me single coding question.
Que 1: Given an array of n numbers with repetition of numbers. You need to find the max
length of continuous sub array with at max 3 unique elements.
For eg
array: 1 2 3 1 4 3 4 1 2
ans: 6 (3 1 4 3 4 1)
Solution: Time complexity O(n)
Extra Space O(1)
Interview Round 2:
They asked me 3 questions but I am not remembering the 2nd one. Sorry for that
Que 1: You are given two binary trees. You need to tell that if one tree is rotated 90 degree
and placed at bottom of that tree and each leaf nodes at max depth of two trees will meet
each other or not.
for eg:
lets assume () as a node
Tree 1

(1)
/ \

125
Chapter 38. Set 37

(2) (3)
\ /
(4,5)
node 4 and 5 are overlapping
Tree 2
(1) (4)
/ \ \
(2) (3) => Rotated one (2) (3)
/ \ /
(4) (1)

So it returns true as node 4, 5 of tree 1 is overlapping with node 4 of tree 2


Firstly I was asked to give algorithm then when i gave he asked me to code it
Solution: Time Complexity O(n+m) (where n and m are nodes in tree 1 and tree 2 respec-
tively). Space Complexity O(n+m)
Que 3:
Suppose u given normal deck of cards 4 suites and 13 cards of each suite in which one card
is missing
you are picking a card one at a time and sees that card and putting it aside
Find the suite and number of missing card.
Then he said change the number of suites to K (very very large you cant add till k)
and N numbers (again very large numbers)
Interview Round 3:
It was an easy round for me atleast but not for others
Que 1: Find the palindrome of a given number without using extra space
Que 2: 100 floors and 2 egg problem changed to 50 floors and 2 eggs
Que 3: You are given array of numbers which increasing first then decreasing. Find the
greates number.
eg: 1 2 3 4 5 4 3
answer: 5
Solution : Time Complexity O(logn)
Space Complexity O(1)
Interview Round 4:
He asked me about my myself apart from coding and as I said “Hacking” so we discussed
about hacking a lot.
He also aksed me about my projects
Then he gave me a puzzle:
Assuming I have a chessboard (8X8)
a knight is placed at (x,y) and he moves N hops
Find the probabilty that he will be inside after N hops.
On a condition that if a knight moves outside then he will remain outside he cant come
inside.
For eg. (x,y)=(0,0)
n=2
probabilty=(12/64)

126
Chapter 38. Set 37

4th round was type of HR as he wants to know about myself and how I do different things.
If I stuck in a position what will I do.
If your boss says that you have to do X and you are not satisfied with this then what will
you do and how will you approach.
After that I waited for 3 hours and I got selected with 4 of my friends �
Hope this will help, I try the possible way to support you.
All the best for your placements �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-37/

127
Chapter 39

Set 38 (SDE-I)

Amazon Interview | Set 38 (SDE-I) - GeeksforGeeks


1) (Telephonic round 1)
a. Print a matrix in spiral order (Code)
Soln: Solved it using recursion. Each recursive call was suppose to print boundary elements.
On every recursive call, shifted the origin point and passed new size of matrix.
b. Given a pair of brace {}. Validate it. (Code)
Soln: using two variables (i.e open_count and close_count) and proceed further.
c. What if we have multiple types of braces? (Approach)
Soln: Using stack.
2) (Telephonic round 2)
a. Given list of songs. How would you shuffle it? (Code)
Soln: Gave various approaches from naive to optimal. The optimal one was similar to
shuffling of array of ints.
b. Give list of words. Print all anagrams together. (Code)
Soln: Used Hashmap with key as “sort(str[i])” and value as List which is anagrams.
3) 3: In-house 1
There are various varieties of clothes (say shirt). Varieties are based on parameters like
pattern, size, colour, etc.
a. What will be your input format so that it can store all values of all parameters?
List<List<String>>. Each List<String> denotes values for a particular parameter
b. Design a class for a shirt for the same requirement.
c. You have to return all different types of shirts that can be formed based on various
combinations of input parameters. (Code)
d. Assuming you have all types of shirts available. Now there are various queries like:
i. Show all types of shirt having colour “red”,
ii. Show all types of shirt having size “small” and pattern “check” etc. etc.
So how will you store I/P so that this requirement can be fulfilled efficiently?
4) In-house 2
a. Given a Binary Tree. Assuming each node denotes some x,y coordinate. root node
denotes (0,0). Write a code to display coordinate of all nodes.

128
Chapter 39. Set 38 (SDE-I)

case (i): Tree is complete and no node’s x-coordinate is overlapping. (i.e all nodes will
expand along x-axis so that no node overlaps). (Code)

o(0,0)
/ \
o(-1,-1) o(1,-1)
/ \ / \
o(-2,-2) o(-1,-2) o(0,-2) o(1,-2)

Here we can see that many nodes are overlapping over x-cordinate.
case (ii): Tree is incomplete and no node’s x-coordinate is overlapping. (Approach)
case (iii): Tree is incomplete and node’s x-coordinate can overlap. (Approach)
b. Design a DS to perform
Insert
Search
Delete
get Random
All in O(1).
Soln: Focus on Delete and get_Random. On further analysis, only get_Random was re-
quired to me modified. Only a bit of tweak will serve the purpose.
5) In-house 3
a. Given array of ints. Assuming total no. of elements is even. Need to tell whether this
array can be grouped in sets of pairs such that sum of each pair is divisible by K.
eg: 0,2,4,8,12,20,18,4 and k=4
so (0,8), (2,18), (4,20), (4,12) is one such set in which sum of each pair is divisible by k.
(Code)
b. There is a vertical rod. Discs of various radiuses are inserted in it. When we will try to
take out any disc then 1st all the discs above it has to be taken out. Taking out a disc and
putting it back is counted as one step.
Considering this, what will be the minimum no of steps in which these discs of various radius
can be stored in sorted order in the rod.
Only minimum no of steps was required. “How to sort” was not required. (Approach)
c. Given array of ints. find ar[i],ar[j] such that j>i and ar[j]-ar[i] is maximum. Famous
problem. (Code)
6) (Semi Technical- Hiring Manager)
a. Normal HR questions. Why Amazon over your previous company, some areas where you
want to improve, define dream job and similar other questions as per the discussions.
As per feedback: my answer for “Why Amazon over prev company” was not clear here.
b. Given two arrays of ints of size m and m+n in sorted order. merge it inplace. Famous
problem. (Code)
c. Given string.
Qusn: Find the char occuring max no of times.
Soln: Simple one. Take auxillary array of size 256 and maintain frequency of each char.
Scan auxillary array and get the required char. O(k+n) where k=256 here.

129
Chapter 39. Set 38 (SDE-I)

Counter Qusn: Why O(k+n)? Why can’t it be O(n) only?


Soln: At the time of maintaining freq of each, compare to get max freq char also. No need
to travel aux array again. O(n)
Counter Qusn: What if memory size is only 100 bytes?
Soln: Detailed one.
Counter Qusn: Assuming updating freq of each char takes 1sec, so it will take N secs roughly.
How can we improve it?
Soln: Use multi threading for parallel programming.
Counter qusn: Will there be any issue?
Soln: In case one aquires lock, other one that needs lock will go in waiting. This adds extra
time and so can take more than N secs.
Counter Qusn: How to improve this?
Soln: Detailed one.
And many more such counter questions.
7) (Amazon Seattle. Semi HR. Analysis of thought process- BAR RAISER)
a. Again same question. Why Amazon over previous company?
This time I was prepared �
b. One +ve point and one -ve point from amazon india site.
c. Was prepared for this and already did some pre analysis on the site.
Many more such HR questions.
d. Analysis of thought process:
Assuming a new building is going to be constructed for IT official purpose. 75 floors. You
are builder. This building will be on lease for diff companies.
i. How many lifts you will add in that building?
ii. At which floor each lift will stop?
Note: At each step, I had to identify the required data after analysis and then only data for
the same was provided.
Soln (i): (As it is totally based on thought process, so counter question from your side is
good point)
1. No of Lifts are determined by many factors. Major factors are height of lift and no of
persons working in that building.
2. I was knowing height of building. To calculate no of persons, I asked size of each floor.
It was 100 sq m each floor.
3. Each floor will have cubicles and other rooms and passages. Assuming 70% of total area
is used by cubicles.
4. Each cubicle will have 4 persons. After calculation it came to be 40 employees per floor.
So 3000 employee in whole building.
5. Next analysis was: In most of the IT company, the in/out timing is flexible. Generally
in time is b/w 9:00-11:00 and out is b/w 5:00-7:00.
6. We have 2hrs of window in which all employee will use the lift. So no of lifts will depend
on this factor also.
7. After calculation, it came out to be approx 9 lifts (which was a good no according to
him).
Soln (ii): Now the qusn is at which floor each lift will stop.
8. AS we don’t know how many companies will be there in this building at any time, so it
is advisable to provide equal chance for employees on the basis of floor no. rather than on
the basis of company.

130
Chapter 39. Set 38 (SDE-I)

9. Best way would be to minimise the no. of stops of each lift.


10. This can be done by giving each lift equal no of floors on which it will stop.
11. It can simply be calculated as 75/9= 9 (round off).
12. So 1st lift will have floor buttons b/w 1-9, 2nd will have b/w 10-18 and so on.
13. This approach was best (according to him) for current scenario.
14. Remember that each floor should get equal chance and we don’t know how many
companies will be there.
Tips: Geeksforgeeks, Careercup, Cracking the code Interview (Book) +++++.
Finally got offer in few days. � Very satisfied.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-38/

131
Chapter 40

Set 39 (SDE)

Amazon Interview | Set 39 (SDE) - GeeksforGeeks


I recently attended the walk-in process for Amazon Off campus recruitment drive. This was
for SDE position at Chennai. I would like to share my interview experience with Geeks for
Geeks.
Written Round :
a) Given a linked list and 2 integers M and N.. Keep M nodes and delete N nodes repetitively
till the end of linkedlist.
b) Given a BST , replace a node value with the sum of all the elements larger than the
current node.
I could solve it with Reverse Inorder traversal and an int pointer to keep track of the
sum.
c) Given a BST and a value , check if the path sum from root to leaf equals the given value.
1st F2F round:
a) Multiply two linked lists represented by numbers. Only one linked list must be used to
do all additions and store the result i.e., intermediate additions should not be done with
extra linked lists and finally computing the result.
b) Given a BT check if there is a BST in it. If it exists print the largest BST in the BT.
c)Given a large file with huge number of words group the anagrams of a word
hai how are you. iahohw done woh.
o/p:
hai ->iah
how ->woh ->ohw
done
are
2nd F2F round:
a) Given a linked list , print the nth last node. He asked me to give the optimised solution
for it.
solved using slow pointer.

132
Chapter 40. Set 39 (SDE)

b) Find the LCA in Binary Tree


He asked me to optimise the code with bottom up approach and gave lots of boundary
conditions
c) Given a zigzag traversal construct a tree from it. Full working code was asked.

eg. 1 3 2 4 5 6 7 9 8
1
2 3
4 5 6 7
8 9

Solved it with double ended queue.


3rd F2F round :
a) Given a chess board of finite length , start postion of a knight , an end position.
->find whether the end position is reachable by the knight.
-> Number of minimum hops required to reach that position.
I came up with a BFS solution instantly . He posed several conditions in the same
question as I have seen the question already.
b) He changed the question to infinite length chess board and if given two knights in a chess
board .find minimum hops required for them meet.
->gave a lot of space and time constraints.
->asked me to write the complete code without STL.
c) if we encode A-1 , B-2 , C-3 , I send a word CAMP encoded as 311316. It can be decoded
as 3 11 3 16 (CKCP), 3 1 1 3 16(CAACP) , 3 1 1 3 1 6 , (CAACAF) . given a input encoded
string find the no. ways it can be decoded. (ACODE prob. in Spoj)
311316 – 4
->Could n’t come up with DP solution at first so gave a solution with recursion tree.
He asked me to optimise to avoid unnecessary computations.. Finally Solved it using DP.
4th F2F round ( Bar Raiser Round):
The Round started with the projects I have done so far. Few basic questions in cloud
computing. I have used Amazon Web Service (AWS) in one of my projects.
a) Lots of questions on AWS . Why we used it when there are so many alternatives.
b) When i convinced him with scalability issues, he posed questions on how AWS handle
load Balancing and scalability issues .
c) Obviously questions on Elastic Map Reduce and Elastic Block Storage. Questions
piled up until I could explain every nook and corner in that project.
d) Strengths and Weakness.
e) Why Amazon and why do I leave my previous company within 2 months.
f) Given a linked list with random pointers , clone the linked list.
Gave few solutions and he asked me to clone without manipulating the original linked
list but with extra space. Came up with little tweaks using HashMap
Map< node * , node *> key is the node and value is the random ptr node.
g) Find the ceil and floor of a value in a given BST without extra space.
if a BST contains 1 3 6 7 9 12

133
Chapter 40. Set 39 (SDE)

->if the given value is 8 floor is 7 and ceil is 9.


->if the given value is 9 both floor and ceil is 9.
P.S. Be cautious in explaining your projects.
5th F2F round: (Hiring Manager Round):
Few questions on projects and advantages of AWS.
a) Asked me about the different inter process communication methods.
b) Which method is faster and why. Then he asked me to explain about shared memory
c) Asked to write the code to implement LRU cache.
d) Then code for malloc implementation given an array.
e) He asked me to write a thread safe code for the given scenario.
given two writer threads and two reader threads . give a mechanism to handle the writer
and reader threads. The writer thread writes a value 1 2 3 4 in a queue or array and reader
thread reads it and print the output as 1 , 2 ,3 ,4 …..In the same order as given and only
once…
->i handled it with a binary semaphore and a single queue for both reader and writer..
f) conditions for a deadlock and he asked me to associate with the real life scenario.
mutual exclusion and all the cases.
g) Different types of scheduling and what type of scheduler does linux have and why.
h) doeslinux have preemptive scheduling and few questions on virtual memory.
He just analysed my approach towards the problem and checked my basic understanding
in OS concepts.
Finally got offer from Amazon after two days. I owe a great thanks to GeeksForGeeks. It
helped me a lot to improve my data structure and problem solving skills. Hope this will
help you. All the Best .
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-39/

134
Chapter 41

Set 40 (On-Campus Round 1)

Amazon Interview | Set 40 (On-Campus Round 1) - GeeksforGeeks


20 Objective type questions (Technical: OS, Java, Networking) and 2 programs. Time given
was 90 minutes.
1) Longest Remaining Rime Scheduling
2) Threads
3) subnetmask – classB – 64 departments
4) Match the following
SMTP
BGP
TCP
PPP
5) On recursion, value of f(513,2)

if(n<0)
return 0;
else
return ( n%10 + f(n/10, 2) )

6) Complexity?

f(i) = 2*f(i+1) + 3*f(i+2)


For (int i=0; i < n; i++)
F[i] = 2*f[i+1]

7) Frog steps either 1, 2 or 3 steps to go to top. In how many ways it reaches the top?
Based on recursion, options

135
Chapter 41. Set 40 (On-Campus Round 1)

a) f(i) = f(i+1)+f(i+2)+f(i+3)+1
b) f(i) = f(i-1)+f(i-2)+f(i-3)+1
c) f(i) = f(i+1)+f(i+2)+f(i+3)
d) f(i) = f(i-1)+f(i-2)+f(i-3)
8) Based on java 2 questions, one from Exceptions
9) Preorder is given, we had to find out the postorder
10) Memory management, pa=32bit, la=36bit , frame size=2^12, first page entry, second
page entry
11) This question is from GATE CS previous question papers

for (int i=0; i < n; i++)


Fork();
No of child process?

Programs:
1) Print left view of binary tree
2) Sum of 3 linked list

Digit.. 123------1->2->3------------linkedlist1
234----2->3->4--------------linkedlist2
34567----3->4->5->6->7---linkedlist3
Output: 34924-------3->4->9->2->4

Sum(linkedlist1, linkedlist2, linkedlist3)


We had to print the linkedlist form of the digit.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-40-campus-round-1/

136
Chapter 42

Set 41 (On–campus)

Amazon Interview | Set 41 (On–campus) - GeeksforGeeks


The first round had 20 multiple choice questions covering C programming, Data structures,
Algorithms, Maths and puzzles, and a question from Networking and Operating systems.
The duration of the test was of 90 minutes and marking scheme was +1, -0.25
It also had 2 coding questions.
i) Given an array of numbers, find the minimum value of the absolute difference that can
be obtained from any pair of numbers from the array.
ii) Find the first non-repeated character in a string. If there are no such chars then return
-1.
There were 4 rounds of technical interview, no HR round. Following are the major questions
asked to me in the tech rounds. I had to first suggest the logic, discuss that with the
interviewer and then he asked me to code it up.
Round 1 –
1) Check if a given tree is a Binary Search Tree or not. Simple enough question.
2) You are given an array whose each element represents the height of the tower. The width
of every tower is 1. It starts raining. How much water is collected between the towers?
Eg. [1,5,3,7,2] – then answer is 2 units between towers 5 and 7.
Looks easy, but if you don’t observe well, then you might end up with the wrong logic like
I did at first. Also there are lots of possible corner cases. Luckily I could identify them all.
3) Given an array and a fixed window size X, you have to find out the minimum value from
every window. De-queue was not allowed. So I had to do it using 2 stacks.
Round 2 –
1) Some DBMS questions like how is database stored in memory,how an image stored in
database and a few more questions from it.
2) What is a height balanced tree. Give an O(n) solution to balance it. Then he changed the
definition of a balanced tree as- a tree is balanced if every node in a particular level should
have the same number of descendants (and not only direct children). And every node can
have any number of children. I had to design the class and then write the code for it.

137
Chapter 42. Set 41 (On–campus)

3) Given an array of integers, find an index such that if you split the array into two parts
the absolute value of the difference between the sum of elements in both parts had to be
minimum. After giving him the logic, he changed it to split it into 3 parts such that sum of
elements in all of them are equal. I had to code this one.
Round 3 –
1) There is a sentence that your friend knows, but while giving it to you, he lost all the
spaces. You have to dictionary with you. How would you reconstruct the original sentence
using it.
2) How to delete a particular node from a circular Linked list.
3) You are given an encrypted file. You don’t know the key used to encrypt it. Like A might
be mapped to B, B to some D and D to some other F. But you don’t know this encryption
scheme. You have the dictionary with you. How will you decrypt the file? I suggested lots of
solution like exhaustive searching, then using some variants to minimize the complexity. He
gave me just a one word hint- histogram. So I gave him a logic that counting the frequency
of every letter used in the dictionary. Then replace the most used letter in the file with
the most used in the dictionary. And then compare words with the dictionary. In case of a
mismatch back –track and use the second largest and so on. I also discussed with him that
it could also have high complexity in worst case, but he moved on.
4) What is indexing in DBMS. How will you implement an index.
Round 4 –
1) A complete path in a tree is from a root to a leaf. A k-heavy path is a complete path
whose sum of elements is greater than k. Write a code to delete all nodes which are not in
any of the k-heavy paths.
2) You have an array whose elements firstly strictly increase and then strictly decrease. You
have to find the point of change.
All the questions in all the rounds required the minimum possible complexity possible (both
time and space). And I had to write the code of my final solution as well. Finally the results
came and I was selected by them.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-41-campus/

138
Chapter 43

Set 42 (On-Campus)

Amazon Interview | Set 42 (On-Campus) - GeeksforGeeks


Following questions were asked during interview.
1. Given an array, find the longest increasing subsequence of size 3 with max product, all
numbers are positive.
2. Given 3 linked lists representing 3 numbers, add them and return the result as another
list (take care that your method handles overflows).
3. Find the lenght of longest path in a binary tree(diameter). I gave a O (nlogn) solution.
He wanted O (n) solution. did that
4. You are standing at 0 0 and you have to get to i, j. Find the number of ways. Did
that with recursion then with DP. Then he extended the question saying some edges are not
traversible. Then edges have weights, find min weight path.
5. Delete all leaf nodes in a tree.
6. Find the peak in an array, array is first increasing then decreasing. Peak is the max
element.
7. Given a binary tree. A complete path is defined as any path from root to leaf. A k heavy
path is a complete path with sum of node values on that path > k node values can be -ve
too. Delete all nodes in a tree which do not lie on any k heavy path.
8. Given a rotated sorted array, find the minimum element.
9. Infinite stream of bits is coming, after every bit comes, you have to determine whether
the number formed with bits till now is divisible by 3 or not, you cannot form the number
as it will overflow at some stage.
10. Imagine a binary tree lying on the floor with nodes as balls and edges as threads, you
are given a pointer to a node. When you pick the tree from that node up what will be the
structure of the tree. You have gravity changing the structure of the tree.
11. An array is given representing the colors of n jars, colors have values 0-99. When two
jars are mixed the resulting volume is same as volume of one jar. Smoke is color1*color2…

139
Chapter 43. Set 42 (On-Campus)

and resulting color is (color1+color2)% 100. Keep on mixing colors such that you end up
with just one jar with minimum smoke.
12. A question on paging, processes also.
Selected … thanks to geeksforgeeks team.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-42-on-campus/

140
Chapter 44

Set 43 (On-Campus)

Amazon Interview | Set 43 (On-Campus) - GeeksforGeeks


Questions asked in Amazon Interview.
Round 2: Written
1. Find the SQRT of a number.
2. Simulate Reversed level order traversal.
Three F2Fs.
F2F 1:
1. Given a binary tree, no two adjacent nodes have same color, but all leaves should be in
same color. You can fill only with two colors. Write a function to find whether a given tree
can be colored using above scenario.
2. Given a binary tree, change the right pointer of every leaf node to the next leaf node
(right to it but may be on different level).
3. Given a class with n people,where each people plays a game with all other people. Results
are with you. You have to arrange them in a queue with a condition that, a[i] should have
won a[i-1], for all I, you don’t need to care about a[i-2] . (a[i] may win or lose a[i-2]).
F2F 2:
1. Write prime numbers from 1 to 100000.
2. Another simple question from tree. can’t remember �
3. Question from probability. Given c containers, r red balls, g green balls. Give a condition
that if a guy randomly pick a ball from any of the containers, it should be red.(more
probable)
F2F 3:
1. Reverse a linked list iteratively, recursively.(Ice breaking question :P)
2. Given a matrix with 1s and 0s, u have to construct a matrix such that a[i][j]=1, if only
every element in ith row and jth column is 1, otherwise 0. You have to use constant space
and O(mn) time complexity.

141
Chapter 44. Set 43 (On-Campus)

3. Maze solve problem. Given a matrix with 1s and 0s, 0 represents free path, 1 represents
blocked area, and you can move in any of the 8 directions. Find the path from source to
destination and print it. Then he told me that he can change destination at run time. And
asked me to do for that.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-43-campus/

142
Chapter 45

Set 44 (For Internship)

Amazon Interview | Set 44 (For Internship) - GeeksforGeeks


The written round was relatively easy. It contained 20 multiple choice questions on basic
c, algorithms and finite automata. Some questions from OS and networking were there too
but were easy. Coding questions were:
1. Find the nodes of the tree as seen from the left view of the binary tree.
2. Rotate the given matrix by 90 degrees i.e. the first row becomes the last column and
second row becomes the second last column and so on.
Interview round 1:
Two questions were asked. One puzzle and the other coding question.
1. Given n coins for two players playing a game. Each player picks coins from the given n
coins in such a way that he can pick 1 to 5 coins in one turn and the game continues for
both the players. The player who picks the last coin looses the game. You have to tell that
for given n coins who looses the game?
2. Given a number n, find the number just greater than n using same digits as that of n.
Interview round 2:
1. Given in facebook find an efficient way to find the mutual friends between you and one
of your given friends.
Hint: hashing, dictionary data structure implementation
2. For two very long numbers given, find the product of these numbers in an efficient way.
Hint: using binary multiplication effectively.
Finally I got internship offer from them….:)
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-44-for-internship/

143
Chapter 46

Set 45 (For Internship)

Amazon Interview | Set 45 (For Internship) - GeeksforGeeks


Hello everyone! Recently I sat for an on-campus internship recruiting process of Amazon.
The process consisted of a written round followed by two face to face interviews.
Written Round:
This round consisted of 20 MCQs and two coding questions. We had to complete the test
in 90 minutes. The MCQs mainly focused on C and general aptitude. They were easy to
solve. The students having faster question solving skills were in advantage! The two coding
questions were:
1. We were given the edges of the graph and we had to find if a cycle exist in the graph or
not.
2. Given a binary tree, we had to print all the nodes in the Zigzag order.

For the given tree, we should print: 1324567


A total of 18 students were selected for the next round from around 150+ students.

144
Chapter 46. Set 45 (For Internship)

Face to Face Interview:


The interviewer started with the question about what projects I have done. I explained
the two recent projects which I did. Then he started asking technical questions. He asked
about:
1. Given a sorted array which has been rotated, we have to find the point of rotation.
I did it in O(n). Then he asked me to write a more optimized code. I then did it in O(log
n) using modified binary search.
2. About heaps, maps.
3. About Job Scheduling.
4. Scaling of websites as one of project was an online portal.
Then he asked me if I have any questions. I asked about how to improve. He said that I
should blue practice the problems more and more. I should work more on algorithms rather
than solving the problems relating to the limitations of any language. He even emphasized
on the fact that companies like Amazon are looking for the students having good knowledge
of algorithms. He even mentioned that GeeksforGeeks is a perfect site for preparing for
companies like Amazon.
I was not lucky enough to be selected in the 2nd round of the interview but it was a
motivating experience. �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-45-internship/

145
Chapter 47

Set 46 (On-campus for


Internship)

Amazon Interview | Set 46 (On-campus for Internship) - GeeksforGeeks


Written:
20 MCQ on basics of C, OS, Networking + 2 Coding.
1) Left view of Binary Tree.
2) Rotate a matrix by 90 degree.
Interview (Round-1)
1. You have to find p,q of matrix p*q such that it fill n elements(n given) Such that
a) matrix should be nearest to a square matrix and
b) 0<=((p*q)-n)<=2 2. Zig-zag traversal of tree 3. You are given an array of length k
and it have numbers from 0 to n (where k>>>n) in O(n) time and no extra space find
occurrences of each element in O(n) time only
Round-2
1. You are given row and column wise sorted matrix you have to find and delete an element
such that it is still sorted in O(n) time.
2. Find if sum of any 2 elements in an array equal to k in O(n) time using extra space.
3. In a BST to every element add sum of elements greater than it.
Result –> Got Selected from Campus Internship Interviews.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-46-campus-internship/

146
Chapter 48

Set 47 (Off-campus for SDE-1)

Amazon Interview | Set 47 (Off-campus for SDE-1) - GeeksforGeeks


Round 1: Written
20 MCQs and 2 coding questions
(1) Mirror a tree.
(2) Find if an array has pair of elements with sum k.
Round 2: Telephonic Interview
(1) Given a number, find the next minimal greater number with same number of set
bits(Approach+code)
(2) Given a linked list with next and arbit pointer. Clone the list(Approach + code)
(3) AVL Tree(Approach)
Round 3: Telephonic Interview
(1) Given a number which denotes number of pair of parenthesis(only one type of parenthe-
sis). Print all the valid permutation of those parenthesis(Approach + code).
(2) Connecting all nodes at the same in Binary Tree(Approach + code )
Round 4: F2F(manager)
Discussion on all projects I have done.
(1) Convert BT to DLL(Approach + code)
(2) How to find if nodes in LL are odd or even(Approach )
(3) How to detect loop in LL(Approach)
(4) Segment Tree(Approach + code)
Round 5: F2F(Two interviewers)
This one was bar raiser I guess
(1) Convert a BST in such a way that every node contain sum of it and every greater element
than it (Approach + code)

147
Chapter 48. Set 47 (Off-campus for SDE-1)

(2) Garbage collector(Approach)


(3) Finding median in array(Approach)
(4) Finding k closest elements to an element in an array(Approach)
(5) Deleting a node from LL provided the tail nodes points to mid element. After deletion
property should be maintained(Approach)
Round 6: F2F(Senior guy)
A long discussion on projects.
(1) Circular Buffer array problem(Approach + code)
(2)BT is BST or not(Approach + code)
Round 7: F2F (Two interviewers)
(1) Given coins of 1,2 and 5 and given a number N. Find in how many ways you can make
the change(Approach + code)
(2) Swapping alternate nodes in LL(Approach + code)
(3) Swapping k nodes in LL(Approach)
Round 8: F2F(Again with manager)
Discussion on projects. Every positive , negative point he discussed on each projects
Now All HR type questions
(1) How will you handle conflict with teammate.
(2) How will you handle conflict with manager.
(3) Your teammate is not sharing required information with you. What will you do?
(4) If you are given 10 requirements and you don’t have to fulfill each and every requirement
what will you do?
(5) Given some languages which one you prefer and why?
(6) Given some tasks with one you prefer?
(7) If you are about to meet deadline and one of your teammates need some help.Would you
cross deadline to help him?
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-47-off-campus-for-sde-1/

148
Chapter 49

Set 48 (On-campus for SDE-1)

Amazon Interview | Set 48 (On-campus for SDE-1) - GeeksforGeeks


Recently, I have been through the interview experience of Amazon India and I would like
to share my experience with everyone.
Position: SDE- 1
No. of Interviews: 1 Written + 4 PI
Day 1:
Round 1 : (Written)
20 MCQ questions consisting of Data Structure, Algorithms, Operating Systems, Probability,
Combinatorics and Quatitative Analysis.
Coding Problems :
1. A string consists of parentheses and letters. Write a program to validate all the paren-
theses. Ignore the letters.
eg. ((alf)ls) – valid
)(dkk)() – invalid
2. You are involved in a betting game whose rules are as follows :
a) if you win a round, the bet amount will be added to your sum and next bet amount will
be $1;
b) if you lose a round, the bet amount will be reduced from your total sum and next bet
will be twice the previous.
c) game ends when all the rounds are complete or you dont have sufficient sum.
Initially, you are given with a string of the form “WLWWL” where W indicates a win and
L indicates a loss and initial sum. Initial bet amount will be $1.
Function prototypes and main was given for both questions.
Round 2 : (Face to Face)
Some discussion on my projects, and then a couple of questions.
1. An array of integers is given, find all the ranges present in the array.
eg. 1 6 4 2 3 — ranges will be {1-4} and {6}.

149
Chapter 49. Set 48 (On-campus for SDE-1)

I used sorting to solve this problem, so some follow up questions about which sorting tech-
nique i would prefer here.
What is the difference between merge sort and quick sort and when quick sort is preferred
over merge sort, etc.
2. Two strings are given. One of them is the initial string and other string contains characters
as per their priority. Sort the initial string as per the given second string. characters in
initial string may or may not be present in the second string. If not present, sort them in
lexicographical order at the end of output.
eg. String1 – ddloyc, String2 – odl
Output – oddlcy
Again, some discussion over various approaches to solve this problem.
Round 3 : (Face to Face)
Discussions over my projects.
1. (Reservoir sampling problem) https://www.geeksforgeeks.org/reservoir-sampling/
2. Generate all valid permutations of n pair of parenthesis. https://www.geeksforgeeks.org/
print-all-combinations-of-balanced-parentheses/
3. Given a bst, update the value of every node with sum of value of all nodes greater than
and equal to the value of current node.
Counter Question : I had used global variable for this purpose, so he asked me to solve it
without any global or static variable.
4. Inorder Successor of a node in bst.
5. Given a list and a number k, invert first k elements and leave next k elements. Repeat
this throughout the list.
Round 4 : (Face to Face)
1. N number of jars are kept in a linear fashion. Each jar contains a color whose value
ranges from 0-99. Now you can mix any two adjacent jars having colors ‘a’ and ‘b’ (both
integers), and it will produce a new color of the value (a+b) mod 100 and will also produce
smoke with value (a*b). Mix all the jars in a way such that in the end only one jar remains
and total smoke produced is minimum.
Day 2 :
Round 4 : (Telephonic with someone very senior)
He said that i must have been through many coding questions already, so he will start with
the basics.
1. What is the difference between C and C++ ?
2. Which one will you prefer, when and why?
3. What is the difference between C++ and JAVA.
4. Which is better, C++ or JAVA. Support your answer.
5. Give one use case where C/C++ can use pointers to solve it, but it can’t be done in
Java.
6. Again, some discussion over my projects. Which project i liked most and why? What
problems did i face during that
project and how i handled them.
7. Given a stream of 0’s and 1’s in which 0’s come first and then 1’s, find the first occurrence
of 1.
8. Design a data structure for phone-book of mobile phones. Implement it and discuss
about its benefits and limitations.

150
Chapter 49. Set 48 (On-campus for SDE-1)

In the evening they announced the result and i was hired!!! � �


Suggestions :- Write a neat code with indentations. It’s a good idea to mention all the test
cases(in case of an algorithmic problem) and all the use cases(if needed to design a data
structure) beforehand. And, don’t just respond to the questions of the interviewer, try to
interact with them.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-48-campus-sde-1/

151
Chapter 50

Set 49 (On-campus for SDE-1)

Amazon Interview | Set 49 (On-campus for SDE-1) - GeeksforGeeks


Recently, I have been through the interview experience of Amazon India and I would like
to share my experience with everyone.
Position: SDE- 1
No. of Interviews: 1 Written + 4 PI (3 F2F and 1 telephonic)
Before telling you the questions and interview procedure, I would like to offer some sugges-
tions. There are always instances when your interview is not off with a great start. You
need not panic and keep your calm. Secondly, to compensate all the shortcomings in the
technical part, interact with the interviewer as much as you can. Show him that you are
really interested in the company. They are looking for future managers not just coders, so
you have to have people skills.
Okay, so here we go:
Day 1:
Round 1 : (Written on Interview Street)
20 MCQ questions consisting of Data Structure, Algorithms, Operating Systems, Probability,
Combinatorics and Quatitative Analysis.
Suggestion: Always code your solution on the editor provided on the website. It takes
screenshots of the page so if you copy a large chunk of data even from your notepad that’s
considered as cheating.
Coding Problems :
1. A string consists of parentheses and letters. Write a program to validate all the paren-
theses. Ignore the letters.
eg. ((alf)ls) – valid
)(dkk)() – invalid
2. You are involved in a betting game whose rules are as follows :
a) if you win a round, the bet amount will be added to your sum and next bet amount will
be $1;

152
Chapter 50. Set 49 (On-campus for SDE-1)

b) if you lose a round, the bet amount will be reduced from your total sum and next bet
will be twice the previous.
c) game ends when all the rounds are complete or you dont have sufficient sum.
Initially, you are given with a string of the form “WLWWL” where W indicates a win and
L indicates a loss and initial sum. Initial bet amount will be $1.
Function prototypes and main was given for both questions.
Round 2 : (Face to Face)
The interview started off with a light discussion about myself, achievements. Then he asked
me about my project and the difficulties faced. Then we moved on to coding problems.
Q1: You are given an array in which you’ve to find a contiguous subarray such that the sum
of elements in it is equal to zero. (I coded using hashtable in java)
Q2: Given a binary tree. Find out if it is a binary search tree or not.
Round 3: (Face to Face)
Q1: You are given a generic tree. Design a structure for it. Now for every node of the tree
make the leftmost child of the node as a duplicate of the node itself and return the root of
the tree.
Q2: He: Tell me the time complexity of 8-queen problem.
Me: (I did not exactly remember the complexity so I coded)
Round 4: (Face to Face)
He asked me variety of theory questions, I was stumped as I did not know many things. He
asked me about ACID properties, oops concepts, SQL etc. out of which I could answer only
a few.
Then we switched over to coding.
Q1: He: You are given various time intervals and you have to merge the overlapping ones.
Me: I had already coded it in the Code Ninja questions on the amazon’s website, so he just
asked me the approach to the question.
Q2: You are given a binary tree. Tell me if it is height balanced or not.
Round 5: (Telephonic)
The interview started with if I had any questions, and then proceeded with the projects I’ve
done.
Q1: You are given a file with many words. You are given a word as an input and you have
to find every anagram of that word in the file.
Q2: Given two words, tell if they are anagrams or not. Extend your solution for unicode as
well.
Finally after a long wait of almost 8 hours the result came and I was hired!! � �
I would like to thank geeksforgeeks for all the pain they take in compiling every article so
that people may understand every concept clearly.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-49-campus-sde-1/

153
Chapter 51

Set 50 (On-campus for SDE)

Amazon Interview | Set 50 (On-campus for SDE) - GeeksforGeeks


Recently, I have been through the interview experience of Amazon India and I would like
to share my experience with everyone.
Number of interviews: 1 online exam (will be completely evaluated by the compiler itself,
then code of those who will clear the cut-off will be analysed by the hiring team) + 3 Face
to face technical + 1 Telephonic (Technical again)
Online exam:
20 MCQ: Aptitude questions, if you are good in logical reasoning then don’t worry about
it (basic permutation and combination), C output questions, and most of them were pretty
simple.
2 Online coding questions: 1. Print the first non-repeated character in a string.
2. Print the left view of a binary tree.
1st Face to face:
A skeleton of a binary tree with nodes having garbage values is given and an array is given.
Had to fill up the binary tree skeleton with the values in array such that the resulting tree
is a BST.
Solution: sort the array, enter the values in an in-order fashion (A long discussion on which
sorting algorithm is the best and why? We ended up discussing how merge sort can be
optimized, just “optimized”, not like reducing the order of time or space complexity). Then
told me to write the merge-sort function for the discussed solution for merge-sort such that
say I am a developer, I can’t test on a machine, and this class will be used by a million
number of users.
2nd Face to face:
Was asked 4 questions: Print all string permutation (String might have repeated characters).
Least distance between two values in a very big binary tree (Binary tree may contain same
value in many nodes).

154
Chapter 51. Set 50 (On-campus for SDE)

1 7
4 3 8 2
1

{Least distance is 3 between 1 and 2 (not 5). }


Vertically print the value in a binary tree. Like in the previous example:
4, 7
1
5, 3, 8
7
2
Next, I was asked to design an efficient data structure for two lifts in a building of n floors.
Round 3 Face to face:
Had to find maximum profit in an array of stocks prices for consecutive days in two cases,
one I can sell and buy any number of times I want, second, I can only buy and sell one time.
Another question was to define a function “inorder_it(Node A, Node root)” which will
return the next node in a binary tree to a particular node A. Was asked to write code for
both of them.
Round 4: telephonic:
Kind of HR + Technical, asked a lot about my internship project and other academic
projects. Then we discussed the problem of sorting rows of a file based on a particular
column. Like as in Excel file, you can sort file based on roll_no, first name, last name, any
column you want.
File is very large, so you can’t just store the whole file into memory.
Solution: sort it out yourselves.
All the best everyone.
And yes, I got through along with 5 other mates from my college.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-50-campus-sde/

155
Chapter 52

Set 51 (On-campus for SDET)

Amazon Interview | Set 51 (On-campus for SDET) - GeeksforGeeks


Hello Everyone!! Recently, I have been through the interview experience of Amazon India
and I would like to share my experience with everyone.
Position : SDET
No. of Interviews : 1 Written + 4 PI (3 F2F and 1 telephonic)
Suggestions : Your code should be optimal, have proper variable naming, consider all corner
cases and should not be lengthy.
Round 1: (90 minutes)
20 MCQs and 2 coding questions
Coding questions :
1. A string consists of parenthesis and letters. Write a program to validate all the parenthesis.
Ignore the letters.
eg. ((alf)ls) – valid
)(dkk)() – invalid
2. You are involved in a betting game whose rules are as follows :
a) if you win a round, the bet amount will be added to your sum and next bet amount will
be $1;
b) if you lose a round, the bet amount will be reduced from your total sum and next bet
will be twice the previous.
c) game ends when all the rounds are complete or you dont have sufficient sum.
Initially, you are given with a string of the form “WLWWL” where W indicates a win and
L indicates a loss and initial sum. Initial bet amount will be $1.
You need to find the amount at the end of the game.
Function prototypes and main was given for both questions
Round 2: (face to face) (1 hour 15 min)
1. Given a 2d matrix in which rows are sorted in ascending order and columns are also
sorted in ascending order .I need to find an element in optimal time complexity

156
Chapter 52. Set 51 (On-campus for SDET)

2. In the same (M X N) matrix I have to print the matrix in increasing order of elements
.write code for it(I used heap for that purpose and used concept of merging k sorted array).
3. Given an array , each element is one more or one less than its preceding element .find an
element in it.(better than O(n) approach)
4. Given two strings STR1 and STR2 .we need to find longest substring in STR1 whose all
characters are taken from string STR2(was asked to write code for it in optimal time)

STR1-abcdefacbccbagfacbacer
STR2-abc
ans : length : 7
acbccba (from position 7 to 13)

5. Given a binary tree. I need to print the nodes in vertical line zigzag manner. For example:
1st vertical line from top to bottom, 2nd vertical line from bottom to top,3rd vertical line
from top to bottom and so on

5
/ \
3 7
/ \ / \
1 4 6 8
/ \ \
2 9 10

Answer would be –
1
23
546
97
8
10
Round 3: (face to face ) (50-60 minutes)
I was asked about my project in details. He asked me project related questions for first 20
minutes.
Next he asked to convert a binary tree in a doubly link list.
I told him various approaches like by using space complexity and in-place conversion.
I was asked to code all those approaches.
Then he gave a hint about one more approach and asked to code it.
Round 4: (face to face) (60-70 minutes)
Again, I was asked about my project in details and he was questioning me on every part of
it. Next he asked me to name the subjects that I have studied so far � . He asked many
theoretical questions on database management systems, SQL, operating systems, OOPs
concepts and their real life examples and also two coding questions.

157
Chapter 52. Set 51 (On-campus for SDET)

1. Code for dfs of a tree(tree can be any general tree)


2. Print pascal triangle and your output should be same as pascal triangular form (have to
consider the space separation) .I told him two approaches and wrote the code.
Round 5: (telephonic) (1 hour 30 min)
For first 40 minutes he asked me about my achievements, about amazon company, my
project in details and what problems I faced in project and how I resolved them. next he
asked one coding question.
1. 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.
Finally, I was hired with three of my friends. � � :
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-51-campus-sdet/

158
Chapter 53

Set 52 (For Internship)

Amazon Interview | Set 52 (For Internship) - GeeksforGeeks


Hi All, Here is my interview experience with Amazon for internship. Hope it helps:
Round 1:
Online round with 20 objective questions on (Questions related to data structures, analysis
of algorithms, C Language and some puzzles.) and 2 coding questions in 90 minutes
Write a program to reverse k alternate nodes of a linked list
Ex: 1->2->3->4->5->6->7->8->9
If k is 3 Output should be: 3->2->1->6->5->4->9->8->7
Given a string. Write a program to form a string with first character of all words.
Ex: The bucket is full of water
Output: Tbifow
Check all edge and corner cases.
Round 2: Face to face round
Given a binary tree. Modify it in such a way that after modification you can have a preorder
traversal of it using only right pointers. During modification you can use right as well as
left pointers. Write complete code and dry run it for some test cases.
Given 2 linked lists. Find out if they intersect or not. If yes, find intersection point .Write
complete code for it.
I could not remember the simple way: find the length of the lists and simply move forward
the shorter list by difference of the lengths and find the intersection point. Instead, I joined
the end of first list at the end of the 2nd list and then went for cycle finding by Floyd
Cycle finding Algorithm. Although both are O (n), but he was impressed as it was a new
approach.
Round 3: Face to face round
Given a sorted array of 0’s and 1’s. Find out the no. of 0’s in it. Write recursive, iterative
versions of the code and check for all test cases.
All Practice Problems for Amazon !

159
Chapter 53. Set 52 (For Internship)

Source

https://www.geeksforgeeks.org/amazon-interview-set-52-internship/

160
Chapter 54

Set 53 (For SDE-1)

Amazon Interview | Set 53 (For SDE-1) - GeeksforGeeks


In each round they ask me why I want to join amazon, why I am leaving my previous
company with such a short span(around 2.5 months) and project stuff.
Interviewers were quite friendly. They would explain you till the point you fully don’t
understand. And even while discussing approach and solving, they would clear your doubts
if any.
Online Test on InterviewStreet
1. Given 2 string , find whether 2nd is sub-string of 1st or not. (it would be great if you
solve with KMP)
2. Given 2 rectangles , find whether they are overlapping or not.
3. Given list of coins with various values (unlimited coins of each type) , find how many
ways you can make a given value. (DP was expected.) Since it was not guaranteed that
coin of value 1 would be present , we have to return -1 if the given value is not possible.
All rounds on same day.
1st f2f:
First I was ask to introduce myself and give a brief over my projects. Latter he ask me to
explain any one of my project and the hardest task I have done.
We have used infix to post ix and postfix evaluation for our generic search expression’s
evaluation. Here we had a lot of discussion on why conversation from infix to post-fix was
needed and all.
1. Given a String s and int r , first fill each character row wise and print column wise.
for e.g. String s = “abcdefgh” and r = 3
so filling column wise would give :
adg
beh
cf
and final ans would be adgbehcf.
he just wanted the exact output. Internally how we handle string was not concern.

161
Chapter 54. Set 53 (For SDE-1)

2. given a string or say number .. for e.g. 134 now with each number , as per mobile’s
keypad , some letters would be associated.
here 1 – > abc , 3->ghi, 4 ->jkl . So we should print all the permutation such that we take
1 character from each of the number.
input number can be of any arbitrary length.
lets say each digit has m numbers associated , then for the input of length n , we need to
generate n^m possible strings.
Took a map of which would return all the letters for the number. solved it using recursion.
its quite similar to permutation of string. .
Interviewer seemed quite impressed here.
2nd f2f
1. Find integer part of sqrt of given number. Initially I gave o(root(n)) solution. Later
solved with binary search(O(logn)).
2. Given an array of integers. replace each number with next higher number on its right
side , which is nearer.(if not present than keep it as it is.)
for e.g. input – > 3 4 6 1
output->4 6 6 1
I suggested we can traverse from right side , we will take extra array (o(n) space complexity
here) and in that array , we would store index of next higher nearer number.
so it would be like

if (a[i] < a[i+1]


then store i+1;
else
traverse using index stored in auxiliary array

Since we needed extra space to store indexes, he asked that the input is array of a structure
which has number and higher Index, 2 fields. So that we don’t need extra space and extra
traversal.

class Node {
int val;
int higher;
}

He was very interested to see how i keep track of indexes and how i traverse between them.
It is o(n) with o(1) space complexity. (when we have a[i]>a[i+1] we don’t do linear search ,
but we jump using the indexes, so its not o(n^2)) It was hard to convince him on complexity.
3. given a binary tree. connect all the node at the same level. each node would have
left,right and nextSibling pointers. we need to fill nextSibling.
solved with level order traversal . Similar to BFS on tree with queue. Only approach was
needed, no code for this one.

162
Chapter 54. Set 53 (For SDE-1)

3rd f2f (Hiring Manager)


1. It was a design question. You have to design a game. it has different types of monsters
and different weapons. hero would shoot monster. each monster would have some initial
health. Each weapon would do some predefined damage to monster. when its health gets 0,
monster would die/disappear. and there would be multiple levels. based on level, monster
and their behavior would change.
2. Given a read only linked list with next and random pointer , clone the list. I told him
that i know the solution and explained him the approach. It was with the use of hashmap
and takes o(N) extra space. Then he ask me whether I know a o(1) space solution, since I
didn’t knew, i was told to solve this. With this , he told that I can modify link list.
Initially I struggled, but with his help, in the end came up with working code. He was
looking fine with implementation.
Here I ask about the work culture and the process being followed at amazon.I ask lot of
questions regarding tools and technology they use. Since I had work on scrum model , it
was quite interesting. He seemed to be impressed here.
4th f2f(Dev Manager)
1. Given 2 sorted linked list , merge them into single sorted list. Change the pointers, don’t
copy data. (same as merge part of mergesort on SLL)
2. Given binary tree, connect all the nodes which are in same column. 1 caveat was that
same 1 node can have 2 parents. Here as in example, node 7 is being pointed by 2 and 6.
Solved it using level order traversal. Used a Map : columNo, Node. it would store the last
visited node of that column. So whenever we visit a node, first we check if its corresponding
column is present in hashmap. if not , it means its the first node of column, put into map.
if the column present , then we will get the node stored in map and current node would be
its nextVerticleSibling. and we update the map.
He deed the dry run with example and code and he was OK with final approach.

1
/ \
2 6
/ \ / \
3 7 8
/ /
4 12
/ \ \
5 9 13
\ \
10 14
\
11

Finally after two days, I got call from HR that I am selected �


All Practice Problems for Amazon !

163
Chapter 54. Set 53 (For SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-set-53-sde-1/

164
Chapter 55

Set 54 (For Internship)

Amazon Interview | Set 54 (For Internship) - GeeksforGeeks


Hi All. Here is my interview experience for internship at Amazon.
Position: 2-Month Intern
No. of Rounds: 1 Online + 2 PI (2 F2F)
Round 1: (90 minutes)
20 MCQs and 2 coding questions
There were 20 MCQs based on C output, probability, basic maths, OOPS, algorithm analysis
and Operating Systems.
Question 1: Given a linked list, write a function to reverse every k nodes (where k is an
input to the function).
Example:
Inputs: 1->2->3->4->5->6->7->8->NULL and k = 3
Output: 3->2->1->6->5->4->8->7->NULL.
Inputs: 1->2->3->4->5->6->7->8->NULL and k = 5
Output: 5->4->3->2->1->8->7->6->NULL.
Question 2: Given a string containing words separated by arbitrary number of spaces.
Write a function that returns a string consisting of the first letter of each word. (Note:
there may be any number of spaces at the starting of the given string, at the end of the
given string or in between words of the string.)
Example:
Input: ” this is a test case ”
Output: tiatc
(Function prototypes and main was given for both the questions. Although many solutions
passed the initial test cases, they were rejected later as they did not satisfy boundary cases.)
Round 2: (face to face) (1 hour 20 min)
Question 1: Given two numbers represented by two linked lists, write a function that
returns sum list. The sum list is linked list representation of addition of two input numbers.
Example

Input:

165
Chapter 55. Set 54 (For Internship)

First List: 5->6->3 // represents number 563


Second List: 8->4->2 // represents number 842
Output
Resultant list: 1->4->0->5 // represents number 1405

I reversed the linked lists and simply added the corresponding nodes along with the carry.
Then he asked me to solve the question without reversing the list. Then I solved the question
iteratively without reversing the lists.
The interviewer then asked me to write a recursive code for the same problem.
After that he asked me to modify the code so that the carry at each place is passed by value
instead of using pointers(which I had used in my code).
Question 2: iterative and recursive code to reverse a linked list(Take Care of corner cases:
when list has no nodes or contains a single node)
Question 3: Write a function to check whether a binary tree is a sub-tree of another binary
tree (Check for all corner cases).
I solved it in O(n^2) time complexity. He did not ask me to optimize my code.
Question 4: Which data structure would you use to keep records of stock market?
I asked him to clarify the problem statement.
He then asked me : Suppose you have to maintain the stock values of various companies
during various periods and return minimum stock value of a particular company over a given
period of time.
I answered segment tree (Probably the correct answer was queue data structure).
However the interviewer proceeded with questions on segment tree.
He asked me to write a code for
a) Creating a segment tree
b) Performing range minimum query in a segment tree
c) Updating the segment tree
He asked me to analyze the time complexity for building the segment tree and performing
the range minimum query in the segment tree.
He then asked me: If you are to maintain the stock value of a company for the past 6
months..then you have to update the segment tree every day by deleting a stock value and
inserting a new stock value. How would you do that?
Here I got stuck and could not perform the updation in better than O(n) time.(However
using queue it can be performed in O(1) time) .
He finally asked me if I had any questions.
Round 3: (face to face) (20 min)
Only one technical question was asked to me in this round.
a) He asked me to speak something about myself and my technical achievements..
b) How to store a binary tree in a file & then read back.(It is not necessarily a BST)
First I answered that I would store level-order traversal of the tree.
He then asked me how I would maintain the nodes at various levels (which I was unable to
answer). So, I changed my approach and told that: I would store in-order and pre-order
traversals of the tree from which the original tree can be easily retrieved.

166
Chapter 55. Set 54 (For Internship)

But then he told me to optimize my approach (As this approach would require twice the
original space to store the data in the nodes). I could not further optimize my approach
(However the better approach was to use parenthesization.

A
/ \
B C
/ \
D E

If this is the binary tree then it can be stored as (A(B(D),(E)),(C)) in the file.)
c) Then there was a 10 min discussion my project , the problems I encountered and how I
solved them.
d) Finally he asked me if I had any questions.
I asked about the intern projects at Amazon and the use of DBMS and NETWORKING in
it.
He started elaborating the entire work-process at Amazon and his work-experience……..most
of which I could hardly understand. He also told me to have a good knowledge of JAVA as
it will be required at some stage during the projects.
Finally I got selected.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-54-internship/

167
Chapter 56

Set 54 (Off-Campus For SDE-1)

Amazon Interview | Set 54 (Off-Campus For SDE-1) - GeeksforGeeks


It was a usual interview process by Amazon: 1 written test, 1 telephonic interview and 4
f2f interviews.
Sometimes they just want efficient algorithm and sometimes just concise and efficient produc-
tion level code is required. Mostly both, algorithm and code, are asked for every question.
Interviewers were very friendly. In the first f2f interview, I was extremely nervous and
stumbling in answering the first question itself, the interviewer told me not to worry and to
take as much time as I want. That expression by him made me calm after some time and I
was able to solve the question with ease.
Solutions to some of the problems are provided at the end of the article.
Written test(same questions as Set-53 Amazon Interview Experience):
1. Given 2 string , find whether 2nd is sub-string of 1st or not. (it would be great if you
solve with KMP)
2. Given 2 rectangles , find whether they are overlapping or not.
3. Given list of coins with various values (unlimited coins of each type) , find how many
ways you can make a given value. (DP was expected.) Since it was not guaranteed that
coin of value 1 would be present , we have to return -1 if the given value is not possible.
Telephonic Interview:
1. You are given an array of integers. You have to find the index in array from where (sum
of left elements)=(sum of right elements). The elements itself is excluded.
2. Delete a node from an unordered DLL. Algo is quite simple. Clear and concise code was
required to be written.
3. Zigzag traversal of a tree. He asked me if I know this question. I said yes and we moved
on to other question.
4. You are given an array of integers(positive and negative). You have to find if there exists
any sequence of numbers in it which has the sum zero. If there is any print the start index
else print -1.
For example: 1 2 3 -1 4 -3 2 is the array and the sequence is -1 4 -3 which returns sum as
zero.
Code and algorithm, both were required.

168
Chapter 56. Set 54 (Off-Campus For SDE-1)

F2F Interview 1:
1. Find the longest even length palindromic substring in a string.
2. The interviewer asked me what are the data structures I know. I told him many of them.
He chose HashMap and asked many detailed questions about it.
F2F Interview 2:
-Tell me about yourself and the work you are doing currently.
1. Write power function. Eg. 2^3=8. Optimize it as much as you can. Simple.
2. Longest path in a Binary tree.
F2F Interview 3:
-Tell me about yourself, your work, strengths and weakness, challenges you have faced in
current job, why Amazon.
1. I don’t remember it exactly, but it was probably : Delete a node with value K from
unordered Circular Link List. Algo is straight forward. Production level working code was
required.
2. Make OO design for 2-players game of chess.
3. You have some packages and you have to decide the build order for them.
A package should be built before the packages that depend on it.
For example. A={B,C}, B={D}, C={}, D={E}, E={}, F={}
So one possible build order for package “A” is E, D, B, C, A.
You have to write a function which will take the package name and will return its build
order. You have API which will return you the list of packages on which calling package
depends on. For example, the API will return B and C in a list when you call it providing
the parameter as package A.
F2F Interview 4:
-Tell me about your work and challenges you have faced.
1. You are given a binary tree in which every node has left, right and a next pointer. Next
pointer is null initially.
You have to modify the tree in such a way that every node’s next pointer will point to the
next node on the same level.
O(1) space complexity code was required to be written.
Eg.

1 1
2 3 ======> 2----------------->3
4 5 6 4-->5----------------->6

ANSWERS:
Telephonic Interview:
1. It can be a recursive procedure.
For example, for 7 3 1 4 5 6. I can write a procedure like “public int getEqualSumIndex(int
index, int left_sum)”
I can call it recursively like this: int right_sum=getEqualSumIndex(index++,
left_sum+arr[index])
Can have return sum like this: right_sum+arr[index];
I can compare the sum like this: left_sum==right_sum

169
Chapter 56. Set 54 (Off-Campus For SDE-1)

The code is very easy to write.


4. I came up with this algo: Start from left and get sum_till_now by adding the current
element. Store the sum_till_now and current index in a HashMap.
If a sum value is repeated, then there must be a sequence in the array which is giving the
sum zero. (repeated sum value’s corresponding index)+1 will be index of the start of the
sequece summing up to zero.
F2F 1:
1. Initially I thought it was a DP problem due to its resemblance with the problem “longest
palindromic substring” and tried to modify that DP solution. But since it is an O(n^2)
space complexity solution, I was told to do it in O(1) space. After some time I came up
with a simple iterative solution. Find two same characters in the string and then expand
its left and right as much as possible. It is an O(n^2) time solution. I coded the same.
F2F 2:
2. https://www.geeksforgeeks.org/diameter-of-a-binary-tree/
F2F 3:
3. If you can relate it to a graph, it is actually topological sorting. Though I didn’t remember
the name of the sort at that time, I explained him the concept, and how we can modify DFS
to get the build order. I coded the same. He told me the name of algo afterwards.
https://www.geeksforgeeks.org/topological-sorting/
After two days I got the call that I have been selected.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-54-off-campus-for-sde-1/

170
Chapter 57

Set 54 (On Campus for SDE)

Amazon Interview | Set 54 (On Campus for SDE) - GeeksforGeeks


Hi All, I got the following question for the On-Campus placement process. Hopefully it’ll
help you too.
Screening Test
Q1. Left View of a tree
Q2. Add three numbers represented as linked lists
example
n1: 1->2->3
n2: 4->5
n3: 6->7->8->9
sum: 6->9->5->7
Round 1 (F2F Interview)
Connect same level nodes without level order traversal. (Code)
Given an array where all numbers but one occurs in pairs, suggest all ways to find the unique
number. What if the array was sorted? (Code)
Round 2 (F2F Interview)
Print cousins of a given node (Not sibling)
Given a 20 GB file and 2GB RAM, how to parse it and detect where to break it, concepts
of memory management
Implement 3 stacks in array, all approaches and code
Deepest left leaf of a binary tree
Round 3 (F2F Interview)
Longest path in a tree with just one bend. May or may not start with from the root.
(Complete code)

171
Chapter 57. Set 54 (On Campus for SDE)

Code for deadlock and how to resolve.


OOPS concepts, polymorphism
Round 4 (Telephonic Interview)
Check if a tree is a subtree of another. (Code)
Convert a given number to Roman numbers.
Thanks a lot to the GeeksforGeeks team again. Appreciate the hard work you guys have
put. Also a big thanks to all the contributors.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-54-on-campus-for-sde/

172
Chapter 58

Set 55 (On-Campus)

Amazon Interview | Set 55 (On-Campus) - GeeksforGeeks


Online Test on InterviewStreet:
18 MCQs (Normal C loop questions, networking, dbms, os, analytical)
2 Coding questions
1. Check if an undirected graph is a tree or not.
2. Given an array of integers, print the 2 elements with least absolute difference.
Interview Rounds:-
Round 1:
Tell me about yourself.
1. Given a matrix(not necessarily square) in which the elements in a row, as well in a column
are sorted. Find a given integer in the matrix.
Tell the approach. And then code.
2. Given a position where a knight is placed on an nXn chessboard. Find the maximum
number of knights that can be placed on the board, so that no 2 knights attack each other.
Remember that you need to just give the number of knights, not all their positions. I
first could arrange ceil(n*n/3) knights. Then he asked me find a better solution. Finally
I got to ceil(n*n/2). Then he asked me to code it. Then he asked me to remove the ceil
condition(check for even and odd separately).
He asked me if I had some question for him. I asked – Amazon strives to be the most
costumer centric company on earth. What, as a programmer/developer, do you do to
achieve this, because generally, the customer’s problems are an issue for high level managers
and planners.
Round 2:
Started with some questions from my Intern project.
1. Given a Binary Tree, replace the data of each node by the sum of data of all its descendent
nodes.(Leaf nodes will have 0)
2. Given a sorted array of positive integers, find the least missing positive integer. First I
gave an O(n) solution. Then he asked me to optimize it. Finally I gave an O(log n) solution.
3. Given a stream of numbers, find k random numbers from them. I explained him Reservoir
Sampling approach. He asked why this approach works. What is the probability of each

173
Chapter 58. Set 55 (On-Campus)

number being selected? What is the probability of any number being selected if stream has
less than k numbers(its 1).
He asked me if I had some question. I said I had one, but I already asked it to previos
interviewer. He asked me if I got a satisfactory answer to it. I said the answer was very
much satisfactory.
Round 3 (CS Round):
He asked me if I am comfortable with writing SQL queries. I prefered not to.
1. What is an interface? Why it is used? Give an example. What is an abstract class? Why
it is used? Give example. Why 2 different concepts of interface and abstract class?
2. Do you know about singleton class? What is it? Implement a simple singleton class. I
made some mistakes in making attributes static etc. He guided me and finally I corrected
all bugs.
3. Given a binary tree, where each node has an extra next pointer. Fill the next pointers so
that each node’s next pointer points to its next sibling node. First I gave a solution where I
would require a map, where each map key will be a level number, and value will be pointer
to the last currently accessed node of that level. Then he asked me to do it without space.
Finally I gave him a solution without space. I gave a non-recursive approach, and he asked
me to code it.
Round 4(Senior SDE 3 from Seattle Office):
He told me about himself, his team, his work and his team’s work.
1. Tell me about one of your challenging project/internship/class assignment.
2. Give a situation from your life where you were given a negative feedback, and how did
you tackle the situation.
3. Explained me a cache situation, where, keys will be in cache, and each key will point to
a string. It was LRU cache condition, and I had to implement the LRU cache. Then write
a function to retrieve a string, given its key, from this cache. Retrievel should be O(1) (if
you give O(n) retrival, he will ask you to make it O(1) ).
Finally got an offer !! � �
While you are answering a question, clarify any doubts that come to you mind. Dont take
any assumptions by yourself at all.
Keep on speaking your approach as you think. Keep speaking, if possible, even when you
write code. They want to test if you really know the approach, and not just copying code.
All rounds were technical and elimination. The last round has the highest weightage in their
procedure. Write clean code, ask for some time if you want.
Thanks a lot to the GeeksForGeeks team for helping with interview preparations! �
All Practice Problems for Amazon !
Save Knights

Source

https://www.geeksforgeeks.org/amazon-interview-set-55-on-campus/

174
Chapter 59

Set 56 (Off-Campus)

Amazon Interview | Set 56 (Off-Campus) - GeeksforGeeks


The most important thing about Amazon interviews is that you need to produce Flawless,
Most Optimal solution in the First try itself. Take your time to think, but when you code
make sure you Cover every edge case before handing your solution to the interviewer.
Online Round (90 mins)
20 MCQ questions spanning Aptitude, basic C/C++ skills
2 Coding Questions
-> Vertical Sum in binary tree
-> Add 2 link lists
Phone Screen ( PS1 ) ( 45 mins)
Basic questions about OS. Virtual memory, multi-threading, etc.
-> Next Greater number for every element. ( Algo + Code )
-> Reverse link list ( Algo )
-> LCA in Binary Tree ( Algo + Code )
F2F Interview 1: (45 mins)
-> LCA of K given nodes in a n-ary tree .( Algo + Code )
-> Sliding window minimum . ( Algo + Code )
Discussion about Internship project .
F2F Interview 2: ( 60 mins)
Discussion about Internship project .High level Design was to be produced
-> Given a boolean 2-D matrix, find the number of unique rows in it.( Algo + Code )
I gave 3 diffrent solutions.One of them used Hashing .The interviewer then went into GREAT
details of hashing .
After a lot of discussion about various Types of hash implementation,pros/cons,uses , he
gave me a Scenario for which i needed to build a good hash function.
F2F Interview 3(Stess Interview) ( 60 mins)
Discussion about Internship project .
-> Given a Binary tree and a arbirary node of that tree , find all the nodes at a Distance of

175
Chapter 59. Set 56 (Off-Campus)

K from that Node .Nodes DON’T have parent pointers.( Algo + Code )
-> Implement 2 stacks in an array .( Algo + Code ) .
Follow up question ->What do we do if we want to change the size of array dynamically.
-> Implement 3 stacks in an array .( Algo )
-> Implement K stacks in an array .( Algo )
F2F Interview 4 ( 60 mins )
-> Lot of OS questions . Mutex,semaphore,Deadlock ,Virtual memory , Scheduling algos .
Then he gave me a Code, and asked to make it Thread Safe .
I had used SQL in my intership project, so was asked basic DBMS questions and SQL
queries.
SQL query to find maximum in a column, without using aggregate MAX function .
-> 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
6->5>4 654
Answer = 632 + 6375 + 6354 + 654 = 13997

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-56-campus/

176
Chapter 60

Set 57 (Off-Campus for SDE-1)

Amazon Interview | Set 57 (Off-Campus for SDE-1) - GeeksforGeeks


Hi geeks, I recently hired for amazon. I just want to share my Interview experience with
You all.
Totally 1 Written + 5 F2F
Written round:
Q1: Convert a sorted integer Array to balanced binary search tree. This is very simple one
and I could do it in O(n) time and O(1)extra space.
Q2: Write a Program to reverse every k nodes of singly linked list without using extra space.
Constraint: k>=2
F2F round 1:
Q1: Find the largest element in the sorted rotated integer array in o(log n) time.
Q2: Find Height of a Binary Tree. This is very easy question, so I did quickly.then he move
on to next one.
Q3: Find your own method to balance an unbalanced binary tree.(you must not use existing
methods like AVL, red black or b trees).
Hint: There is no restriction on placing nodes. You can remove any node from any place
and put it in any place.
I devised an algorithm which will make use of two lists. One list contains nodes far away
from the root and this is sorted in decreasing order of levels and left to right if nodes are
in same level. Other list contains nodes which are not fully filled. This is sorted increasing
order of levels and left to right if nodes are in same level .
Remove the first node (listed in list1) and insert as a child of first node in list2.add this
node also in list 2. Do this operation until the height of the tree becomes log(n). Interviewer
was impressed with this and finished the interview.
F2F round 2:
Q1: There is a file which contains N words. There may be M anagrams in that file, K words
on each anagrams. K>=1, M>=1, N>=1. You need to write an algorithm which will create
one list for each anagram with k words and group all M lists with one data structure (This

177
Chapter 60. Set 57 (Off-Campus for SDE-1)

is the main area.we need to think a data structure which will minimize the space and time
complexity of word Finding appropriate List and Inserting word).
I could do the insertion in O(1) time by keeping track of tail pointer in each list. But finding
the appropriate list needs o(n) in case of linked list, o(log(n)) in case of binary search
tree. Using hash table, you can do this in o(1), but writing a hash function is difficult
and inefficient in terms of time. Then I suggested Trie data structure.with this, we can
reduce the time complexity well. But space complexity will be more. I told all the ideas
to interviewer. They were much satisfied with this. And moved to next question(without
writing code J)
Q2: Find min and max element of an unsorted integer array.
Very simple question you can do two pass on the array and find it, but number of comparisons
will be o(2n). He asked me to reduce it.
I gave an algorithm which will do the same in O((n/2)*3) which is fairly less than o(2n).
They were impressed on my solution and asked weather I have any question .
F2F round 3: (CS fundamentals and system programming)
Questions were in C++ patterns, Network Programming, Linux, since I did project on
networking, Linux I could perform well in this round.
F2F round 4: (Hiring manager round):
Interviewer was keen on testing cultural fit. Nearly 10 to 15 questions on my previous
project,
Why amazon?
Why you want to leave previous company?
What initiative you took in prevous company?
How will you manage conflict with your manager?
How will you demonstrate ur product to customer?
F2F round 5: (bar raiser)
This also had cultural fit questions and then a data structure question.
Qn: Find the distance between two nodes in a binary tree, no parent pointers are given. I
could solve this in post order traversal in o(n) time complexity. He asked me to code in
home and send it via mail.
Geeks for geeks is my Wikipedia for interview preparations. Thanks to geeks for geeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-57/

178
Chapter 61

Set 58 (On-campus for Software


Development Engineer)

Amazon Interview | Set 58 (On-campus for Software Development Engineer) - GeeksforGeeks


I’m in E&CE and I’m sharing my interview experience with Amazon on IIT campus to help
you prepare for your interviews. There was online test for 300 students. 25 were selected
for interviews. There were 4 back-to-back rounds on the same day. My interview process
lasted for around 5 hours and finally I got hired. �
Round 1:
1. Given 1 billion integers. Find 100 maximum integers. Memory available is insufficient to
store 1 billion integers.
2. Given array of N integers ranging from 0 to N-1. Output maximum repeating integer.
Use only O(1) memory.
Round 2:
1. An array of integers is given such that it is first ascending and then descending. Find
index of some given integer in that array. Ex. 2,4,6,8,7,5,4,3. Input: 4. Output: 2, 7. Write
code on paper.
2. Two sorted arrays are given. Find median when both arrays are merged and sorted.
Write pseudo code on paper. Take care of boundary conditions.
Round 3:
Basic OS, DB concepts.
1. You are given some integers. Propose a data structure to implement “add”, “delete”,
“fetch” and “fetch any” operations. All four operations must complete in constant time.
2. There is a B-tree with two type of nodes A and B. Return nth A or nth B while doing
inorder traversal in O(1) time. And write pseudo code on paper.
Round 4 with manager:
There is very huge text file consisting several rows and columns of integers. Memory available
is not sufficient to store whole text file. One column can be stored in memory. Sort whole

179
Chapter 61. Set 58 (On-campus for Software Development Engineer)

file corresponding to given column keeping all rows unchanged. You cannot make new text
file. Write neat code on paper.
Solution:
Round 1:
1. Make min heap of first 100 elements. For each remaining elements, if it is greater than
root (min) node then remove root node, add that element then heapify. Time = 1 billion *
log(100)
2. Simple. For i = 0 to N-1, A[A[i]%N] += N. Return i with max A[i]. O(n) time.
Round 2:
1. Find pivot point. O(log n) Binary search in both left and right arrays. O(log n)
2. Compare median of both arrays. Accordingly select right half or left half array. Repeat.
O(log n)
Round 3:
1. Make a hash table and a linked list. When you add an element add it in both hash
table and linked list. But in hash table along value caralso store pointer to the same value
in linked list. To delete an element find it in hash table, use stored pointer to delete the
same element from linked list also. For fetch any operation return head node of linked list.
Memory = 2*N
2. Preprocess in O(n) time: Make two vectors for A and B. Traverse in-order. When you
get A add its pointer in vector of A. Same for B.
Round 4:
Read whole column. Heap sort (saves memory). Now you know old indices and new indices.
Shift entire rows from old index to new index. Keep one row in temp storage to avoid
overwriting.
Some tips that may help you:
1. Always be confident for whatever you are saying.
2. Listen carefully. Ask doubts until the question is perfectly clear to you.
3. Think out loud. Start with obvious approach and then improve upon it.
4. They will test your way of approach, thinking process. Don’t give up. Interviewer may
give you hint if you are stuck.
5. Direct them to ask you about your strong topics.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-58-campus-software-development-engineer/

180
Chapter 62

Set 59 (Off-campus for SDE-1)

Amazon Interview | Set 59 (Off-campus for SDE-1) - GeeksforGeeks


I recently went through the Amazon interview process for the post of SDE-1. It was an
amazing experience for me.
Online Round (2 hours):
Q1- Program to rotate a matrix by 90 degree clockwise.
Q2- Program to convert a binary search tree into doubly linked list.
Q3- Program to find a node which is just greater than a given node in a tree.
Q4 –Given a sentence. Find all the characters which are repeated more than 1 time and
print them in lexicographical order.
F2F interview 1(45 minutes):
Q- Given a MXN matrix. To find the number of ways to reach the mth row and nth column
cell from 0,0 cell. Find the same if some of the cells are marked as not reachable.
First implemented using recursion then through dynamic programming.
Q- Given a linked list like a1-a2-a3-a4-b1-b2-b3-b4. Convert it into a1-b1-a2-b2-a3-b3-a4-b4.
F2F Interview 2(50 minutes):
Q- Given a sorted array of 0 and 1. Find the first occurrence of 1. Production working
code was required. I provided him O(logn) solution. He asked me how it is O(logn). Then
I explained him and generated the formula for same. He was convinced finally.
Q- Implement the cache using LRU technique. Production working code was required.
F2F Interview 3(1.5 hours):
Discussion on my current project. He asked every minute details of my project and made
me feel like he knows better than me about my project �
Then he asked me to implement a data structure for showing the currently visited items by
a customer on any website. You will find the same on Amazon website at bottom left side.
Program to sort m sorted arrays. I told him that I knew this. So we moved ahead.
Data structure to push, pop and find min element in O(1) time.

181
Chapter 62. Set 59 (Off-campus for SDE-1)

F2F Interview 4(45 minutes):


Q- To delete all the nodes from a binary tree that lie on a path whose sum from root to leaf
is less than a given value K. Twist was that the node values can be any integer. It may be
a negative number.
He asked me to find the time complexity and space complexity.
I did it using recursion with O(n) time complexity and O(1) space complexity. He said that
there is some space being used by my program that I am not taking into consideration. I
got his point. Since I was doing it using recursion, So some internal stack space was being
used and that would be O(logn)i.e height of tree. That was bit tricky.
Q- Given two sorted arrays. Find the median of the combined array.
One thing that you need to keep in mind is that you need to provide them the optimized
solution with respect to time and space and don’t forget to consider the corner cases.
After 4 days I got a confirmation call from Amazon �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-59-campus-sde-1/

182
Chapter 63

Set 60 (For Internship)

Amazon Interview | Set 60 (For Internship) - GeeksforGeeks


Believe me or not before I faced an Amazon interview round I was never sure whether all
those gratitude that people usually present to GeeksforGeeks were actually worth. But it is
always easier to connect the dots looking backwards and now I can say with assurance that
this website really deserves all the applause.
I was recently interviewed for an internship position at Amazon and had to go through a
total of 3 rounds i.e. one online followed by two telephonic rounds.
Online Round
As usual the online round had two coding questions and 20 MCQs. This was a pretty easy
round and it’s duration was 90 minutes. The round consisted of questions from various
domains like Algorithm, Data Structure, Operating System and Aptitude.
A few days after appearing in this round, I was informed that I have been qualified for the
next round.
First Telephonic Round
I had just three days to prepare for this round and truly speaking, it was my first experience
of appearing in any such interview.
This round lasted for almost 60 minutes. It began with my general introduction followed by
a brief discussion on my projects. After this, the interviewer asked me four questions.
Question 1:
Given an array of numbers find all such triplets that satisfy the given condition.
Condition: a[i] < a[j] < a[k] where I < j < k.
At first go I thought that it was a pretty easy question but slowly the mist started to clear
and I realized how tough it was. The interviewer wanted me to solve it in linear time i.e.
O(N)
Question 2:
Given two trees check if they are mirror images of each other or not.
This was a straight forward question and it took me less than 10 minutes to code it.

183
Chapter 63. Set 60 (For Internship)

Now the interviewer wanted to test my understanding of operating systems and asked two
fairly direct questions, to which I gave my answer based on my understanding (not bookish
definition as I did not remember any of those � ).
Question 3 & 4:
What is semaphore and what do you mean by a deadlock.
After two days I got a call from the HR informing me I have been selected for the next
round. Now it was the time for the last and the decisive round.
Second Telephonic Round
For this round I had slightly more time than the last, due to the fact that the weekend fell in
between.The interviewer was very very cool and helping this time, something which I kept
at the last in my list of probable things that can happen during an interview. Duration of
this round was around 90 minutes.
This time I had to face three technical questions and one general question on Amazon.
Question 1:
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.
Question 2:
Given an array of numbers find the maximum count of duplets and triplets such that there
sum is a multiple of three. Number that has appeared once can’t be included anywhere else.
I solved this question using a property of modulus.
Question 3:
Given the stock prices of 10 days find the best possible buy sell pair.
For this question I started with a O(N2 ) solution but then finally managed to reduce it to
O(N) solution with constant space complexity.
I was also asked few questions on Amazon like what are domains in which Amazon deals.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-60-internship/

184
Chapter 64

Set 61 (For Internship)

Amazon Interview | Set 61 (For Internship) - GeeksforGeeks


Hello geeks, Last month I appeared for the Internship Interview of Amazon.
What my personal experience says is that never try to jump to the right solution straight-
away, instead take your time and think progressively about the possible solution to the
given problem.
Check for boundary test-cases carefully and also don’t remain completely blank during
your conversation with interviewer but keep on telling him about the tentative solutions
that are coming to your mind.
My entire process consists of 3 rounds:
1. Online Round.
2. 1st Telephonic Interview
3. 2nd Telephonic Interview
Round 1:
It was an online round consisting of 20 Multiple Choice Questions (from C language, Oper-
ating Systems, Data Structures and Algorithms and Software Development Concepts) and
2 Coding Questions:
1. Given 2 linked lists constructed another linked list containing the sum of those 2 linked
lists. e.g Given : 1 -> 2 -> 3 and 4 -> 5 -> 6 Ans: 5 -> 7 -> 9
2. Find the Vertical sum of the given Binary Tree.
Round 2 (Telephonic):
The duration of telephonic Conversation was about 60 minutes and the Interviewer asked
me 2 coding questions:
1. Given an array of +ve as well as -ve numbers, find out whether it is possible or not to
convert it to 0 by adding/subtracting operations on all the elements.
e.g arr[]={1,2,3}
YES (1+2-3)

185
Chapter 64. Set 61 (For Internship)

arr[]={3,6,2}
3+6-2 != 0
3-6-2 !=0
-3-6-2 !=0
-3-6+2 !=0
-3+6-2 !=0
-3+6+2 !=0
3-6+2 !=0
3+6+2 !=0
Hence ans= NO
2. Given a binary Tree where the structure of each node contains an extra “next” pointer
(initially all NULL), modify the binary tree such that all the nodes at the same level gets
connected by utilizing these given extra pointers.
The interviewer also asked me to write the code for the same.
Round 2 (Telephonic):
The duration of telephonic Conversation was about 90 minutes and the Interviewer asked
me 2 coding questions:
1. Write a code to find the Diameter of the given a binary tree
Firstly I gave the solution which has complexity O(n^2) then he asked me to optimize it so
finally I did it in O(n).
2. 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.
I had a very great time preparing for the interview and got to learn a lot of new concepts.
I am really very thankful to GeeksForGeeks for being the primary source of my preparation
and believe me guys this website is just awesome.
And ya forgot to mention I finally got the confirmed offer for Internship at Amazon � �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-61-internship/

186
Chapter 65

Set 62 (For SDE-1)

Amazon Interview | Set 62 (For SDE-1) - GeeksforGeeks


I recently went through the Amazon interview process for the post of SDE-1.
Round 1 (Written)
1. Given an array, output an array where every index conains nearest greatest element to
that element on right side.
2. Program to convert sorted array to Binary Search Tree
3. Find first non-repeating character in String
ex: geeksforgeeks: f
geeksforgeeksFirst:o
Round 2 (F2F)
1. Given linked list as a-x-b-y-c-z
output it as a-b-c-z-y-x
that is reverse alternate element and append to end of list
2. Output nearest number greater than given number such that output is palindrome
ex: 121:131
900:909
99:101
Round 3 (F2F)
1. Vertical Sum in Tree( I told him I know the solution, he proceeded further)
2. Given stream of Strings find top 5 words with maximum frequency or count
3. Given 2 nodes in Binary Tree find distance between them
Round 4 (F2F with hiring manager)
1. Projects done so far, HR questions
2. Design Linkedin and find till 2nd level connections and path between 2 connection
for ex: if A is friend of B which is friend of C
print between A and C A-B-C
3. Programming language: Java
About synchronisation, serialization, transient and volatile keyword, Singleton Class

187
Chapter 65. Set 62 (For SDE-1)

Round 5 (Bar Raiser)


1. Count Inversion in array that is if i a[j]
Told the solution nlogn of divide and conquer. He asked another solution, then told by
inserting in BST and whenever node goes to left side then adding 1 and number of children
on right side . We have to keep track of count of right subtree in every node
Round 6 (F2F)
1. HR questions (Why leaving company, projects, SWOT)
2. Program to check for mirror tree
3. Data Structure so that push, pop, getmin, getmax O(1) (using 3 stacks)
4. Data Structure so that push, pop, pop min, pop max
Told Solution till O(logn) by using min heap, max heap with pointers to doubly linked list
nodes
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-62-for-sde-1/

188
Chapter 66

Set 63 (For SDE-1)

Amazon Interview | Set 63 (For SDE-1) - GeeksforGeeks


I have a total experience of two years. I am sharing my interview experience with Amazon.
This is for SDE1 Amazon.
A very big thanks to whole team of geeks for geeks. It is because of them only that I was
able to make Amazon and get a job in my dream company. Otherwise it was impossible for
me.
The interview questions of this interview experience are deleted on request.
You may find below links useful.
Amazon Company Preparation.
Amazon Interview Experiences.
Videos for Amazon Interview Preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-63-sde-1-2/

189
Chapter 67

Set 64 (Off-Campus for SDE)

Amazon Interview | Set 64 (Off-Campus for SDE) - GeeksforGeeks


I am sharing my off campus SDE interview experience with Amazon.
Online round: (1hr)

1. Given coin array and a sum K, find min. number of required coin to make sum K.
2. Two rectangles are given in two D space. Find if these are overlapping or not
3. KMP for pattern searching

After two days I got the call to come Amazon office for F2F interviews:
1st Round:

1. Program to construct binary tree from its inorder and preorder traversal. (algo+code)
2. Reverse every k-element in a linked list(algo+code)

2nd Round:

1. Tell me about one of your best project in detail.


2. Design Restaurant reservation system.

3rd Round:

1. 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)
2. Given a function “f” in which 0 occurs with probability 0.4 and 1 occurs with probabil-
ity 0.6. Using function “f” deduce a new function “f1” such that both 0 and 1 occurs
with probability 0.5
3. Given a matrtix, find the maximum sum subarray in it.(algo+code)

190
Chapter 67. Set 64 (Off-Campus for SDE)

After one week I got the call from HR for my BR round.


4th Round (BR Round):

1. Tell me about yourself.


2. Why are you looking for change?
3. How will you handle conflict with your manager?
4. What is the most challenging work done by you in your current company?
5. Lots of discussion happened about current company’s project.
6. Given a number N, find the smallest 3 digits number such that product of its digits
is equal to N. ( algo+ optimal code)

In all the rounds, the most optimal production quality working code was required and if
you get stuck, then they will give you HINTS but don’t consider this in your favor!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-64-campus-sde/

191
Chapter 68

Set 65 (Off-Campus for SDE-2)

Amazon Interview | Set 65 (Off-Campus for SDE-2) - GeeksforGeeks


My experience for Amazon’s Software Development Engineer-2
1st Round (Face-to-Face)
1. Design ATM
2. Design Car Service center
—- Deep dive into design and focus on specific modue called ‘Service’
—- Supervisor should be able to allot a Best Engineer to Service customer request, How do
you code to get best engineer to fix the car service request.
2nd Round (Face-to-Face)
1. Write a program to get all list of nodes without siblings in Binary tree
2. How do you implement ‘Car service center’ application to achieve Reliability, Scalable
and Consistent in distributed environment.
3rd Round (Face-to-Face)
1. Some behavioural Questions
2. Core java Q: Why do we need equals method ? Can we check equality using hashcode
method. Difference b/w them ?.
3. Get all nodes K distance away from leaf nodes. I could able to tell him my idea, but I
couldn’t able to come up with program with in given time.
4th Round (Face-to-Face)
1. Specific questions on current working project.
2. Implement my own Connection pooling
3. Given a linked list, write a function to reverse every k nodes. Initially I told him solution
with help of Stack , then he asked without using extra space, With his clue, I could able to
tell him using recursive logic to solve it.
Inputs: 1->2->3->4->5->6->7->8->NULL and k = 3
Output: 3->2->1->6->5->4->8->7->NULL.
5th Round (Face-to-Face)
1. Given a string, find the longest substring which is palindrome. For example, if the given
string is “forgeeksskeegfor”, the output should be “geeksskeeg”. I have seen this question ,

192
Chapter 68. Set 65 (Off-Campus for SDE-2)

but never thought about solution.


Same question i got in interview, I was very happy to get solution, interview asked me
optimize further. I could fix 1 improvement and he suggested 1 improvement.
2. Identify all possble entities/domain objects in Cricket. Went little deep.
3. Given Channel, Program and TRP ratings, How do you consume those at server side,
and what do you do to retrieve specific data like 1Get all programs in given channel where
TRP is > 10�.
4. Some behavioral Questions
Overall it was great experience, Myself satisfied with my performance in all rounds expect
3rd round :(.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-65-off-campus-for-sde-2amazon-interview-set-65-campus-sde/

193
Chapter 69

Set 66 (For SDE)

Amazon Interview | Set 66 (For SDE) - GeeksforGeeks


A F2F
1. Min stack problem (algo+code)
2. filling next pointer in tree but in zig-zag order (algo+code)
B Hiring manager
1. A big file (some TB’s) containing custid, page and time stamp, find out the repreating
customer( the one who visits after 24 hrs)(algo)
2. In a paragraphs tell the frequency of the words(algo)
3. A sequence of array, print the kth largest number(algo+code)
C F2F
1. Left view of a tree (algo+code)
2. Swap two node pointers in a singly linked list(algo+code)
D F2F
1. Given some sets of people who fight against each other. They are represented as graph.
if a link exists between A and B, the it means that A and B are fighting against each other.
Likewise there are some more links. The question was to divide the nodes into groups such
that no person in a group fight with another member in that group. (More of bipartite
graph) find the groups (algo)
2. A singly linked list, find the kth element from the last. The question was further modified
to not to process a node more than once. (algo)
E Bar raiser
1. Questions on projects, what is it, what did you do (deep diving)
2. Situation that has to miss deadline
3. Any situation encountered with performance issues
4. Any situation where you need to convince your team mates

194
Chapter 69. Set 66 (For SDE)

5. Any situation where you can see there are some improvements required and proposed
6. There is a large file( 1TB) containing braces. Question is to check for their balance. I
said will use a counter, will increment on an open brace and decrement on an close brace. If
counter goes negative or counter is non zero at the end of the file, braces are not balanced.
Otherwise balanced. Followup question was to make this process parallel (meaning to see
if this problem can be solved through parallelism, like dividing the the problem into sub
problem….) Remember the file is very large.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-66-for-sde/

195
Chapter 70

Set 67 (For SDE-1)

Amazon Interview | Set 67 (For SDE-1) - GeeksforGeeks


1) Round 1 telephone interview – implement division without using division operator in
log(n) time.
solution: use bitwise shifting
2) Round 2 telephone interview – write a program to buy and sell stocks to maximize profit,
can only do 1 action per day i.e. buy or sell.
solution: I used 2 pointers to keep track of best buy and sell rates. I implemented it in O(n)
time. He was happy with the solution.
After a few days I got a call from the recruiter saying the team was very happy with my
interviews and wanted to meet with me in person.
I had to actually reschedule my on-site interview as I couldn’t locate the office since it was
not locatable on Google maps!!
I got in the office in Toronto. I was given a visitor pass and escorted to a meeting area
where the interviews took place.
3) F2F(HR round)
This was easy, the interviewer asked basic questions about my background and what made
me choose computer science. I talked about my favorite project and she answered some my
questions.
4) F2F(Director) he wanted me to do BFS search. Given a level, child index return the child
node for a binary tree. I gave him a inorder search instead, he was okay with the solution.
5) F2F(SDE) this is when things started to get tough. He wanted me to design a library
reservation system. He wanted me to explain him a design and draw some diagrams and
then implement the classes.
We didn’t have enough time to do all of it. He wanted to know what data structure I would
use to perform searches for books. I choose LinkedHashMap because it allows O(1) lookup
and O(1) insertion.

196
Chapter 70. Set 67 (For SDE-1)

6) F2F(SDE) He wanted me to build a boggle game. This is where I got a little mixed up
with some java and C# syntax and he was not too impressed. I tried to write the algorithm
using 2 for loops and he gave me some hints as to how to implement it.
7) F2F(SDE) Given a list of words, find anagrams. This was easy enough to implement. He
asked runtime in the end.
The interviewers communicated with you all the time, its not like you go in an exam and
quietly write what you have memorized. There is lots of pressure and lots of explaining to
do as you write the code.
All in all it was a great experience. The guys were cool and fun to interview with.
Geeksforgeeks was a tremendous help towards the interview.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-67-for-sde-1/

197
Chapter 71

Set 68 (For SDE-1)

Amazon Interview | Set 68 (For SDE-1) - GeeksforGeeks


I went through the Amazon interview process for SDE-1, I didn’t make it past the 3rd F2F
round.
Online Round:
1. Find if a given string contains duplicates
2. Given a BST, find the maximum N elements of the tree
3. Given a BST, convert it into Doubly Linked List
4. Rotate a 2-D Matrix by 90 degrees
Telephonic Interview:
1. Given an array of integers (+ve and -ve), give a contiguous set of numbers that add to 1
Eg. 4 3 5 -3 -1 2 -3 10 2
Ans: 5 -3 -1 2 -3
2. Check if a given tree is a BST or not
3. In a 2-D Matrix with the following properties:
i. Contains only 1s and 0s
ii. Every Row is sorted
Find the row with maximum zeroes.
F2F:
Round 1:
1. Print all the cycles in a directed graph
2. Given an unsorted array, assign every element to its immediate larger number after the
current number, assign to -1 if no such number exists
Eg. 3 1 2 5 9 4 8 should be converted to
5 2 5 9 -1 8 -1
Round 2:
1. In a 2 D array where every row and column are sorted, give the nth smallest element

198
Chapter 71. Set 68 (For SDE-1)

2. In a Binary tree, every element must contain the sum of its sub-trees
Follow up question: how would you solve this if you can ONLY increment the value of a
node
Eg. If a node’s value is 20 and its sub-tree sum is 10, the node’s value can’t be set to 10
because you can only increment
3. Given n, find the smallest number for which product of the digits is n, if no such number
exists, print -1
Note: Digits can only be split as single digits, i.e., 132 can’t considered as 1 * 32 or 13 * 2,
it would only be 1 * 3 * 2
Eg. Answer for 36 would be 49
Round 3:
1. Convert a Binary tree into another binary tree whose in-order traversal gives a sorted list
This has to be done in-place
Eg.

1
2 3
4 5 6 7

should be converted into

4
2 6
1 3 5 7

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-68-for-sde-1/

199
Chapter 72

Set 69 (For SDE-1)

Amazon Interview | Set 69 (For SDE-1) - GeeksforGeeks


Online Coding Round:

1. Find if a given string contains duplicates


2. Given a BST, find the maximum N elements of the tree
3. Given a BST, convert it into Doubly Linked List
4. Rotate a 2-D Matrix by 90 degrees

Telephonic Interview 1:

1. Sliding Window Problem: Given a larger integer buffer/array (say size, x), now given
a window size (say, n) and a number (say, k). Windows starts from the 1st element and
keeps shifting right by one element. The objective is to find the minimum k numbers
present in each window.
2. Given a binary tree, each node having an integer data, the objective is to create a new
Doubly Linked List using this binary such that each node in DLL has vertical sum
of nodes in binary tree. The order of nodes in DLL shall be left to right as that of
binary tree’s vertical nodes i.e., leftmost vertical sum shall be 1st node in DLL and
the rightmost vertical sum shall be the last node in DLL.

Telephonic Interview 2:

1. Given the root of the binary tree and a pointer to any random node in that tree, the
objective is to print all the nodes at ‘k’ distance from the given random node.

Face to Face:
Note: Time and space complexity were discussed in each of the following questions. And
for each question I was asked to optimize the algorithm and later write the working code
for it.Also in each round the current project was discussed.
Round 1:

200
Chapter 72. Set 69 (For SDE-1)

1. Given a matrix (m*n), source (0, 0) & destination (m-1, n-1) (i.e. last cell), Find out
total number of ways to reach the destination from the source.
2. Given a binary tree, defining a term “complete path sum” as, sum of values of nodes
lying in a path from root to the leaf; Now given a value ‘k’, we have to find the k-heavy
path and prune the binary tree i.e. prune/delete nodes for which complete path sum
is smaller than k.

Round 2 (Manager’s Round):


A thorough discussion on an issue: If I am an owner of company which is selling some
product. So, how shall I store my data in Database such that when any analyst comes and
asks for any information then I could provide him most precise values. It mainly consisted
which data should be stored and how it should be stored.

1. Given two sorted arrays, create a final sorted array. Later, the problem was extended
saying that, now we have ‘m’ number of sorted arrays each of size ‘n’, now efficiently
create a final array. A lot of discussion was done on complexity of the approach (both
time and space).

Round 3:

1. Given a binary tree, where cost of travelling to the left child is ‘1’ and same for the
right child is ‘2’. Now, given the root of the tree and a value ‘k’, find the total number
of nodes that are at a distance/cost of ‘k’ from the root.
2. Given an unsorted integer (positive values only) array of size ‘n’, we can form a group
of two or three, the group should be such that the sum of all elements in that group
is a multiple of 3. Find the maximum number of groups that can be generated in this
way.
3. Given an integer array, find minimum number of jumps to reach the end of the array.
https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/

Round 4:

1. Given a BST, convert it into a Doubly Linked List in place. NOTE: We don’t have to
create a new data structure i.e. we have to modify the links/pointers in given BST.
2. Question was framed this way: Given street of houses (a row of houses), each house
having some amount of money kept inside; now there is a thief who is going to steal
this money but he has a constraint/rule that he cannot steal/rob two adjacent houses.
Find the maximum money he can rob.

NOTE: I didn’t face any HR round, all though in each rounds I was asked about the reason
for the change.
In all it was a great experience, and interviewers were really cool and gave a plenty of time
to think and code, sometimes suggested/hinted if I got stuck.
GeeksforGeeks has been extremely helpful for me in preparing.
All Practice Problems for Amazon !
Maximum money

201
Chapter 72. Set 69 (For SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-set-69-sde-1/

202
Chapter 73

Set 70 (On-Campus For


Internship)

Amazon Interview | Set 70 (On-Campus For Internship) - GeeksforGeeks


Online Round Coding Question:
Q1. Given a float number 7.64, convert it into the string WITHOUT using any inbuilt
function/library.
for eg:
input
float no.: 7.64
output
string: 7.64
Q2. Given the inorder and preorder traversals of a Binary Tree, output the postorder
traversal of it.
for eg:
input:
Inorder: 7, 8, 4, 1, 6, 2, 5
Preorder: 1, 4, 7, 8, 2, 6, 4
output:
Postorder: 8, 7, 4, 6, 5, 2, 1
Round 1 written:
Q1. Given a string find the length of longest substring which has none of its character
repeated?
for eg:
i/p string:
abcabcbb
length of longest substring with no repeating charcters: 3 (abc)
Q2. Given a link list with right pointers and each element of the list has a down link contains
another link list with down pointers as:

203
Chapter 73. Set 70 (On-Campus For Internship)

5 -> 7 -> 9 -> 18


| | | |
10 6 14 20
| | | |
11 8 19 22
| | |
12 13 24
|
15

each right and down list are sorted.


Write a function flatten() which flattens this link list to a single link list with all the
elements in sorted order as:
5->6->7->8->9->10->11->12->13->14->15->18->19->20->22->24

PI Round 1:
The interview started with discussions and questioning about the internship project and
other projects mentioned in my Resume.
After the discussions about projects interviewer asked a question on string the question
was:
Q1. A string of length n and an integer m was given, give an algo. to rotate the string
counter clockwise by m. I was asked to give all the check conditions for input m.
Then the interviewer asked me to write a code for the same with a strict guideline that there
should not be any mistake in the code ;).
Q2. After this he asked me about heap, min and max heap, insertion and deletion in a heap.
He asked me to prove that the time complexity of inserting n elements in a heap.
At-least he asked about the uses of heap data structure and other data structure which are
implemented using heap.
PI Round 2:
Q1) What is the difference b/w abstract and interface class?
Q2) Write a program to create single thread and print “Hello World”, stating all the argu-
ments of createThread function?
Q3) What is a deadlock and what are the condition necessary for the deadlock to occur?
Q4) What is a cache memory and how it is implemented?
Q5) Explain LRU, FIFO and other page replacement algorithms?
Q6) Write a code to implement LRU cache and then implement full cache memory?
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-70-on-campus/

204
Chapter 74

Set 71 (For SDE-2)

Amazon Interview | Set 71 (For SDE-2) - GeeksforGeeks


Recruitment Drive – Delhi (22 March 2014)
Position SDE-2
1st Round – Coding and Algo (50 Minutes)
1. Find In order predecessor in BST.
2. Find Nodes which are at “K” distance from given node.
Interview asked to explain logic and write full code with all boundary conditions.
2nd Round – Design Round (50 Mins)
1. Asked about abstract classes and abstract class there uses and where they have to used.
Asked me to design online cab booking system for amazon. Then asked me to design High
Level diagram for it.
3rd Round – Coding and Algo Round ( 1 Hour)
1. Asked to explain how to check Binary tree is BST? then asked me to write whole code
of it.
2. Then asked me about assembly line problem. https://www.geeksforgeeks.org/
dynamic-programming-set-34-assembly-line-scheduling/
3. Then asked me to solve Knapsack Problem https://www.geeksforgeeks.org/
dynamic-programming-set-10-0-1-knapsack-problem/
4th Round – Manager Round (45 Min)
Asked me about my experience with current company and details of my project
Then asked about singleton pattern.
All Practice Problems for Amazon !

205
Chapter 74. Set 71 (For SDE-2)

Source

https://www.geeksforgeeks.org/amazon-interview-set-71-sde-2/

206
Chapter 75

Set 72 (Off campus for SDE-1)

Amazon Interview | Set 72 (Off campus for SDE-1) - GeeksforGeeks


Amazon Interview (Off campus for SDE-1)
Experience: 8 months
Interview Process – 2 (telephonic) + 3 (f2f – Bangalore) + 1 bar raiser (telephonic)
Telephonic 1 (25 minutes only)
Q1. Two strings s1 and s2 are given; find a minimal length substring in s1 which does not
contain s2 as a substring. (Do include all edge cases)
Q2. Swap all nodes of a linked list with their next nodes.
Telephonic 2 (65 -70 minutes)
Q1. An integer array of size n is A[] given, find the three numbers s.t. A[i] > A[j] > A[k]
and I < j < k.(algo only) Q2. An array of integers is given, trim the array such that 2*min >
max. min and max are the minimum and maximum elements of the array. You can remove
elements either from start or from end of the array if above condition does not meet. No of
removals should be minimum. (algo + code)
For example a, b, c, d, e f are the elements of array, c is the min num and e is max no
condition 2*c > e is true then we are done but if false then remove either from start i.e. a,b,c
or from end i.e. e, f such that new min or max would satisfy the condition and removals
should be minimum.
Q3. A sorted array of integers and a number K is given, find the closet number to K. (algo
only)
F2F 1 (60 minutes)
Brief introduction about my self and my work experience in current company
Q1. Equilibrium Point in an integer array (sum of left side elements should be equal to sum
of right hand side elements)
Q2. Extend above for multiplication (multiplication of left side elements equal to multipli-
cation of right side elements)
(special case of Zero and some discussion on arithmetic exception and range bound errors)
F2F 2 (60 – 65 minutes)
Some general introductory questions; why are looking for a change and work experience.

207
Chapter 75. Set 72 (Off campus for SDE-1)

Q1. For a given number K, print all pairs of valid parenthesis combination and return the
total count of such combinations.
Q2. There are n balls kept on a table and connected in random fashion but there is no cycle
(no back edge). Write the code to select a ball such that after lifting the whole structure
from that ball height will be minimum. (algo+code+ mathematical proof of correctness)
Q3. Difference b/w http and https.
Q4. Suppose you are handling Amazon website and you have 10 MB size home page.
Optimize the homepage for a customer who has 100 kbps internet connection.
Further he asked for the customer who has 100 mbps internet connection.
F2F 3 (with Hiring manager, 80-90 minutes)
Lots of discussion about current project. He will ask you everything from bottom level to
your contribution.
Q1. Implement memcpy (*src,*target) function.
Q2. Reverse contents of a linked list.
Q3. I code in java so lots of question on oops and java like swing and awt difference , vector
and array list difference , interface and abstract classes.
Q4. Client and server code in chat window, background process in server and network,
networking layers.
Q5. Process and threads and code for thread safe situation (take an example and explain)
Bar raiser (Telephonic one hr)
Hr Question like biggest challenge so far, projects, why are you looking for a change, why
amazon, biggest mistake.
Q1. Given flat files (for an entire year, 1 per day) of train schedules (arrival and departure
times at a given station) find Min platforms required to accommodate the trains in that
station.(algo only)
Q2. I want to write a ransom note. But I don’t want to write it by hand, I’m going to cut
letters out of a magazine. How can I tell if the magazine has enough of the right words to
spell out the note I want to write? Let’s assume we have a way to digitize the text of the
magazine. (algo only )
I asked him about Amazon kindle and Amazon instant video. Show him that you know lot
about amazon.
Advice for Amazon: except from all data structure, read Trie data structure very well and
how to process big data.
Next day I got call from HR tht I am Hired � �
Thanks a lot to geeksforgeeks team.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-72-campus-sde-1/

208
Chapter 76

Set 73 (For SDE-1)

Amazon Interview | Set 73 (For SDE-1) - GeeksforGeeks


I have been interviewed for SDE1 by amazon. Here are the questions.
1st Round – Online Coding
1. Contiguous elements in an array whose sum is k.
2. Convert sorted array to binary search tree.
2nd Round – Telephonic
1. Implement stack with Push, Pop, GetMin and GetMax in constant time. Algo + Code
2. Given a matrix, sorted both horizontally and vertically, algo and code for finding an
element in it. Algo
3. Given a stream of characters, convert it to a sentence with valid words. Assume you have
a function IsWord which returns true if the passed string is a word. He asked me to write
code and mail him. Algo + Code
Ex: Iamgoodboy – I am good boy
3rd Round – Telephonic
1. Given an array of characters, find the longest continuous non-repeating sequence of
characters. Algo + Code
Ex: aabcdefdghiajk – efdghiajk
I have given a hash based solution, so he asked me to write a custom hashfunction and how
to handle collisions.
2. Find the next largest palindrome number of the given number. Algo + Code
Ex: 120 -121, 123 – 131
4th Round – InHouse technical round
1. Find the mirror image of a binary tree. Algo + Code
2. Given a string, find the largest repetitive sequence. Algo + Code
Ex: abcdefbcd – bcd, banana – ana
5th Round – InHouse technical round
1. Given a string, remove ‘a’, ‘bc’ from the string and print the
result. Algo + Code
Ex: asdbc – sd

209
Chapter 76. Set 73 (For SDE-1)

2. You will be receiving an infinite sequence of numbers continuously


and at any particular moment find the 10 largest ten numbers received
till now. Algo
6th Round – Bar raiser round
1. Given a graph, find the nodes which are at less than k distance
from the given node.
Continuation: find all the nodes which are less than k distance from m
nodes. Algo + Code
2. Implement a queue using an array. All base conditions. Code
3. Given a very big array of millions of integers, find sum of all the elements.
Parallel processing and threads is the answer. Threads concept,
synchronisation and so many of it.
4. OS concepts – virtual memory, paging, process states, paging algos.
5. In detailed explanation of projects done till date.
7th Round – Manager Round
Asked dilemma situation. Any process development work, work experience and all.
geeksforgeeks helped me to refresh all kinds of topics. Thank you.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-73-for-sde-1/

210
Chapter 77

Set 74

Amazon Interview | Set 74 - GeeksforGeeks


Phone Interview:
1) Given a 2D matrix where every row is sorted, give the index of row which has maximum
number of one’s
2) Given a Binary tree, print its every level in a new line.
Face to Face Interview (Round 1):
1) you have an array which has a set of positive and negative numbers, print all the subset
sum which is equal to 0.

eg 2, 1, -1, 0, 2, -1, -1
o/p: 1, -1
1, -1, 0
0
2, -1, -1

2) How do you check whether a binary tree is a binary search tree.


Face to Face Interview (Round 2):
1) you have a billion numbers how do get kth top elements
2) given a number n, print all pairs of valid parenthesis

eg: n=2 -> (()), ()()


n=3 -> ()()(), (())(),()(()), ((()))

I did not clear after this round, I hope this helps others.
All Practice Problems for Amazon !

211
Chapter 77. Set 74

Source

https://www.geeksforgeeks.org/amazon-interview-set-74/

212
Chapter 78

Set 75 (For SDE-1)

Amazon Interview | Set 75 (For SDE-1) - GeeksforGeeks


I am currently in my 8th semester . I recently attended the off campus drive for SDE1 at
Amazon. Here’s my journey.
Round 1:- (Written)
This was a written round . It was hosted on interview street.
It was a 90 minutes test with 20 mcq and 2 codes
1> Return the longest palindromic substring in a string
2> Count the number of 2’s in all number from 0 to n .
Mcq’s were based on ds algo,operating system and maths.
After two days I got a call from the hr that I have cleared the written and a phonescreen is
to be scheduled.
Round 2:- (Phone screen 1)
This was supposed to be a 1 hour round. The interviewer shared a collabedit link.
1> Divide an array into 2 subarrays such that the absolute difference of their sum is mini-
mum. It was then extended to divide into two subsequences .
2> Convert a sorted array to a balanced binary search tree.
3> Convert a linkedlist with positive and negative integers into a list with first all negative
integers, then positive. order amongst negative and positive numbers to be maintained .
Generally if first phonescreen is convincing the next step is direct face to face interview ,
else one has to go through another phonescreen . I had one phonescreen only . After a
month i was called for inhouse interviews . All arrangements were made by them .
Round 3 :- (Face to Face 1)
1> Define a BST. Now check if a binary tree is a BST
2> Given an array of size n, and an integer k. find minimum number in every subarray of
size k
3> Given n non-negative integers representing an elevation map where the width of each
bar is 1, compute how much water it is able to trap after raining
4> Given an array find all triplets whose sum is equal to a given number k

213
Chapter 78. Set 75 (For SDE-1)

Round 4 :- (Face to Face 2)


1> Find the diameter of a tree.
2> Print the diameter of a binary tree . (U have only left and right pointers)
3> Assembly scheduling problem (Dynamic Programming paradigm)
Round 5 :- (Face to Face 3)
1> How to check if two sets are disjoint ?
2> How to implement hashing for a set .
3> Given n sets , give the minimal number of sets which must be removed so that the
remaining sets are all disjoint (Variation of set packing problem)
The interviewer was interested in some greedy heuristic as he knew its an np complete
problem and no solution can be better than exponential
4> You are given a matrix of 1’s and 0’s . The property is that
every row of matrix is sorted in descending order . Return row with maximum number of
0’s
Round 6 :- (With senior manager)
Interview started with detailed discussion of projects.
1> Implement lastindexofastring(String s1,String s2) . If s2 is present multiple times return
the last index of s2 in s1 , else return -1.
2> Given a paragraph of text, write a program to find the first shortest sub-segment that
contains each of the given k words at least once. A segment is said to be shorter than other
if it contains less number of words.
The interviewer then asked me if i had done something on multithreading . As i was not
very confident so i said no and he dint go further .
He then asked me what is my biggest regret in my student life in college .
Amazon hr’s were extremely helpful. After 3 days I got a confirmation call that I was hired.
Geeksforgeeks has been instrumental in helping a lot of people to land up in good companies.
Keep up the good work �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-75-sde-1/

214
Chapter 79

Set 76 (For SDE-1)

Amazon Interview | Set 76 (For SDE-1) - GeeksforGeeks


Hello Guys, I was recently interviewed by Amazon for SDE-1 position. Following is my
interview experience.
Round-1 (Written on InterviewStreet)
1. Rotate a N*M matrix 90 degrees clockwise
2. Given a string find the repeated characters and print them in lexicographical order. e.g
i/p string- “ABCCAD” o/p-“AC”
3. Given a binary tree, find the k-th largest element
4. Convert Binary tree to DLL
Round 2 (Telephonic)
1. Given an MxN array, in which the rows are sorted. Need to sort the complete array
Round 3 (F2F)
1. Spiral Level order traversal of Binary tree
2. Given a huge file 100 million integers. He further divided the file
to 100 files with 1 million integers each. Each file is sorted. Find the efficient way to find
smallest ‘m’ integers. Note ‘m’ is very less in comparison to a million
3. Given sorted & rotated array find the index of given integer
Round 4 (F2F)
1. Given a Binary Tree and a sum k.Print all the paths with sum = k. Path can or cannot
start with root
2. Reverse k elements of linked list
3. Given a 2D array find the maximum sum rectangle
4. Given a list of n mp3 songs. Play them randomly. No song should repeat until all the
others are played.
Round 5 (F2F with Development Manager)
1. Tell me about yourself and the projects done in previous company. A discussion on those
projects followed.
2. Why do you want to leave your previous company
3. Given a binary tree

215
Chapter 79. Set 76 (For SDE-1)

1
/ \
2 3
/ \ \ /
4 65
/ \
/ \ / \
7 8 9 10
Needed to connect the nodes vertically
1
/ | \
2 | 3
/ | \ | / | \
4 | 5 | 6
/ \ | / \ | / \
7 8 9 10
Assume each tree node has an additional pointer
(struct node* vertical)

Round 6 (F2F)
1. Given stock price of Amazon for some consecutive days. Need to find the maximum span
of each day’s stock price. Span is the amount of days before the given day where the stock
price is less than that of given day

E.g i/p = {2,4,6,9,5,1}


o/p= { -1,1,2,3,2,-1}

2. Given a Binary tree each node should contain the sum of left and right subtrees. Leaf
nodes will become 0 in the resulting tree.
Round 7 (F2F with Project Development Manager)
1. Tell me something about yourself
2. Tell me about your previous company and projects
3. Why do you want to leave the previous company in such a small time.
Finally got the offer after few days �
Tips:- Be clear to the interviewer, the are quite helpful. Try to discuss the various approaches
that come up in your mind if you are struck somewhere.
All the best.!!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-76-sde-1/

216
Chapter 80

Set 77 (Off-Campus For SDE-1


/ 1.5yrs experienced)

Amazon Interview | Set 77 (Off-Campus For SDE-1 / 1.5yrs experienced) - GeeksforGeeks


Amazon SDE1 Off campus
Written Round
1. Given an array in which elements are first increasing and then decreasing. find the
maximum element in the array.
2. Given an array of unsorted elements, find the minimum difference between any 2 elements
in the array.
1st f2f
Discussion about my projects (nearly 20 mins)
1. Given an array of positive numbers, find the maximum sum of a subsequence with the
constraint that no 2 numbers in the sequence should be adjacent in the array. (extended to
negative numbers)
2.Write a function to print the level order traversal of a binary tree in spiral form.
2nd f2f
Small discussion about my projects
1.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.Given 2 strings str1 and str2. What is the efficient way to navigate from str1 to str2? The
constraints are i) a string can be changed to another string by changing only one character.
ii) all the intermediate strings must be present in dictionary. If not possible, return “not
possible to navigate from str1 to str2”. (pre-processing is allowed and enough memory is
available). for example: str1 = feel and str2 = pelt, then the navigation is feel -> fell ->
felt -> pelt (Hint: Graph)

217
Chapter 80. Set 77 (Off-Campus For SDE-1 / 1.5yrs experienced)

3rd f2f
Discussion about my projects (nearly 20 mins)
1. Given two numbers represented by two linked lists, write a function that returns sum list.
The sum list is linked list representation of addition of two input numbers. It is not allowed
to modify the lists. Also, not allowed to use explicit extra space.
2. Given a matrix of characters and a string, find whether the string can be obtained
from the matrix. From each character in the matrix, we can move up/down/right/left. for
example, if the matrix[3][4] is

o f a s

l l q w

z o w k

and the string is follow, then the function should return true.
4th f2f Hiring Manager
Deep discussion about my current project (nearly 45 mins)
(application architecture, challenges faced and a lot of technical discussion)
1. Write a program to check whether the given binary tree is BST.
5th f2f Bar Raiser
Deep discussion about my current project (challenges faced, etc) nearly 20 mins
Deep discussion on REST api authentications (Hash key vs Encryption & Decryption) nearly
20 mins
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-77-sde-1/

218
Chapter 81

Set 78

Amazon Interview | Set 78 - GeeksforGeeks


The first round was an online test hosted on Interviewstreet.com. Around 350 students
appeared in the online test. The duration was 90 minutes. It consisted of 20 MCQs based
primarily on Predicting The Output, OS, CN and Data Structures.
These questions were pretty basic and easily solvable.
Apart from that, there were 2 coding questions.
1. Given a string, find the first element which is non -repetitive i.e that element must not
be present anywhere else in the string.

Eg : Input : teeterson
Output : r, as it is the first element which
is non repetitive.

2. Given a string of digits,find the next smallest number using the same digits.If its not
possible to get such a number print -1;

Eg : Input : "123" Output : "132"


Input : "12453" Output : "123534"
Input : "987" Output : "-1"

After a week, the results came out and 25 students were shortlisted.
Personal Interviews:
Technical Interview 1 :
1. Given an array of 1s followed by 0s,find the number of 0s.

219
Chapter 81. Set 78

Eg : Input : 111100 Output =2


Input : 1 Output =0

I solved it by using Binary Search to find the first and last occurrence of 0 in the array and
subtracting the results.
2. Given an array of positive and negative numbers, find the pair of elements whose sum is
closest to 0.

Eg : Input : 3 5 -9 -4 17 11
Output 3 , -4

The brute force solution would be O(n^2) by comparing each pair of elements.As expected,
he asked me to optimize my solution.
So I sorted the array using merge sort. (I know its not in-place but it did not strike me at
the time)
Then used two indexes at the beginning and end of the the array and incre-
mented/decremented the indexes as needed.
3. Given a Binary Tree , print all the root to leaf paths.
I started by telling him my approach and the logic behind the recursive solution that I had
in mind. Then he asked me to write test cases for the function that I had written.
6 students were selected after this round.
Technical Interview 2
1. Given a binary tree convert it to a double linked list.
2. Given an array of integers , replace each element with the product of the remaining
elements.

Eg : Input - 1 2 3 4
Output : 24 12 8 6

First, i gave the obvious solution. I computed the product of the whole array and then
divided it by each element to get the resultant array.
But he asked me to do it without using the division operation. After some cross questioning
I gave the following solution.
Store the product of the left side elements for each integer in an array L[].

For eg : Here , L[]= {1 , 1 , 2 , 6 }

Do the same for the right side elements.

220
Chapter 81. Set 78

Here R[] = { 24 , 12 , 4 , 1}

The multiply R[i] and L[i] to get the resultant array.


Complexity : O(n)

Finally 2 people were selected.


Result: Selected for a 6 month long internship as SDE-T (Testing)
GeeksForGeeks has been instrumental in my preparation for the interviews and I am really
glad that I discovered this website at the right time.
PS : Could you guys tell me if the SDE-T position is inferior to the SDE-1 position or are
they of the same level?
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-78-fresher-internship/

221
Chapter 82

Set 79 (For SDE-1)

Amazon Interview | Set 79 (For SDE-1) - GeeksforGeeks


I have 8 months of experience and I recently appeared for interview of Amazon for role of
SDE-I.
Written Round:
Q1: Convert a binary tree to DLL.
Q2: Given a random node address in Singly linked list. Delete that node.
You need to write full code in language of any choice with all the edge cases covered.
Interview 1:
Q1 : Given a sorted array and a number and element K. find K nearest elements to the
number in sorted array.
Q2: 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
Interview 2:
Q1: Given 4 youtube servers which are processing user requests.
i> At any given time If someone requests for currently running videos, then return the
number of videos running at a time.
ii> Which server will actually get the request ?
iii> How the servers will communicate with each other ?
iv> Other methods to do this task to reduce overhead on servers?
v> How many videos running given a time constraint ?
Q2: Given a binary tree and each node has an extra next pointer apart from left and right.
Connect all the nodes using next pointer in Zig-Zag Manner.

222
Chapter 82. Set 79 (For SDE-1)

Interview 3:
Q1: Discussion about project in current company.
Q2: Given a shared memory between multiple threads, how will you ensure safe access to
memory in different scenarios like reading and writing? If at thr point of wrtitng there are
mutiple read requests from threads how pending requests can be managed.
Q3: Given an array that has positive numbers and negative numbers and zero in it. You
need to seperate the negative numbers and positive numbers in such a way that negative
numbers lies to left of zero and positive numbers to the right and the original order of
elements should be maintained
Interview 4:
Q1: Discussion about current project in company.
Q2: Why you want to leave your current company ?
Q3: Why Amazon ?
Q4: Which phone you have
Q5: Which one will you buy next
Q6: given a function with signature
bool isFactorialDivisible( int x, int y)
Return true if x! is divisible by y
else return false
After 3 days I got the confirmation call.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-79-sde-1/

223
Chapter 83

Set 80

Amazon Interview | Set 80 - GeeksforGeeks


Online Written
1. Cant remember the question exactly, but it was bit easy and was easily solvable using
the substring function for the string.
2. Need to find whether two rectangles overlap or not
3. Need to find the matching percentage , if we are given two paragraphs
Telephonic
1. Need to find the least common ancestor for given two nodes
2. Implement Min stack problem with other optimizations
Fully functional code and covering all boundary conditions was required
Face to face 1 (Hiring manager)
1. Top K words from the file containing millions of words. Proper code for the scenario.
2. Why do you want to change the company
3. What is your manager review for you in your current company
4. What all projects you worked on and detail
5. Some other non tec questions
Face to face 2
1. Given a number n where n means 0,1,2,3….n-1. Compute the no of BST which can be
formed using this range as input in any order
2. Given a string input : aaabbccdeeabb output should be : a3b2c2de2ab2
Challenge here is that we need to do it in place, without any other string or data structure
For both the problems full code with all the boundary conditions was required
Face to face 3
1. Rotate a 2D matrix by 90 degree, but here the matrix is stored in 1D form

224
Chapter 83. Set 80

2. Given a linked list which contains representation of any number, like for 1234, the
representation will be 1->2->3->4. Now we need to add 1 to the number, so that the
output is 1->2->3->5
3. Then he asked me 1-2 questions for which I immediately responded the solution, through
that he got the idea that I already know the solution
4. Moved to the white board, he draw a matrix, each contains only 0 ad 1 but in sorted
manner. I need to return the row which is having the max no of zeros. Then he asked me
optimized solution for finding the first ‘1’ in the array
5. Then he explained me a production line problem, Many factors were involved in that,
robotic arm need to draw some lines with various colors on some wall. We need to minimize
the cost of drawing those lines, Code was not required in that situation, as the problem set
was very big, but we discussed the complexity plus solving procedure for each of the factors
of the problem. Every minute detail of how will I solve the problem.
Basically problem itself was composed of many different types of sub problems, keeping
mind open at that time is very important.
Then after few days, I mailed the HR regarding the result, she told me one round is still
pending, will update soon and after 1-2 week, they sent the mail for halting the process,
didn’t get any solid reason, as it was totally unexpected, all my rounds went well.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-80/

225
Chapter 84

Set 81 (For SDE-I)

Amazon Interview | Set 81 (For SDE-I) - GeeksforGeeks


Hello Geeks, I had interview in amazon few days before. I’m sharing you my experience. It
was for SDE-I Profile for Hyderabad(India) location.
Round 1: Online Coding(Interviewstreet)
Q1. Print the nth largest node of the given BST. In this question you will have to write a
function.
Q2. Convert the BST into sorted doubly linked list. In this question also you will have to
write a function.
Q3 & Q4 was simple algorithm based.
Round 2: Telephonic Interview-I
Q1. Given Matrix, and co-ordinates of sub-matrix of given matrix find sum.

Eg 1 2 3
4 5 6
7 8 9

Coordinates for submatrix 1,1 and 2,2


Sum= 28

Q2. Given a linked list reverse every n chunks.


EG: 1 -> 2 -> 3 -> 4 -> 5 -> 6…n = 3
Output: 3 -> 2 -> 1 -> 6 -> 5 -> 4…
later they extended this Question…If there is only one node and give many conditions.
Round 3: Telephonic Round-II
Q1. Design a data structure for insertion, deletion & get minimum element in O(1)time
complexity? Implement the same.

226
Chapter 84. Set 81 (For SDE-I)

Q2. Given a Binary Search Tree and two nodes find parent node which is parent of both
nodes in a given binary search tree. Later the they extended it to simple binary tree.
Round 4: F2F-I
Q1. Is given n-ary tree is Sum tree or not? implement function…
Q2. find Nth largest element in an array
Round 5: F2F-II
Q1. Vertical traversal Order of tree(implement it).
Q2. Lots of discussion on project.
Round 6: F2F-III
Q1. Given a circular array and a pointer find the given element in the array.
Q2. Lots of discussion on current company & company’s work.
Round 7: F2F-IV
Explain:
1. Customer Producer problem,
2. Semaphore
3. Deadlock how to solve it.
Q: Favorite Sorting Algorithm.why,where to use it? and various question on the sorting
algorithm which I answered.
Every time they ask for time complexity for code. Ask to optimize my solution.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-81-for-sde-i/

227
Chapter 85

Set 82 (For SDE-2)

Amazon Interview | Set 82 (For SDE-2) - GeeksforGeeks


Round 1 (F2F):
1) Find the merge point between two lists.
2) Given a sorted array find the number of BSTs you can form.
Round 2 (F2F):
1) Discussion projects i have worked on.
2) Given millions of files process them sequentially in multiple stages and make sure it has
good scalabilty, error handling, elegantly handles changes to the system. etc.
Round 3 (F2F):
1) Given a matrix with each cell containing each number of candies, and a constraint that
you can move only right or down, from the top left corner to the bottom right corner, find
the path that gets you maximum candies.
2) Convert a Binary tree to its mirror in-place.
Round 4 (Telephonic + online coding):
Given a continuous stream of strings, maintain strings such that duplicate are eliminated on
the fly. The interviewer wanted working code. So coded the solution during the interview
and emailed it to him 10 mins after.
So if you get “Ted”, “John”, “Mark”, “Ted”, “David”, at the moment in
time, the list should contain John, Mark, David.
Round 5 (Hiring manager in US, telephonic + online coding):
1) Discussion on current projects.
2) Why Amazon
3) BFS vs DFS
4) Given a function to getFriends that gets a list of profiles of friends of a particular friend,
implement a function to get the shortest path between two given profiles.
All Practice Problems for Amazon !

228
Chapter 85. Set 82 (For SDE-2)

Source

https://www.geeksforgeeks.org/amazon-interview-set-82-for-sde-2/

229
Chapter 86

Set 83

Amazon Interview | Set 83 - GeeksforGeeks


Written (50 Minutes)

• 20 aptitude and general cs objective questions


• Code : Find minimum # elements to be removed from int array so that max element
is <= 2x of min element
• Code : For given array a of size n we create a set of a[i] , a[a[i]] , a[a[a[i]]] ….. i varies
from 0 to n-1 , find the max size of such set.

Face to Face 1

• Design MP3 player which would play only unique songs in random order from given
list of songs
• Code : Print left and right most elements at all levels of a binary tree.
• Max elements in sliding window of size k over int array of size n.

Face to Face 2

• Code : Find min element at given level in binary tree


• How would you combine lots of big sorted files residing on disk ( file size >>> memory
)
• What happens when you enter URL in browser.
• Design multiple stacks in a Single one big int array as efficient as possible ( real world
example multiple process function stacks creation and deletion in memory of linux os
)

Face to Face 3

• Discussion on challenging work projects.

230
Chapter 86. Set 83

• Design in-memory file system.

Last round Telephonic

• Toughest work project experience.


• A robot standing at top left corner of a grid, it can only move in right or bottom
direction , determine total number of possible paths are their to reach bottom right
corner.
• Code : Prune binary tree so that only nodes which are part of K-Heavy path remains,
K-Heavy path means total of all elements in a path from root to leaf is > K.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-83/

231
Chapter 87

Set 84

Amazon Interview | Set 84 - GeeksforGeeks


I attended a hiring event for Amazon in world trade center in bangalore.
First round was coding test (Written round) :
1. Given a string of parenthesis, write a function if it is balanced.
2. Convert BST to a Doubly linked list.
3. Find the number of occurrences of words in a paragraph.
First Round :
1. Asked Why Amazon?
2. Asked some questions on resume.
After some friendly talk, jumped on technical but easy questions :
1. Implement BFS.
2. Difference between Dijkstra and BFS.
3. Given a linked list, find out if the list is circular, also find the point from where the cycle
start.
4. Given an array, find the max sum over a sub array.
5. If you have two eggs, how many max steps you need to find the floor, from which the
eggs break.
And some more easy questions.
It was already 5, so they decided to have further rounds later.
10 days later I had attended interviews :
First Round :
1. Asked about heaps, given an array, tell if it is min heap, if not, apply operation min-
heapify.
2. Is a heap a complete binary tree?
3. Asked What is hashmap.
a. What happens when two numbers map to same key?
b. how does chaining work?
c. What to do when you have a bad hashing function, and only we can modify the
structure of hashmap not hashing function?

232
Chapter 87. Set 84

d. What do to when you your hashmap is filled completely (as in all the linked list are
filled up to their capacity)
4. What is quicksort? Implement for a linked list and tell complexity.
Second Round :
1. What is quicksort?
a. What is complexity when all elements are sorted and how can you improve it?
(Randomization)
b. Will randomization work when elements are same?
c. What algorithms sort equal elements in O(n) time ?
d. using the information, how can you improve quick-sort? Think about it, its good.
Don’t want to spoil it for you by writing answer here.
e. implement this modification.
2. Given two river banks (visualization : two parallel lines), one bank has numbers written
(1….n) in sorted order. On the other bank the numbers (1…n) are arranged randomly. A
bridge can be formed from the ith point from bank 1 to ith point in bank 2. Find the max
number of non-intersecting bridges you can form?
3. Given 1…n , and given some statements like i hates j, then find some arrangement of n
numbers such that if i hates j then in the arrangement i comes before j. Say 1 hates 2, then
123456789 is acceptable but 213456789 is not.
4. Asked about internet. What happens when you type a URL on your browser?
Third Round (Hiring Manager):
1. Why do you want to leave current company?
2. Why do you think amazon is the right place for you?
3. Implement a calculator which takes a maths expression and evaluates it and prints the
result.
4. Given statements like A is connected to B. D is connected to E. And transitive connections
are allowed. Write a code which takes input such connected statements and and two numbers
i and j and returns true if i and j are connected (can be transitively), and false if not
connected.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-84/

233
Chapter 88

Set 85

Amazon Interview | Set 85 - GeeksforGeeks


1st Telephonic round
After few project and introduction related question.

1. Write a program to find an element in sorted and rotated array.


2. Write a program to print all path whose sum is equal to a given number path must
start from the root node and it may or may not end at the leaf.

2nd Telephonic round


After 3-4 days
Some c/c++ question what is malloc how does it work and memory layout and allocation
related questions

1. Write a program to find longest repeating substring In a given string running code
were required covering all base cases.
2. U have given 10 files and you have given a string suggest data structure which ll
facilitate efficient search of string in the file if string appears more than ones in that
case u have to print line number and file in which they appear.

After 15 days I got cal that I have cleared the telephonic round and my F-2-F interview is
going to take place in Hyderabad
F-2-F round 1
After introduction and project related questions

1. Write a program to print a tree in vertical order asked more than one approach to do
this problem and modified problem many times.

234
Chapter 88. Set 85

2. Write a program to convert a tree to doubly link list in post-order fashion only change
of pointer are allowed that is left pointer can work as previous and right pointer s as
next.

This interview went well J

F-2-F round 2(Bar raiser)


Few question related to OS what is deadlock, Race-condition, Semaphore and many more,
few question Related to DBMS what is Normalization define all normal forms(I directly told
him I don’t remember I read it in 5th semester )

1. Why amazon??
2. Why do u want to leave company XYZ.
3. Your biggest challenge till the date.
4. Many project related question.

Data structure

1. U have given 10 files each having 1 million integer in sorted order, physical memory
have size of 3 million suggest method to extract 1 million integer in sorted form
efficiently.
2. Write a program to convert a decimal number into binary your code should work
on both big endian and small endian machine. U have given a variable which tell u
whether machine is big endian or small endian

DBMS and few bar raiser question made this round average L
F-2-F round 3

1. You have given an n-ary tree write a program to check whether this tree is sum tree
or not.
2. Given an array write a program to find kth smallest element in the array. He was
hardly interested in the solution he just want to know how many ways u can solve it
solved using 5-6 method at the end he was satisfied with the answers.

F-2-F round 4
Longest one….this interview went on for 1 hour and 30 minutes but was interesting
one(interviewer looked lyk a frustrated guy…some tyms I felt that he is going to punch me
� :P)

1. You have given M array each of size n all array are sorted separately write a program
to make a big sorted array of size m*n . during discussion he told me to prove
many lemma like height of tree is log(n)( for n elements) sum of n natural number is
(n*n+1)/2 and many more. He modified problem many times don’t use extra space
do it in space etc. discussion went on for almost 1 hour but at the end he was happy
with the solutions(I suggested 2 method and further optimization in them.

235
Chapter 88. Set 85

2. U have given an binary matrix which is sorted row wise and column wise write a
program to search a row in the matrix having maximum number of zeroes.

Finally this interview also went well he was happy with my performance
After 2-3 days I got mail from the HR that I m rejected LL reason was bar raiser … 1 advise
to all don’t take BR round lightly it does not matter how well u performed in other round
if u didn’t do well in BR round then there is no way u can make it. An average round tech
interview is fine but average BR round means rejected.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-85/

236
Chapter 89

Set 86

Amazon Interview | Set 86 - GeeksforGeeks


This is an account of my recent interview experience with Amazon. My process started off
at one their hiring drives. It was a tiresome process that comprised a written round followed
by six rounds of interview, spanning around 37 days.
Following is an account of my experience:
Round 1 (Written round):
1. Given two linked lists each of which represent a number, write a function that returns a
linked list that represents the sum.
2. Given a sorted array of numbers. Construct a balanced binary tree with the numbers in
the Array as keys.
3. Given a sorted Array of numbers that has been rotated by a few positions, write a
function to search an element in the Array.
Round 2 (F2F):
1. Given a binary tree in which the node structure has an additional field called “next”
which of pointer to tree node type, fill up this field of each node to point to the next node
at the same level (NULL if last node).
2. Sort an almost sorted Array. An almost sorted Array being an Array in which a number
is at the most k positions away from its position in the sorted Array.
3. You are given a 2D grid in which each cell is either empty, contains an entry “D” which
stands for Door, or an entry “W” which stands for wall (Obstacle). You can move in any of
the four directions from each empty position in the grid. Of course you cannot move into a
cell that has “W” in it. You need to fill each empty cell with a number that represents the
distance of the closest door to that cell. (They asked me only for the Algo as there wasn’t
much time).
Round 3 (F2F):
1. Given a 2D (Rectangular) grid of points. You need to find the shortest path from a
given source point to a destination point. You can only move up or right. Now among

237
Chapter 89. Set 86

these points, there a few special points from which you can directly jump to the diagonally
opposite point (Top-Right diagonal). You are granted a function which when invoked on
the point returns 1 if it is a special point and 0 if it is not.
2. You are given a sequence of black and white horses, and a set of k stables numbered 1 to
k. You have to accommodate the horses into the stables in such a way that the following
conditions are satisfied:
a. You fill the horses into the stables preserving the order of horses. For instance, you
cannot put for horse 1 into stable 2 and horse 2 into stable 1. You have to preserve the
ordering of horses.
b. No stable should be empty and No horse should be left unaccommodated.
c. Take the product (number of white horses * number of black horses) for each stable and
take the sum of all these products. This value should be the minimum among all possible
accommodation arrangements.
Round 4 (F2F with Hiring Manager):
1. Discussion on my current work, difficulties and challenges faced at work, difficult people
I have had to work with, instances when I went out of my way to propose creative solutions
to existing problems at work etc.
2. Given a parentheses string, determine if it is a valid / legitimate parentheses string. For
strings consisting of single parentheses type and those consisting of multiple types.
Round 5 (F2F – Bar Raiser):
1. Discussion on my current work, difficulties and challenges faced at work etc:-
2. Given a floor of dimensions 2 x W and tiles of dimensions 2 x 1, write code to find the
number of ways the floor can be tiled.
3. Given a graph, if we were to print all nodes within k hops of a given node, which algorithm
would we use, the answer to this was obviously a Breadth first search. He followed it up
asking, if one were to use Depth first search instead to code this problem instead, one would
encounter bloated running times for Graphs with certain attributes (Perhaps Dense graphs
or some such). Describe what types of graphs would a DFS algorithm falter with and why.
Round 6 (Telephonic Interview):
1. Given that you want to maintain a backend for a bookstore Application that would store
names of Authors and books, such that the application can return all the books written by
a specific Author and all the Authors of a specific book which is specified in a query. The
query can be such that only a substring of the Authorname or the bookname is specified
and all the matches should be returned. I proposed a trie based solution, and was asked to
code the solution on a collabedit shared document.
2. Describe multithreading.
3. Describe all the processes that happen between you typing in a URL and the webpage
appearing on your screen.
4. What is a singleton set What is the data storage model (Data structures) used to store
records in a relational Database.
5. Given an Array containing numbers between 1 to n, out of which 1 number is missing,
find the missing number.

238
Chapter 89. Set 86

6. Given a sorted Array and a number, print all pairs of numbers in the sorted Array that
sum to the given number.
I got the confirmation call the same evening that I had the telephonic interview. Geeks-
ForGeeks is a godsend for interview aspirants aiming at top companies. Keep
up the outstanding work guys, your website has shaped careers and lives. J
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-86/

239
Chapter 90

Set 87 (For SDE)

Amazon Interview | Set 87 (For SDE) - GeeksforGeeks


I recently cleared the Amazon SDE position. Through out my prepration GeeksforGeeks
played great role, this is the only site which i referred/followed more than 90% of the time
during preparation phase.
Please find my experience with amazon below.
1 Written test
1) Given a array of number find the next greater no in the right of each element

Example- Input 12 15 22 09 07 02 18 23 27
Output 15 22 27 18 18 18 23 27 -1

2) Given a link list and input int K, reverse the link list in K size slots

Example Input 12--> 13--> 3--> 20--> 55--> 87--> 20--> 77--> 90 Lets k =3
Output 3--> 13->12--> 87--> 55--> 20--> 90--> 77--> 20

3) Given tree and input int K, Print the nodes that are k distance way from leaf.
Input is below tree and k = 2

240
Chapter 90. Set 87 (For SDE)

Output-2, 5, 4
2. First F2F round (DS and Algo)
Two interviewer was there in panel, Only one was asking question other was only observing,
He was noting down all the conversation happening between us and noticing approach and
solution provided by me. This was common in all the interview rounds.
1) Given a infinite string of O’s and 1’s respectively. You need to find the transition point
from 0 to 1.
I gave the native solution in O(n). He told to optimize more. Direct binary search can’t be
applied on it because string was infinite and length of string was not given.
I told that i will divide the string in 10 size slots it will reduce complexity. Still he told
to optimize more. I told i will increase the slot size in power of 2 like 2,4,8,16,32. he was
satisfied with that.
He again complicate it by adding that now my string contain 0, 1, 2 in sorted order. You
need to find transition point from 0 to 1 and 1 to 2. i provided the approach.
After that told this time i want to make it generic. String can contain 0 to n(input) number
find all the transition point. I solved it, he was satisfy with approach and told me write
code for it.
2) Find common elements out of two sorted array
3. Second F2F(DS and Algo)
1) It was bit difficult for me to crack, She stated asking from java cloning, which was my
weak area. Given a class which contain string Name and reference to person friend, clearly
shown below.

Class A {
A(String str, Person P { //Constructor
this. name = str;
this.friend= P ;
}
// override
Clone() {

241
Chapter 90. Set 87 (For SDE)

// code for this function was expected from me


// which can produce the deep copy
}
}

Suppose A–>B–>C–>D means A is friend of B, who is friend of C and so on..


Calling once the Clone method will clone the whole friend list like
A’–>B’–>C’–>D’ (there A’ is the clone of A).
Cracking this was really tough for me, because i was not familiar with these question.
2) How to find the last nth element from singly link list, its was very easy for me.
Solved in 2 min and wrote the code quickly.
3) Given a sorted array of number , value K and value X, find the K nearest number to the
value
Example: Input 12 16 22 30 35 39 42 45 48 50 53 55 56 K = 4 X = 35
Output 22 30 39 42
Interviewer was running out of time because 1st question took huge time. So she told to
tell only the approach, code was not expected.
4. Third F2F (Bar raiser)
Interviewer was of friendly nature. He was very senior and very cool guy. Started with my
project question and then some behavioral question and in last one technical question

1. What is your current project, What value you added in your project till now.
2. What challenges you faced while working in project and how did you overcome.
3. What was the important learning for you in last project.
4. If you have the option to go 3 year back in life, then what would you like to change
in life, means which skills and steps/decision you want to gain or change.
5. What you did in past on which you feel proud.. blaa blaa….
6. Given a tree, how will you find the vertical sum of nodes
refer this link to understand more about question
https://www.geeksforgeeks.org/vertical-sum-in-a-given-binary-tree/
I gave the solution using Hash map, but he was not satisfy with answer. He told to
gave other solution because Hash map will increase the space complexity. I used array
solution which was increase time complexity, then i used circular link list and finally
solve it using doubly link list. He was satisfy with solution. Told me to code for it.

5. Forth f2f round(OOPS, design pattern and OS fundamental)

1. Started with my project details, my project was in android mobile, so he told me to


design a “Contact application”. Class diagram and their relationship was expected
from me. What all design pattern you can use in that.

242
Chapter 90. Set 87 (For SDE)

2. Explain inheritance and Base class is given you need to stop exposing the base class
methods without touching the base class at all. It was really tricky. question i liked
it.
3. What is deadlock and How to detect deadlock in system.

4. Concept of Database normalization and various types of it.


5. He also started asking some networking question. Like TCP/IP, socket connection.
6. How the chat between 2 user work internally, internally how the packets flows between
layer. And suppose user A send “Hi” message to user B and user B just shutdown the
system. What will happen in that case.

6. Fifth f2f (Hiring manager)

1. Why you want to join Amazon.

2. What did you know about Amazon.


3. Current project explanation.
4. What new code you implemented and how much impact it put on other.
5. Given a tree, write the In-order traversal. I wrote in 2 min using recursion.
Next addition was, can you write it using iteration tried and wrote some buggy code.
He started checking and told the bug and told me to correct it. Even-through i solved
the same question at my home, Still it was not clicking my mind. I started correcting
it but failed. After that interviewer gave one hint. I used the hint and solved the
whole code again. He was running out of time so took the code sheet and told i will
check it later in free time.
Refer this link for actual solution and proper understanding of last question
https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/

Message for all :-


Amazon expect accurate and precise code with less complexity. So discuss first with your
interviewer the approach. Don’t jump into code.
Even if you don’t know the right answer, keep on discussing various possibilities to solve the
question and try crack that problem with different angle. Practice more and more verity of
questions.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-86-sde/

243
Chapter 91

Set 88

Amazon Interview | Set 88 - GeeksforGeeks


Online Test:

1. Rectangle overlap problem


2. String searching problem
3. Coin change problem

1st Telephonic interview:


Questions regarding processes in OS(how it is represented in memory like code segment,
data segment, stack , heap), garbage collection , stack and heap , what happens when a
URL is entered in browser and then proceeded to 2 programming questions

1. Given a BST, transform it into sum tree where each node contains sum of all nodes
greater than that node.
2. Shuffle an array

(All arrangements were done by Amazon including travel, stay)

Onsite F2F 1:
Started with general introduction , asked about my work , know any design patterns and
where you applied them in your project etc.
He asked a single question to design a single stack with push , pop and pop mid operations
, followed by working code.

F2F2:
Again started with general introduction , work i do , then he gave a question about finding
count of each occurrence of words in a document.

244
Chapter 91. Set 88

I gave hashing based solution (with working code), it lead to a great discussion on hashing
, then he led me to give a solution with tries . As much time is not left he asked me to tell
the approach only.

F2F3 (With Bar raiser):


Bar raiser will be from a different team.
He asked me a question to connect siblings at each levels of a binary tree , as i knew this
question already. He wanted working code. After i gave the code he found a bug and i found
one myself.After resolving the code he moved on to different question.
Next question is optimal implementation of 3 or more stacks in a single array.I gave some
approached based on heuristics and with extra memory.He dint seem satisfied and then
asked many questions about work i do and grilled me on many aspects.

F2F4(With Hiring Manager):


Asked me to design Automated Air traffic controller system . Gave me few requirements ,
made me identify classes and its members , and some high level code for identifying probable
aircraft collisions.
He asked me about situations where i missed the deadlines and learnings from it , How do
you build trust with Customer .
Then i asked him few questions like What specific qualities you look for in a potential candi-
date , How an SDE can contribute to Amazons claim to be most customer centric company
and any concerns about my employment background (as i am working in manufacturing
industry currently).
Interviews were held on friday , i got a call from HR lady on Tuesday following week.

Some tips:

1. Practice lot of pen and paper code.


2. Folks at amazon do not want pseudo code , they want working code with minimal
syntactical errors.
3. Online plus telephonic rounds are for screening only.Also , Don’t pass the time in
telephonic rounds, they want to give at least two questions (easy though)
4. McDowell’s book and recent 40 sets of amazon interview experiences will make you
good to go.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-88/

245
Chapter 92

Set 89

Amazon Interview | Set 89 - GeeksforGeeks


Online round:
1) Program to check if two rectangles overlap.
2) Program to find if a given string, say S, contains another given string, say P.
3) Write a program to check if the coins can be summed up to a given number, if yes print
the coins that sums upto the given sum.
Telephonic round:
1) Given a singly linked list, modify the value of first half nodes such that 1st node’s new
value is equal to the last node’s value minus first node’s current value, 2nd node’s new value
is equal to the second last node’s value minus 2nd node’s current value, likewise for first
half nodes.

Ex:
1) 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7
Modified list:
6(7-1) -> 4(6-2) -> 2(5-3) ->0(4-4) -> 5 -> 6 -> 7
2) 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
Modified List:
7 -> 5 -> 3 -> 1 -> 5 -> 6 -> 7 -> 8

2) Reverse the alternate level nodes of the binary tree.

Ex: Given tree:


a
/ \
b c
/ \ / \
d e f g

246
Chapter 92. Set 89

/ \ / \ / \ / \
h i j k l m n o

Modified tree:
a
/ \
c b
/ \ / \
d e f g
/ \ / \ / \ / \
o n m l k j i h

Face to Face Rounds:


Round 1:
• Thorough discussion about one project that I considered as the most interesting or chal-
lenging.
• Suppose we need a service to perform certain task every day at some specified time. How
do we ensure that everyday at the specified time the service will do that task?
• Design a stack that supports push, pop, and retrieving the minimum element in constant
time.
• Program to get the maximum distance between two nodes in the binary tree. The inter-
viewer further generalized this problem for n-ary tree. Then he asked how to get the longest
path in a graph.
Round 2:
• What happens when we enter the url in the browser?
• Difference between inner join and outer join.
• How does the garbage collector works in java?
• Questions on stacks and heaps(memory management).
• We have n gold coins. We need to amalgamate all the n coins to create one single coin,
we can merge two coins at once. The cost of merging two coins is equal to the value of those
coins. How do we ensure that the cost of merging n coins in minimum.
Ex: 5 ,8 , 4, 3, 9, 6
We will merge 3 and 4, cost=7 {Remaining coins: 5,8,9, 6,7}
Then we merge 5 and 6, cost=11 { Remaining coins: 11,8,9,7}
Then we merge 7 and 8, cost=15 { Remaining coins: 11,15,9}
Then we merge 9 and 11, cost=20 { Remaining coins: 20,15}
Then we merge 20 and 15, cost=35 { Remaining coins: 35}
Total cost: 7+11+15+20+35 = 88
If we had merged the coin array {5, 8, 4, 3, 9, 6} in different fashion:
Merging 5 and 8, cost=13 {Remaining coins: 13, 4, 3, 9, 6}
Merging 13 and 4, cost=17 {Remaining coins: 17, 3, 9, 6}
Merging 17 and 3, cost=20 {Remaining coins: 20, 9, 6}
Merging 20 and 9, cost=29 {Remaining coins: 29, 6}
Merging 29 and 6, cost=35 {Remaining coins: 35}
Total cost: 114
As we can see that the cost is less in the first case. Program to get the minimum cost of
merging all the n coins.

247
Chapter 92. Set 89

• Replace BST nodes with the sum of nodes greater than or equal to the node.
Round 3 (Hiring Manager):
• Detailed discussion of my work in the current company.
• Some behavioural questions like how do you handle certain situations etc.
• Design a restaurant reservation system. I was also asked to write some sql queries in this
regard.
Round 4 (Bar Raiser):
• Given a linked list, write a function to reverse every k nodes (where k is an input to the
function).
• Given a sorted array which may contain duplicates, write a method to find the starting
and the ending index of the given number if present.
Suppose we are give array: 1,2,2,2,5,6,6,9,10,10,10
If the number given is 9 then starting index and the ending index will be 7.
If the number given is 2 then the starting index will be 1 and the ending index will be 3.
If the number given is 7 the the starting and the ending index will be -1 as the number is
not present in the array.
• Write a method to compress a given string “aabbbccc” to “a2b3c3” . It should be an
inplace compression, no extra space to be used.
• Discussion about my current project.
• Describe a scenario when you failed, when you helped our collegue etc etc.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-89/

248
Chapter 93

Set 90

Amazon Interview | Set 90 - GeeksforGeeks


1. Phone Interview
a. Given sorted array in decreasing order. Find first occurrence of given key.
b. Find diameter of a binary tree.
2. Face to face 1 (Programing skill)
a. https://www.geeksforgeeks.org/dynamic-programming-set-31-optimal-strategy-for-a-
game/
b. Merge N sorted lists to a single sorted list but comparisons should be minimum
3. Face to face 2 (DS round)
a. 1 represent A, 2 rep B etc and 26 rep Z. Given a number, find number of possible decoding
for this number. No need to consider number starts with zero. Eg: input – 1234, output –
3(ABCD, AWD, LCD)
b. How to find a loop in linked list. How to remove this loop.
c. How to design LRU cache(looking for the DS’s used and their interaction)
4. Face to face 3(Design)
a. A device need to upgrade and downgrade its software. Eg: mobile phone need to upgrade
its OS. Design high level and low level.
(follow-up – 1. form version X to Y is not possible but z can. 2. from current version to
latest version not possible but we can upgrade to an intermediate version and then to latest
version. What
DS will be effective here)
b. Design a semaphore.
5. Face to face 4(curtain raiser)
a. HR questions including prev projects, best work etc
b. Given a linked list where each node contains an extra arbitrary pointer which points to
any node in the list. Write code to clone the list.
b. Print vertical sum of a binary tree.
c. Print a binary tree in vertical zig-zag order.
6. Manager round

249
Chapter 93. Set 90

a. manager round HR questions. Team fit questions etc.


b. Given a mathematical expression. How to design this expression evaluator using OOPs
concept.
Each round consists of 1 to 1.30 Hrs.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-90/

250
Chapter 94

Set 91

Amazon Interview | Set 91 - GeeksforGeeks


I recently got interviewed with Amazon for SDE position for their Hyderabad office.
Round 1: (F2F)

1. Discussion around current company and work I was doing there. Why Amazon?
2. There is a robot standing at first cell of an M*N matrix. It can move only in two
directions, right and down. In how many ways, it can reach to the last cell i.e. (M,
N). Discuss all the approaches and then asked to code it.
3. Remove the nodes in the binary tree for that the sum of all values from root to leaf is
less than K.

Round 2: (F2F)

1. Convert a Binary Search Tree to DLL in-place.


2. Implement LRU policy.
3. Find the First Non Repeating Character in a stream of characters. Use Constant
Space and linear complexity in terms of character count.

Round 3: (F2F)

1. Why do you want to leave your current organization?


2. Current Project Discussion and your contribution in the project.
3. Some Nice Behavioral questions.
4. Given a magazine of thousands of pages. You have to construct a note out of it by
cutting the words out of it. You can only cut whole word from magazine and you can’t
add any words. Also, you can’t cut partial words or alphabets from it.

Round 4: (F2F)

251
Chapter 94. Set 91

1. Given an array of size N= k*s. In this array, construct blocks of k size each (Number of
such blocks will be s). Now find all combinations of these numbers such that difference
among the k numbers in the block should not be greater than d. e.g. N=6, k=2, s=3
A={2,4,6,8} and d=2. So the answer should be 2 {{2,4},{6,8}},{{4,6},{6,8}}.
2. Given a binary tree with usual left and right pointers and one additional pointer called
adj. modify the tree in-place such that adj pointer should point to the right node in
same level as current node or if it there is no node right to it, adjshould be NULL.

Round 5: (F2F)

1. How many Binary Search trees can be constructed using sequence of N numbers?
Write Code for it.
2. How many cycles of length 3 can be constructed using edges of aundirected graph?

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-91/

252
Chapter 95

Set 93

Amazon Interview | Set 93 - GeeksforGeeks


I have just completed a full interview with Amazon and wanted to give back to Geeks-
ForGeeks my experience because it has helped me so so much to go through it.
1st phone interview
Why Amazon?
How do you find out the cause of a slow UI request?
Write function to convert a stream of incoming characters to an integer.
Write function to convert one character to one digit number.
2nd phone interview
Get nth to last element
Check if 2 binary trees are equal recursively and iteratively
On-site interview
1st interview
Write a url shortner. Design scalable architecture that host this service.
2nd interview
Array vs linked list. Rest vs Soap. What is a hashtable? Write code to handle hashtable
collisions?
3rd interview (lunch)
Situation where you missed a deadline.
What are you proud of the most in your career?
Situation on how you handled conflict.
Other behaviour questions
4th interview
Why Amazon?
Build a clone of a binary tree sent from a different machine
5th interview
Design and implement algorithm to find the shortest path from start to finish of a maze.

253
Chapter 95. Set 93

I thank GeeksForGeeks for all the help it gave me.


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-93/

254
Chapter 96

Set 95 (For SDE-I)

Amazon Interview | Set 95 (For SDE-I) - GeeksforGeeks


Hi, Below is my interview experience for Amazon for SDE-I position.
Round-1(F2F)
1.) Traverse a binary tree in a spiral manner. (zig-zag manner)
2.) Given a number, find the just greater number than the given number containing the
same digits as the given number. Write code for this.
Round-2(F2F)
1.) Print a binary tree in a level order traversal but in bottom to top manner.
2.) Given 2 BSTs, validate their equality. Both are equal if they consist of the same set of
values
irrespective of their structures. (Can you traverse them parallely).
3.) Given a infinite stream of integers, find the first non-repeated number till now. Write
code for this.
Round-2(F2F)
1.) Given a binary tree, convert it into doubly linked list and after the conversion, the linked
list should
look like the post order traversal of the binary tree. The conversion should be in-place.
What is the time and space complexity of the program.
2.) Given the following sequence
A, B, C,…..Z, AA, AB, AC,…….AZ, BA,…..BZ…..ZZ, AAA…..
1, 2, 3,…..26,27………………………………………..
Given n, return the string. What is the time and space complexity of the program.
Write code for this.
Round-4(F2F) – with Hiring Manager
1.) Given an array, return the second largest number. Write code for this.
You can not modify the array, just traverse the array once and return the required number.
Handle all the edge cases. What should be the function signature.
2.) Given two files which contain very large size of number, say the size of the file is 5 GB.

255
Chapter 96. Set 95 (For SDE-I)

That means that you can not load the whole file into memory. How would you add these
two files and store the result in another file. Long discussion on optimization.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-95-sde/

256
Chapter 97

Set 96 (On-Campus for


Internship)

Amazon Interview | Set 96 (On-Campus for Internship) - GeeksforGeeks


I’m a 3rd year grad and amazon visited our campus. My interview had only 3 rounds.
Round 1 (Online round 20 MCQ’s and 2 coding questions )
MCQ’s were mostly on data structures ,time complexities and C,C++ outputs with 2 apti-
tude questions.
1) Given 2 linked lists of digits as data in their nodes add two numbers.

Eg: 1 -> 2 -> 3 -> 4 and 4->3


print 1 - > 2 -> 7 -> 7

2) given few sets of intervals print out the the entire intervals without overlapping , if they
overlap then combine them into one.

Eg: Input : (5,7) (1 , 6) (2 ,4) (10 ,14) (8,9)


Output : (1,7) (8,9) (10,14)

Round 2 (F2F)
Tell me something about yourself.
1) Convert a BST into inorder, preorder and postorder linkedlists inplace.
2) Make a queue out of 2 stacks, as it was easy he asked me to code and asked me the
complexities.
3) Given a linked list with a loop find the loop and make it straight . I did with HashMap
but he told me not to use extra space so i told him floyd’s cycle.
He asked me i had any questions.

257
Chapter 97. Set 96 (On-Campus for Internship)

Round 3(F2F) (After lunch)


1) Given a Binary tree convert into a BST no auxillary space (i did it with an inorder
traversal) he asked me to code.
2) Given an infinite stream of characters find the first non repeating character at any instance
, The storing,retrieval should be o(1) .
I told him a solution using a hashmap then he modified that he may have millions of unique
characters not just alphabets.
i gave a solution with a linked list and a hashmap. This question was not asked to me but
was to my friend .Its a good one.
3) print all the binary values of number from 1 to n , each number’s binary should be printed
in 0(1).
for eg: n = 6
then print 1 10 11 100 101 110. printing 1, 10 ,11 ,100,101,110 should be in o(1) each
I thank Geeksforgeeks for letting me know about Floyd’s cycle .
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-96-campus-internship/

258
Chapter 98

Set 97 (On-Campus for SDE1)

Amazon Interview | Set 97 (On-Campus for SDE1) - GeeksforGeeks


I had my amazon interview few days back in my campus.
First Round:
First round was a simple round. It had 20 MCQ questions on C/C++ and 2 coding questions.
The coding questions were:
1.) You have given an array in which numbers are first increasing and then decreasing. Find
the maximum element in O(log n).
2.) Swap the data of alternate nodes of a list.
We were given 90 minutes for 22 questions. For objective questions, you should be clear
with virtual functions, inheritance, data types etc.
Second Round:
In this round, we were divided in groups. And a tree problem was given. We have to solve
them individually.
My problem was:
Given a bst and two boundary values. Prune the tree if the node data lies outside the
boundary values
Round three:
In this round,
1) Reverse a doubly linked list and a singly linked list. Both iterative and recursive. Which
one is better approach and why?
2) Can you reverse a list in less than O(n)?
3) Differences between list and array. Which data structure you like and why?
4) How will you find the kth node from last in a list? Discussion on optimization
5) Given a string. Print all permutations of it. Discussion on time complexity and optimiza-
tion.
Round four:
1) Interleaving of a string. A big discussion on various test cases. Your code should handle
the case if the string contains repeated characters.

259
Chapter 98. Set 97 (On-Campus for SDE1)

2) Check if a binary tree is a bst or not


3) find diameter of a tree.Follow up how will find the height of a binary tree?
Round five: Problem Solving round
1) Given an array of heights of poles. Find the no of poles which are visible if you are
standing at the ith pole.
2) You have a you tube video. A person watches the video in random order. You have given
the start and end time of various intervals he watched. How will you confirm whether he
has watched the full video or not.
3) Given a number. How will you find the next greater number with same digits.
Round Six: (HR round)
1) tell me about yourself.
2) why amazon?
3) Project discussions.
4) A little discussion on OOPS.
All the best Guys.. �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-97-campus-sde1/

260
Chapter 99

Set 98 (On-Campus)

Amazon Interview | Set 98 (On-Campus) - GeeksforGeeks


I am a fourth year undergraduate CSE. I had my amazon interview in my campus.
First Round:
First round was a simple round. It had 20 MCQ questions on C/C++ and 2 coding questions.
The coding questions were:
1.) You are given a string that represent an expression of digits and operands. Eg. 1+2*3 ,
1-2+4. You need to evaluate the string or the expression. NO BODMAS is followed. If the
expression is of incorrect syntax return -1.
Test cases :
a) 1+2*3 will be evaluated to 9.
b) 4-2+6*3 will be evaluated to 24.
c) 1++2 will be evaluated to -1(INVALID).
Also, in the string spaces can occur. For that case we need to ignore the spaces. Like :- 1*2
-1 is equals to 1.
2.) You are given an array of both negative and positive integers. You need to rearrange the
array such that positive and negative numbers alternate. Also, the order should be same as
previous array and only O(1) auxiliary space can be used and time complexity boundation
O(n).
eg. -2 3 4 5 -1 -6 7 9 1
result – 3 -2 4 -1 5 -6 7 9 1.
Second Round:
In this round, we were divided in groups of 5. And two problems were given and we need
to write the code on paper for that problem.
My code were :
1.) You need to determine whether the linked list is palindrome or not.
2.) Print the level order traversal of the binary tree in the spiral form.[They also asked us
the solution without any extra space and O(n)
Time complexity].

261
Chapter 99. Set 98 (On-Campus)

Third Round(F2F):
Interview asked me to write the code for the two problems which are :
1.) Reverse the alternate K Nodes of the Linked List.
eg. 1->2->3->4->5->6->7->8->NULL
Result – 3->2->1->6->5->4->8->7->NULL.
2.) You are given the binary Tree and the two nodes say k1 and k2 . You need to determine
whether the two nodes are cousins of eachother or not.
eg. 6
/\
35
/\/\
7813
and say two node be 7 & 1. result will be TRUE.
say two nodes are 3 & 5. result will be FALSE.
say two nodes are 7 & 5. result will be FALSE.
3.) Give the algorithm, data structures, time complexity and space complexity for the
following problem :
In our mobile phones when we enter say four initials of the number say 9 4 5 6, then our
phone shows the whole lists of number that starts with these entered number.
Now the problem is : how it is implemented and what is the best way of doing this keeping
the balance between space and time complexity. Also, user can enter any number of initials
and your program should print all the numbers with those initials that are present in your
phonebook.
Fourth Round(F2F):
Interviewer asked some questions on C++ . They were :
1. What are virtual functions?
2. What is the use of virtual functions?
3. What are pure Virtual functions?
4. Syntaxes of Virtual functions and pure virtual functions?
5. What are abstract classes in C++?
6. How we can implement pure virtual functions in JAVA ?
Design question :
How we can restrict our class so that only single instance of it can be created?
What is Singleton Design Pattern?
Operating system Question :
1. What are semaphores?
2. What is producer consumer problem and give different solution for it?
Two questions he asked me to code :
1.Convert one string to another string.For that purpose you can use three operations –
SUBSTITUTE,DELETE,INSERT.Each having cost as one except
substitute having cost 2.You have to determine the minimum cost required.
For eg.
First String : INCLINE
Second String :DECLINE
Minimum cost required are : 4 [change I to D and N to E].

262
Chapter 99. Set 98 (On-Campus)

2. Implement the stack in which push(),pop() and getMiddle() has O(1) complexity at any
point of time.
3. Find the maximum size BST present in the binary tree.
He also asked question about my projects and why I choose them. He asked to just explain
the whole set of thing that I have performed in it.
(About 10 minutes discussion)
Fifth Round(F2F):
This round started with the deep discussion about my projects. Interviewer tried to get
each and every aspect of my project with lot many why
and how questions.She asked me the future scope of my project and what are learnings I
got from it.(About 30 minutes discussion).
Then she asked me implementation, algorithm, data structures, time complexity and space
complexity for the following problem:
Say we have website having several web-pages. And also there are lot many user who are
accessing the web-site.
say user 1 has access pattern : x->y->z->a->b->c->d->e->f
user 2 has access pattern : z->a->b->c->d
user 3 has access pattern : y->z->a->b->c->d
user 4 has access pattern : a->b->c->d
and list goes on for lot many users which are finite and numbered.
Now the question is we have to determine the top 3 most occurring k-Page-sequence.
for the above example result will be : (k=3) a->b->c , b->c->d , z->a->b.
[Question took the long discussion and she kept adding constraints, cases and more problems
to the above problem.]
One question she asked me to code which is:
You are given a sting. Find the character in that string which is not repeated and which
occur last in the sequence.
Eg.- aababaacdffgxc
Result – x
I would like to thanks GeeksForGeeks which helped me to improve my knowledge and
understanding of Data structures and Algorithms �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-98-campus/

263
Chapter 100

Set 99 (On-Campus)

Amazon Interview | Set 99 (On-Campus) - GeeksforGeeks


Amazon interview experience :-
1st Round :-
20 mcq and 2 coding questions
1. Left view of binary tree
2. addition of 3 link list
2nd round F2F :-
1. check listlist is palindrome or not
2. level order traversal in spiral form
3rd round :-
1. Length of the longest substring without repeating characters
2. Length of the longest substring who occur more than one in string
like :- geeksforgeek so answer is geek.
4th round :-
tell me abt ur self
check tree is BST or not and code for it
Check number is power of 2 or not
what is Dns
difference btw TCP and UDP
one tough question is which i dont remember but it i dont know how to solve this question
but interviewer help me alot to crack this question and ask me to code for my algorithm.
5th round(HR round) :-
1. about myself
2. 15 min. about my project
3. given a string return character whose count is 1 and position is right most… example :-
aabccddefff so b and e count 1 :- so return e.
4. given a newspaper you have to find word in it.. so i solve it by trie.
suggestions :-
1. if you dont know answer of coding question so dont worry interviewer will help you. He

264
Chapter 100. Set 99 (On-Campus)

always give you hint and you have to think on that way.
2. GeeksforGeek
3. Always say interviewer what is your intrest subject.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-99-campus/

265
Chapter 101

Set 100 (On-Campus)

Amazon Interview | Set 100 (On-Campus) - GeeksforGeeks


First of all many many thanks to geeksforgeeks for such a great guidance. Amazon visited
our campus for recruitment. Here is my interview experience.
Round -1
20 MCQs (C ,Aptitude,DS,DBMS,Networks)
2 programming questions were asked-
1.) Print all root to leaf path of a given binary tree whose path sum is a given value k.
Note: tree was given in the form of array (so no need to create the tree).
Input: Input contains two space separated integers K and L followed by 2^L-1 space sepa-
rated values
Output: All root to leaf path which has a path sum = k.
Sample Test case :
Input :
40 4 10 11 13 # 15 28 6 # # 8 4 # 9 11 #
Output:
10 11 15 4
10 13 6 11
2.) Given few sets of intervals print out the the entire intervals without overlapping, if they
overlap then combine them into one.
Sample test case:

Input : (5,7) (1 , 6) (2 ,4) (10 ,14) (8,9)


Output : (1,7) (8,9) (10,14)

Group fly Round:


2 ques were asked in this round. We were asked to write code on paper very fast.(It was an
elimination round.
1.) Given a binary tree as below

266
Chapter 101. Set 100 (On-Campus)

A
/ \
B C
/ \
D E
/ / \
F G H

Convert the structure of the tree like a left aligned tree whose each node contains a down
pointer and a right pointer and looks like the below tree..

A
|
B – C
|
D—E
|
F—G – H

2.)The arrival and departure time of trains are given. Find the minimum number of plat-
forms to accommodate all the trains.

Eg. Arrival Departure


7 11
8 10
13 14
4 6
Output: 2

Round 2. (F2F)
1. An array is given in which elements are first monotonically increasing and then decreasing.
Search an element in the array. Working code was asked which takes care of all the edge
cases. Also asked the time complexity of the code.
2. Implement queue using 2 stacks .
What would be the complexity of enqueue and dequeue operation. I told him O(1) for
enqueue and O(n) for dequeue. Then he asked to optimize it. Then he asked the Average
case time complexity.
Round 3 (F2F)
1. You are given a graph. Write a function to remove all the cycles. Means after the function
call the graph must be converted into a connected acyclic graph(tree).
2. What happens when u send an email to someone.
3. What is socket ? What is port?
4. Which protocol is secure for mail transfer? Which protocol is used by Gmail?

267
Chapter 101. Set 100 (On-Campus)

5. What is the port number of SMTP?


6. Suppose u open notepad and type something and save it what would happen.
7. What is static member?
8. What is singleton class??
9. If a class has all its members as static would it be a singleton class? Compare them.
10. What is process scheduling? How does it happen? What are various queues maintained
by the system? (Where does the scheduler process run ??- This ques was asked in 2nd round
of DE Shaw & co).
11. Suppose various process are waiting for a particular resource? What is this situation
called? How does the system overcome from this problem?
12. What the various ways of process communication?
13. What is thrashing ?How to overcome from it?
Round: 4.)(HR + Technical)
1. Tell me something about yourself
2. A long discussion on project. Brief description. How can you improve it?What changes
will make if I ask you to develop it again? Give example of implementation of various oops
concept in your project.
3. What is multithreading? Then he said that there are situations where there is no need of
multithreading.eg- if I want to add two numbers then no point of using multithreading.So
give an example where you can actually implement multithreading. (ANS – Fibonacci
number)
4. Some behavioral questions like-
What are you good at?
What are you proud of?
What are the things you want to change in yourself?etc.
5. Various oops concept like encapsulation, abstraction, inheritance , etc. with example.
Suggestions:
• Don’t start writing the code immediately.
• First tell him the approach .
• Take care of all the edge cases.
• Many times interview may give you hints so make the interview interactive.
• Very Important – Don’t focus just on a particular subject like only DS.
• More or less give time to everything.
• Study the concepts of OOPS and OS properly.
• Have a basic Idea of DBMS and Computer Networks also.
All the best.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-100-campus/

268
Chapter 102

Set 101 (On-Campus)

Amazon Interview | Set 101 (On-Campus) - GeeksforGeeks


Off late, Amazon had an On-campus recruitment. Here is the interview process.
1) Written Round

1. 20 MCQ’s

• two C code snippets


• a couple of questions of time-dist-speed
• easy questions on operating systems
• find the no.of network addresses of a class C address

two coding questions

• Given a set of inputs (x,y) which represent intervals, merge overlapping intervals
e.x. (3,4) ; (2,5) ; (1,4) ; (8,9)
output should be – (1,5) ; (8,9)
*note – my code had errors, but as i had used merge sort for sorting the inputs, i
cleared the first round, whereas others with properly working code but in-efficient
algorithms didn’t
• Given a (nXm) matrix, with values present in each cell and a few in-accessible cells
marked as -1, find the path from (0,0) to (n,m) with highest sum.

2) Interview Round 1

1. Given an array, find a pair with sum = k


*note – If you already know the approach/already coded a question before, let the
interviewer know before hand!

269
Chapter 102. Set 101 (On-Campus)

2. Given a regular expression, and a string, validate the string against the regular expres-
sion
e.x.
Regular expression : ab*bbc*c
Pattern : abbbc VALID
Pattern : abc NOT VALID

3) Interview Round 2

1. A couple of questions from arrays, binary trees and BST’s , which were directly taken
from DS section of geeksforgeeks.
(I said I have coded them all and know the approach)
2. Box stacking problem for 2 dimension, 3 dimensions.
(I said I know the approach for all)
3. Box stacking problem for k dimensions
(I didn’t know the approach, so tried it out in the interview. Nearly reached the
solution, with the help of the interviewer. In the end, turns out, this was the same
question which was asked to him, during his interview round in amazon 2 years back.
“SET 2”)

4) Interview Round 3

1. Same question from interview round 1, given an array, find a pair with sum k.
But, now I was asked to optimize the solution to O(n) time.
2. Explain how chat-messenger functions in Facebook,Whatssap
3. Validate whether a given 9X9 matrix is a sudoku matrix or not.
(In all cases, the goal of this round was not to check your coding skills, but your ability
to handle all varieties of test cases!)

5) Interview Round 4
(This I believe, was probably a stress interview a.k.a Bar Raiser Round. The motive was
to shift your attention from one topic to another rapidly and see if you can handle the
questions that follow.)

1. Tell me something about yourself


2. The interviewer asked me to pick up a project from all those I had worked on. I chose
my B.Tech project related to Genetic Algorithm and Graphs
3. Explain the algorithm
4. How are graphs being represented in your project
5. Various ways to represent adjacency nodes (adjacency matrix, adjacency list)
6. Write code for adjacency list

270
Chapter 102. Set 101 (On-Campus)

7. Write code for reversal of linked list (iterative and recursive)


8. Which one would you prefer, arrays or linkedlist, if so why!
9. Why use double pointers to pass head of a linked list, why can’t we just return the
value from the function. Which one do you prefer and why.
(As I had done my code using double pointers.)
10. What is a stack and heap, and how is memory allocated
11. Given a step function f(i) whose value increases just once as we move from i = 1 ..
infinity,
Find the value of i, where the transition occurs.
(I suggested increasing the length for checking by a power of 2, and then when a
transition occurs, do a binary search within the boundary.)
12. Why increase the length in powers of 2 and not just increase it by a constant factor
of some value ‘n’

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-101-campus/

271
Chapter 103

Set 102

Amazon Interview | Set 102 - GeeksforGeeks


I had my Amazon Interview some days back and now I am posting my experience here.
Round 1 (Apt)
20 mcq question and 2 coding questions were there
Mcq consisted of questions from C, Data Structure, OS, and so on
Coding Question 1 – Given a String and a pattern find all anagrams of the pattern in the
original string. You need to print all the index of the location where the match was found
Ex –
INPUT – ABDACDBACA
ABCD
OUTPUT – 1 3 4 5 (at index 1 BDAC , at index 3 ACDB and so on )
Coding Question 2 – Given an array containing zero and non zero digits you need to
shift all the zeroes to the right of the array. Output should be number of non zero elements
present in array and minimum number of swaps needed to do so.
Ex –
INPUT – 1 0 -6 5 0 0 2 0
OUTPUT – 4 (number of non zero elements)
1 (swap 2 with 0 present at index 1)
1st PI
Started with a general introduction with the interviewer. Some basic introductory questions
like Tell me something about yourself and after we were settled he started asking question
1 . Given a binary tree store the vertical sum of the tree in a list.

272
Chapter 103. Set 102

2. Given a number you need to output the minimum number of factors needed to represent
that number such that none of the factors is divisible by a perfect square.
EX-
INPUT – 8
So number of factors of 8 (2*2*2 , 4*2 , 8) (NOTE : do not consider 1 because it is divisible
by all numbers) So minimum factor will be 1 (8) but it is divisible by 4 so not allowed then
minimum is 2(4 * 2) but again 4 is divisible by 4 so not allowed so finally answer is 3 (2*2*2)
OUTPUT – 3
You need to explain the logic of both the programs and then have to code both of them
2nd PI
General Introduction about myself and asked me my Weakness and strongness and again
once we were comfortable started asking questions

1. There are a number of houses in a row and each house contain some amount of money
in it. Now suppose you’re a thief and you want to steal money from this houses so
find the maximum money you can steal. Condition was that no two adjacent houses
can be robbed.
After doing this he asked me to also print the houses that were robbed
2. Given an expression consisting of opening and closing parentheses you need to find
the number of onions present in it.
Onion is any structure of the form ()
() – onion of size 1
(()) – onion of size 2
((())) – onion of size 3
So suppose if input is (()()) so output will be 2 because there are only two onions
present in it
Again Complete coding of the two functions was needed
Then he started asking questions on subjects – OS , Networking and a SQL query

3rd PI
Started with introduction and then he gave me question

1. Given an n–ary tree .Print the right view of the tree.


After that he added to print the right view in a zigzag way like first element from top
element , second from bottom third from top fourth from bottom and so on. Then
asked to print both the left and right view of the tree
2. Given an array of 0’s and 1’s print the numbers in the form of Fibonacci sequence i.e.
1st 1 zero then 1 one then 2 zero then 3 one and so on
Ex –
INPUT – 00101111011101011000

273
Chapter 103. Set 102

OUTPUT – 01001110000011111110 (Number of 0’s and 1’s in the input and output
must be same so if you run out of any of them then just simple print the remaining
number)

Coding of both the program’s was needed


4th PI (Bar Raiser)

1. Given a list of cities you can travel in an number of city now you need to find the
number of ways in which you can travel this cities.
2. Implement the pow function in logarithmic time.
3. Implement a DFA which will accept all string containing even number of 0’s and 1’s
4. Find the 2nd maximum number from a table using SQL query
5. Check whether a grammar is ambiguous or not

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-102/

274
Chapter 104

Set 103 (On-Campus)

Amazon Interview | Set 103 (On-Campus) - GeeksforGeeks


First of all, I would like to convey my special thanks to geeksforgeeks for such a special
guidance. Here is my interview experience:
First day:
Round-1 :
20 MCQs(Data structure, C, C++, OS, Probability ).
2 programs :
1. Given an array of integers. Segregate all the non-zero numbers at the beginning. Print
the number of non-zero integers and the minimum number of swaps required for these
operations.

Eg. : I/p : 1, 0, 0, -6, 2, 0


o/p : Number of non-zero integers : 3
Minimum number of swaps : 2

2. Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char
txt[]) that prints all occurrences of pat[] and its permutations (or anagrams) in txt[]. You
may assume that n > m.

E.g. : I/p : txt[] = “BACDGABCDA” pat[] = “ABCD”


o/p : Found at index 0
Found at index 5
Found at index 6

Second day:
Round 2 : PI
1. Discussion on Project.
2. Code : Given an array of integers. Find the minimum distance between two numbers.

275
Chapter 104. Set 103 (On-Campus)

I did it in O(N) time complexity.


Then he changed the question and asked what if the array is sorted and contains duplicates.
I did it in O(logN) time complexity.
3. Given a linked list. Segregate all the positive numbers at the beginning and all the
negative numbers at the end.
I did it in O(N) time complexity.
Round 3 : PI
1. Discussion on project.
2. Code : LCA of BST.
3. Code : LCA of Binary tree.
4. Discussion on heap and stack.
5. Code : Maximum subarray sum.
6. Os concepts : What is semaphore? Brief explanation on wait() and signal() operation.
Round 4 : PI
1. Discussion on oops concept. Asked me about copy constructor, virtual function, virtual
class,
Template, exceptional handling.
2. Discussion on Os concepts. Semaphore, different page replacement algos.
3. LRU implementation using stack ( I was not allowed to use any other data structure).
I did it using two stacks.
4. It was a modification of this question.
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided
into K compartments (numbered from 1 to K) and each compartment can be occupied by
at most one customer. Each customer that visits the restaurant has a strongly preferred
compartment p (1 ? p ? K), and if that compartment is already occupied, then the customer
simply leaves. Now obviously, the chef wants to maximize the total number of customers
that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve
this task. You are to help him with this. Given a list of N customers with their arrival
time, departure time and the preferred compartment, you need to calculate the maximum
number of customers that can dine at the restaurant.
Instead of restaurant and customers, I was given platforms and trains.
I was asked to design a data structure for that.
Third day :
Round 5 :
1. Discussion on project.
2. Discussion on different types of sorting techniques.
Difference between merge sort and quick sort. When and where are they used.
Discussion on counting sort.
3. Discussion on hash-map.
Design a data structure which will provide the same function as hash-map.
4. Code : Given an array : A1[] = 2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8
A2[] = 2, 1, 8, 3
Sort A1 in such a way that the relative order among the elements will be same as those are
in A2. If the element is not present in A2, append them at last in sorted order.
o/p : 2, 2, 1, 1, 8, 8, 3, 5, 6, 7, 9
I did it O(NlogN) time complexity.

276
Chapter 104. Set 103 (On-Campus)

Round 6 : (Bar-Raiser)
1. Code : Convert little endian to big endian.
2. Code : Kth max in a file.
I did it using min-heap, then he sked me to use other data structure. Then I did it using
Balanced binary search tree.
3. Code : Find the second non-repeating character in a string.
4. Given prime number p>=5 :
Prove that : (p^2 – 1) will be divisible by 24.
5. Given a decimal number N as a string of digits (only 0’s, 1’s and 2’s are there), how do
I check if it’s divisible by 3 using regular expressions only, without converting to int? I was
asked to design DFA for that.
I would like to thanks GeeksForGeeks which helped me to improve my knowledge and
understanding of Data structures and Algorithms
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-103-campus/

277
Chapter 105

Set 104

Amazon Interview | Set 104 - GeeksforGeeks


Online round:
20 MCQs on mathematics, probability, operating systems, DBMS, compilers and basic DS
concepts.
Coding questions (Full code required):
1. Given an array containing zero and non-zero elements, modify the array such that it has
the 0’s at the end and the non-zero elements at the beginning. Print the number of swaps
required and the number of non-zero elements.
2. Given a ‘pattern’ and a ‘text’ print the indexes of ‘text’ where any anagrams of ‘pattern’
occur.

Input:
abcdad (text)
abcd (pattern)
Output:
0, 1

1st technical:
1. Given a linked list reverse the even nodes in one pass and in O(1) space.
So 1->2->3->4->5->6->7->8 should be converted to 1->8->3->6->5->4->7->2.
2. Given an array containing integers, modify the array such that the 5’s are at the end and
the rest are at the beginning (maintaining the same order).
2nd technical:
1. 5 minute discussion about my OCR project.
2. Given an undirected graph, count the number of cycles with 3 nodes.
3. What is a spanning tree? Difference from tree, if any.
4. How to find the minimum spanning tree of a graph?
5. Given an array convert it to another array such that the following condition holds:

278
Chapter 105. Set 104

a < b > c < d > e < f > g < h where the modified array is {a,b,c,d,e,f,g,h} Input: 1,2,3,4,5,6
Output: 1,3,2,5,4,6 3rd technical:
1. What do you know about memory management in Operating Systems? What is segmen-
tation? What is paging?
2. Design problem: Given a station with n platforms. So each platform has one line. But
these n lines join into one, after leaving the platform (on both sides). Each train has to wait
a minimum of x minutes in the platform. Trains arrive from both ends. If all the platforms
are occupied they wait. There is also a point beyond the end of the platform (on both sides).
This point indicates that an incoming train has to wait at that point until a leaving train
(from that end) passes that point. Design the whole system.
3. How are big files stored in memory? What are the uses of B-tree? How is it more useful
than BST?
4. Given one billion file indexes and said that n files are missing. How would you identify
the file indexes of those who are missing?

4th technical:
1. Given an array of integers. This array denotes ‘our’ own ascending order of the elements.
So if the array is {2,3,1,4}, by mathematics we can say that 2<3<1<4. Given another array,
sort this new array in ‘our’ ascending order. Let’s say the new array is {1,2,4,3,5,4,9,2},
output will be {2,2,3,1,4,4,5,9}. Note that since 5 and 9 do not occur, they are sorted by
actual ascending order at the end. 2. Integers are coming in a stream. A special integer
(say -9999) denotes reset. Design a data structure such that when the special integer comes
the previous elements are printed in a zigzag way and all the elements are deleted (reset).
And then continues to accept other integers. What DS will you use?

Say the input is


1,2,3,4,5,6,7,8,-9999,0,1,100,-9999,-9999,500
Output will be
1,8,2,7,3,6,4,5
0,100,1

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-104/

279
Chapter 106

Set 105 (On-Campus)

Amazon Interview | Set 105 (On-Campus) - GeeksforGeeks


Written Round:
20Q questions on C, data structures , some aptitude questions and other related concepts.
2 coding questions :

1. Merge overlapping intervals. This question has come many times so I am not repeating
it.
2. Given a singly linked list you have to subtract the value of first node from the last
node and so on until you reach the middle node.

Eg 5 -> 4->3->2 ->1


Output : 4->2->3->2->1.
First PI:
1. A brief discussion on my projects that I have done .
2. One thing that I am most proud of , a discussion on this .
3. Given an array you have to write two functions:
a.) getMinimum();
b.) upate(index, value);
A detailed description on my approach , I gave him 2-3 approaches which were not satisfac-
tory , He told me to give it a fresh thought , then I have him a solution . He was satisfied
and then he asked me to code it.
4. Some basic questions on operating system concepts like CPU scheduling, why CPU
scheduling , advantages , types. Questions on deadlock.
Second PI :

280
Chapter 106. Set 105 (On-Campus)

1. Tell me about yourself.


2. Discussion on graph data structure , then asked me to find number of three node cycles
in a graph .Write code.
3. Given a string , find minimum distance between two given characters of the string,
write code.

A detailed discussion on its complexity and the code I wrote.


Third Round :

1. A detailed discussion on my projects.


2. What happens when you type in a url .
3. Suppose that a user reports that your website is taking a long time to load , suggest
possible remedies .
4. Difference between TCP and UDP.
5. Implement LRU cache. Code required.
6. A simple question on doubly linked list . Code Required .

Fourth Round( Bar Raiser /BR Round):


It was a telephonic round . I was given a design problem . We have a customer using
amazon Kindle , suppose he wants to borrow a book for some days , lets say x and wants to
finish reading the book within the days limit. The book contains ,lets say y chapters ,once
he starts reading a chapter he has to finish that on the same day . He can read the book
only in a sequential manner , you have to tell how many chapters should he read on each
day so that he can finish reading the book .
A discussion on my approach and
Then he asked me to write a code for it.
Then he asked me some HR related questions .

1. Quote some example when you have motivated your team .


2. Quote some example when you have led down your team .
3. What projects and subjects are you interested into.

And some others, I don’t remember.


It was an amazing experience, I learned a lot from it. Thanx a lot to GeeksForGeeks, you
have helped me a lot.
Suggestions / Tips :
They need a code for whatever algorithm you are telling them, so be specific, take your time
to jump to a conclusion .Discuss whatever you have in your mind , everything you discuss
matters and creates an impact , they will also guide you at times, and stay cool and relaxed,
clear any doubts you have. And an important thing is to try to justify each and every thing
you say, that matters a lot.
All Practice Problems for Amazon !

281
Chapter 106. Set 105 (On-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-set-105-campus/

282
Chapter 107

Set 106 (On Campus for


Internship)

Amazon Interview | Set 106 (On Campus for Internship) - GeeksforGeeks


Amazon came to our campus recently for placements and internships. I attended for intern-
ship and i am sharing my experience here.
First Round: Online:
20 MCQs based on basic aptitude,OS,C programming and data structures.
2 coding questions:
1st: Consider a coordinate system consisting of n coordinates from (x1,y1)…..(xn,yn)
Also there are two values ymin and ymax given to you. You have to return min(D) where
D is x^2 + y^2 for all y lying between ymin and ymax inclusive. If there is no such y then
return -1.
2nd: Given a number n and a number k. You have to find the next bigger number from n
which is obtained after exaclty k swaps.
Eg: Take n=43592169 and k=5
1st swap: 43952169
2nd swap: 49352169
3rd swap: 94352169
4th swap: 94532169
5th swap: 95432169 :- final number.
First Interview:
1. Check if a linked list is palindrome or not.
2. Given an array of n integers(positive or negative). Find the maximum sum of subsequence
of the array and also total number such arrays possible having the maximum sum.
Second Interview(Final):
1. A linked list consists of two pointers: a next pointer and a child pointer. We have to
make the linked list linear i.e. making all the child pointers NULL.

eg: 1->2->3->4

283
Chapter 107. Set 106 (On Campus for Internship)

| |
5->6 8
|
7
answer would be:
1->2->3->4->5->6->8->7.

2. Given a distance n. A person standing at position 0 has to reach n. He can either take 1
step or 2 steps at a time. In how many ways he can reach there.
Finally some definitions from OOPS, OS and basic data structures.
I was finally hired for the Internship at Amazon. I would like to thanks Geeks for Geeks
which helped me a lot in my preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-106-campus-internship/

284
Chapter 108

Set 107 (For SDE-1)

Amazon Interview | Set 107 (For SDE-1) - GeeksforGeeks


I finished interviews at Amazon few days back. Here is my interview experience:
Telephonic round (Screening):
1) Discussion around work in current company. Why Amazon?
2) You are given an infinite sorted array containing only numbers 0 and 1. Find the transition
point efficiently.
3) He gave me some function and asked me to arrive at the complexity of it.
F2F-I:
1) Brief discussion on work in current company
2) Flatten linked list – https://www.geeksforgeeks.org/flatten-a-linked-list-with-next-and-
child-pointers/
3) Design a data structure which holds number 1 to n such that insert, remove(this
operation will take in a number between 1 to n as argument and remove that number from
data structure if it exists) and get valid element in the data structure operations are done
with O(1) complexity

F2F-2:
1) Brief discussion of work in current company
2) Find and print longest consecutive number sequence in a given sequence

Ex: Input: 1 2 5 3 6 8 7
Output: 5 6 7 8

3) A fair die is thrown k times. What is the probability of sum of k throws to be equal to
a number n?
F2F-3:
1) Brief discussion of work in current company. Why Amazon?
2) Why do you want to leave current company? What do you like most and dislike most

285
Chapter 108. Set 107 (For SDE-1)

about your current company?


3) Sum two numbers represented by linked list iteratively and recursively.
4) You are given an infinite sorted array containing only numbers 0 and 1. Find the transition
point efficiently.
F2F-4:
1) Lots of HR, behavioral and team fit questions
2) User statistics are logged in the following format –

user_id|page|time at which page was accessed


We need to identify most followed 3 page sequence by users.
Example:
Input: U1|Page1|05/08/2014 10:00
U1|Page2|05/08/2014 10:01
U1|Page3|05/08/2014 10:02
U1|Page4|05/08/2014 10:03
U2|Page2|05/08/2014 10:02
U2|Page3|05/08/2014 10:04
U2|Page4|05/08/2014 10:05
U3|Page3|05/08/2014 10:04
U3|Page4|05/08/2014 10:05
U3|Page5|05/08/2014 10:06
Output: Most followed 3 page sequence for the input is
Page2 -> Page3 -> Page4.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-107/

286
Chapter 109

Set 108 (On-Campus)

Amazon Interview | Set 108 (On-Campus) - GeeksforGeeks


Dear, I just got hired by Amazon in my campus placement drive. Below are the details of
my selection process with amazon.
Fist Round(Online):
20 MCQ questions and 2 Coding Questions .
Coding Questions :
1. Merge overlapping intervals(Very well known repeating problem).
2. Given a singly linked list you have to subtract the value of first node from the last node
and so on until you reach the middle node.
Eg: Input: 5 -> 4 -> 3 -> 2 -> 1
Output: 4 -> 2 -> 3 -> 2 -> 1
F2F-1:
1) Given a sorted circular link list and a pointer to random node, now insert a new node.
I did it , but i used if and else for some special cases in my code so he asked me to do it
without if else for special cases (generic & simple code ).
2) Given a pointer to node in tree and a root pointer. Print all the nodes which are at a
distance k from the given node.
F2F-2:
1) He gave me task scheduling problem:
Given a set of modules, some modules depend on previous modules and can only be executed,
if the requirements of that module is complete.

Eg: module A depends on module B,C


module B depends on module C and D
module C depends on E
module E depends on D
module D doesn't depend on any other module

287
Chapter 109. Set 108 (On-Campus)

so he asked me to give a schedule for above modules such that when a module is executed
then all requirements of that module are complete.
so answer would be D E C B A
2) Given a string of letters from alphabet. Remove all pairs(2 consecutive same character)
of characters which occur consecutively.And do it recursively on remaining string.

Eg given string abcdaadhhhhhzppzl


then output string should be : abchl

Hint: He asked me to use some data structure for it .


3) Given a binary tree set the sibling pointers . I told him that i already know the question
so he said code it .
4) He asked me about hashing .
4.1 He asked me about complexity . I told him about O(logn) and O(1) .
4.2 Then he asked me about how do you get O(1). I told him my approach . He said how
will you rehash it when required . I told him that i will use extra memory and copy the
hash map . Then i Optimized and did it in-place using a Boolean field.
4.3 Then he took this question to OS and asked me to do it using threads .
4.4 Asked me what all problems you will need to take care about this problem while using
threads and give solution to it.
5) Discussion on my projects
F2F-3:
He gave me 3 coding questions :
1) Given a number n find the number of valid permutations of a string formed using char-
acters ‘(‘ and ‘)’ . A string is valid if it has matching opening and closing parenthesis .
Eg: given n=2 so you can have 2 possible permutations which are valid (()) and ()() .
2) Given a singly link list reverse every 3 nodes and if nodes are less than 3 then reverse
them also.

Eg: Input: 1->2->3->4->5->6->7->8


Output: 3->2->1->6->5->4->8->7

3) Given a string of letters from alphabet insert frequency of each character in the string.

Eg: Input: aaabbbccdefgggaaa


Output: a3b3c2d1e1f1g3a3

Time Complexity Required O(n) Space Complexity Required O(1)


Fourth Round (Bar Raiser):
It was a telephonic round with a collabedit screen shared on our laptops.

288
Chapter 109. Set 108 (On-Campus)

1) Tell me something about yourself .


2) He saw that i had given a seminar on cloud computing and sky computing so he started
with cloud computing .Then he asked me why didn’t cloud computing exist 15 years ago .
3) What do you understand by 32 bit and 64 bit OS ? . He asked for explanations in terms
of hardware and software . Then he asked me that will a 16 bit program run on 64 bit OS
without any problem . He asked me what can be the reason for problem faced .
4) What happens when you type www.amazon.in in your browser ? . He asked me for the
set of activities that take place during this time . Then he went into asking how do you get
to know the IP address of your ISP . Then after a lot of discussion he was satisfied .
5) Some questions about Complexity of a algorithm . Asked me to prove complexity of few
sample codes .
6) Some questions about storage space of a variable( data segment , stack , heap , BSS ).
Some questions about Macro preprocessors and there problems & solutions .
7) Some questions about error in sample code given (like returning non compatible pointer
type or returning address of a local variable etc )
8) In DOS and Linux shell when we press the up arrow we get the recently used commands
. He asked me to implement this facility. Then he asked me to do it if memory bound was
very tight .
9) This was a question to check my analytic skills . We have customers using www.amazon.in
for buying phones. Let say we have a user who visits www.amazon.in for buying mobile
phone . He selects a mobile then fills his address details and then when he finally goes for
payment then he gets to know that this phone is not available . So how can you improve
the over all user experience . Then he asked me that will you suggest redirecting the user
to some other site if the product is out of stock .
10) Some HR Questions like What are your areas of your Weaknesses ? What are you doing
to improve on them ?
It was an amazing experience. Thanks a lot to GeeksforGeeks for helping me get my dream
job �
Suggestions/Tips :
1) Discuss your approach as many times as possible.
2) Don’t start Coding the problem until the interviewer asks you to do it.
3) Tell everything that you are thinking about the problem. They are more interested in
knowing how you are approaching the problem.
4) Asks for hints if you are stuck up. They will help you.
5) If you don’t know answer to a question then please say it directly. It will save time for
other questions.
6) First be confident about your approach then only code it.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-108-campus/

289
Chapter 110

Set 109 (On-Campus)

Amazon Interview | Set 109 (On-Campus) - GeeksforGeeks


Amazon visited my Campus a few days back. I did not clear the final round of Amazon but
I got selected in D.E. Shaw the very next day after rejection from Amazon �
Here is my interview experience of Amazon.
Online Round (conducted on HackerRank):
20 MCQ questions and 2 Coding Questions (no C++ questions, C input-output ques-
tions(very hard) and aptitude questions).
Coding Questions :
1. Merge overlapping intervals(Very well known repeating problem).
2. Given a singly linked list you have to subtract the value of first node from the last node
and so on until you reach the middle node.
Eg: Input: 5 -> 4 -> 3 -> 2 -> 1
Output: 4 -> 2 -> 3 -> 2 -> 1
Advice: Many people say that making 1 code is enough to clear the 1st round while this
is not true, I made both the codes and many of my friends who made only one code were
rejected. Everyone who made both the codes were selected. There were some students who
cleared this round by making only one code but don’t try your luck here by making only
one code is my suggestion.
Round 1(Bar Raiser):
Complete discussion on my project.
Suppose you have a file with billion entries and you have to sort the data of a file according
to a column and can put only that column in memory and after putting that your memory
gets full.
e.g. your file contains
name age address pincode sex
….. …. … … …
And you can have to sort the file according to pincode then you can only put pincode in the
memory.
I approached it firstly by using merge sort but this requires the entire file to be put into
memory. Then, I suggested using min heap but he said that heapify process of billion

290
Chapter 110. Set 109 (On-Campus)

numbers will take a lot of time. He said you are getting close, then I suggested that we can
use a balanced binary search tree to store the pincodes along with indexes and then traverse
the bst in inorder fashion and swap the indices of the first pincode of file with the index of
inorder element. He was happy after hearing this and asked me to write the code and to be
careful with edge cases.
I did it.
Round 2 (CS Fundamentals)
He wanted to check my knowledge of DBMS, OS, and Computer Networks. Asked everything
related to these subject including all the layers of networks and from process-threads to
deadlocks to memory management in OS. Asked a SQL query to find 3rd maximum marks
of student from a database. I gave him 2 solutions � .
Asked me my favorite sorting algorithm. My favorite is insertion sort but I told him merge
sort because I knew a lot about merge sort so I wanted to drive the interview towards merge
sort and as expected he asked many questions on merge sort and I gave him all the answers.
He asked me to build a tree from given preorder and postorder traversal of tree, I said it
is impossible to build from only these 2 traversals , you have to give me inorder to build a
unique tree.
Round 3 (CS Fundamentals + Coding)
Deep discussion about project.
Asked me to choose my favorite subject other than any related to coding or algorithms. I
said Computer Networks. He asked why it is your favorite ? Why not OS or DBMS?
He asked me What happens when you type www.amazon.in in your browser. I was
expecting this question � . I knew this, told him everything.
See the links below for solution
http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/
http://superuser.com/questions/31468/what-exactly-happens-when-you-browse-a-website-in-your-browser
http://edusagar.com/articles/view/70/What-happens-when-you-type-a-URL-in-browser
He asked me to solve a coding problem now.
Suppose I am given a sorted array of unknown size, then how will I search an element in
this array efficiently.
I said I can increase int i by the power of 2 and check whether the given arr[i] > element
to search whenever I find such element then I can apply binary search between i/2 and i.
He said this approach will work but what happens if while increasing i , you cross the array
length. Suppose an array is of size 6 , then your i will become 8 and arr[8] will give garbage
value so your program may go in an infinite loop. I said I can increase i in try block and
whenever this case occur then I can catch the exception in catch block where I will decrease
i by 1.
He smiled and asked me to write the code by taking care of edge cases.
Round 4 (Coding)
Deep discussion about the project which was on security. The interviewer asked me to
design the database of a chat application similar to whatsapp. I did it and said what
if some intruder access the database, then I said I will apply md5 encryption on phone
numbers, then he asked me how md5 works. Why only md5? He asked me what are Man
in the middle attacks and asked me to remove man in middle attacks from the message
transfers. He was impressed. �
He then asked me what is cache, why are cache fast and how it differs from RAM and hard
disk architecturally. This one was a bouncer, I hated computer architecture, admitted I am

291
Chapter 110. Set 109 (On-Campus)

a beginner in computer architecture. He laughed and said thank god, there is one thing in
which you are a beginner. I laughed too �
He moved further towards coding.
1. Suppose the structure of a binary tree is

struct node { int val;


struct node *left,*right,*random;
}node;

Where random pointer points to any random node of the binary tree and can even point to
NULL, then how will you clone this tree.
This was the culprit question who led to my rejection.
I gave a lot of thought to it, but wasn’t able to solve it directly. I said we can use hash,
then he said what if there are duplicates in the tree then your hash will fail, then I said we
can convert the binary tree to doubly link list in place then clone the doubly link list, he
said ok but how will you generate the original tree from doubly link list, I never said it was
balanced. I gave a lot of thought here, nut yeah couldn’t solve it.
I got the solution by trying it after the interview, you can clone the left and right pointers
easily by traversing the tree and to clone the random pointers, you can apply this : newroot-
>random=oldroot->random; oldroot->random=newroot;
Then traverse new tree again and put newroot->random=newroot->random->random.
2. https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
I solved it efficiently.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-109-campus/

292
Chapter 111

Set 110 (On-Campus)

Amazon Interview | Set 110 (On-Campus) - GeeksforGeeks


Hi, Amazon visited our campus few days back. Before I start off with my experience, here
are few suggestions.
1. Don’t just go through the codes. First try it on your own, that’s very important. Once
u have cracked a problem, write it in a paper and check for the corner cases.
2. For the online round. GeeksQuiz is enough to get you through the MCQs. For the coding
part, once u have cracked a problem, always try to run the program at one go.
3. OS, DBMS and Networking. If you get a good hold on these subjects, it will make you
stand apart from other candidates.
First day:
20 MCQs(Data structure, C, C++, OS, Probability ).
2 programs :
1. Given an array of integers. Segregate all the non-zero numbers at the beginning. Print
the number of non-zero integers and the minimum number of swaps required for these
operations.

Eg. : I/p : 1, 0, 0, -6, 2, 0


o/p : Number of non-zero integers : 3
Minimum number of swaps : 2

2. Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char
txt[]) that prints all occurrences of pat[] and its permutations (or anagrams) in txt[]. You
may assume that n > m.

E.g. : I/p : txt[] = “BACDGABCDA” pat[] = “ABCD”


o/p : Found at index 0
Found at index 5
Found at index 6

293
Chapter 111. Set 110 (On-Campus)

Second day:
Suggestion: Always think loud when you are coding
Round 1 : PI 45 min
1. Discussion on Project.
2. Code : LCA of a BST.(check for all corner cases)
3. Code : LCA of a Binary Tree(check for corner cases)
4. Code : Maximum sum subarry along with its starting and ending index.
5. Code : Heap operations
Round 2 : PI (With Manager) 1 hr 15 min
1. Discussion on project.
2. Code : Given an array : A1[] = 2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8
A2[] = 2, 1, 8, 3
Sort A1 in such a way that the relative order among the elements will be same as those are
in A2. If the element is not present in A2, append them at last in sorted order.
o/p : 2, 2, 1, 1, 8, 8, 3, 5, 6, 7, 9
As I carried on telling him the approach, he went on modifying the question ( what if A2 is
much larger than A1 ?, what if they are of the same size ?)
A lot of discussion on complexities for all modifiactions. He was quite happy with my
answers.
Finally he asked me to code the O(nlogn) approach.
Round 3 (Subject Round) 1 hr
1. OS : Virtual Memeory (lot of discussion of its advantages, thrashing , etc)
Then he asked me design a LRU replacement policy(approach) which i did. Then he asked
to implement FIFO replacement policy with stacks. I did it using two stacks.
2. Neworking : He started with Transport Layer( discussion on ports. How data from
applications are changed into packets ?, etc).
Then he went to Network Layer (A lot of discussion on subnet masking and how it is used by
routers to map the IP address of incoming packet, how a Subnet is different from Internet).
Next we moved to Data Link Layer( Discussion MAC addresses, sliding window protocols,
etc).
3. DBMS: What is indexing?, Why indexing ?, How to implement indexing ?, What are the
different types of Index? .
Differences among Inner Join, Left Outer Join and Right Outer Join. He followed it up with
a SQL query on Outer Join.
As my first three rounds went very well, fourth round was of 15 minutes only.
Round 4 (Bar Raiser) 15 min.
1. Logical question. Given a prime number ‘p’. Prove that p^2-1 is always divisible by 24.
2. Find 2nd maximum element in a given array in one iteration.
All the best !
GeeksforGeeks has helped me throughout my preparation. This is the best site for clearing
your concepts on Data Structures and Algorithms. GeeksQuiz has helped me to get through
the MCQs in the online round. Thanks again !

294
Chapter 111. Set 110 (On-Campus)

Keep Smiling !
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-110-campus/

295
Chapter 112

Set 111 (On-Campus)

Amazon Interview | Set 111 (On-Campus) - GeeksforGeeks


Amazon visited our campus, these are the questions that I faced.
Online Round (90 minutes)
20 MCQs(Data structure, C, C++, OS, Probability ).
2 programs :
1. Given an array of integers. Segregate all the non-zero numbers at the beginning. Print
the number of non-zero integers and the minimum number of swaps required for these
operations.
Eg. : I/p : 1, 0, 0, -6, 2, 0
o/p : Number of non-zero integers : 3
Minimum number of swaps : 2
2. Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char
txt[]) that prints all occurrences of pat[] and its permutations (or anagrams) in txt[]. You
may assume that n > m.
E.g. : I/p : txt[] = “BACDGABCDA” pat[] = “ABCD”
o/p :0,5,6
1st PI

1. About 10 minute discussion on my project on Cloud Platforms and Big Data Analysis
in Yahoo SDC. I asked him some doubts and he answered them clearly.
2. Given a string of digits, output all the dictionary words they can represent. (Basically
smart dial algorithm of an android phone). Each digit represents the corresponding
characters on a cellphone as follows.

296
Chapter 112. Set 111 (On-Campus)

e.g. : I/p : 3323 O/p : DEAD , DEAFFirst, he asked me how I would store the
dictionary. When he was satisfied by my approach, he asked me to write a recursive
function that would do the job if a dictionary is given as an input.
3. Then he gave me a class design. He went on changing his requirements and I was asked
to add support for them in my implementation. At first, his requirement was to draw a
rectangle and a circle. Then he went on adding requirements and finally it was to draw
different specializations (like curved-edges, skewed-edges, dashed-lines) of rectangles,
triangles and circle. He gave a constraint that support for a new specialization can be
added easily in my design.

2nd PI

1. Given, the starting and ending time of different meetings, what is the minimum number
of conference rooms that will be enough to accommodate all of them.He asked me to
code it.E.g, :
I/p : Meeting I – 8:30 – 12:50
Meeting II – 10:15 – 11:30
Meeting III – 11:45 – 1:30
O/p : 2
2. Implementation of a doubly-linked list using a single pointer. I didn’t know the answer
at that time. He gave me a few hints and I was able to solve it. Then he asked me to
code it.

3rd PI

1. Given an array of integers. This array denotes ‘our’ own ascending order of the
elements. So if the array is {2,3,1,4}, by mathematics we can say that 2<3<1<4.

297
Chapter 112. Set 111 (On-Campus)

Given another array, sort this new array in ‘our’ ascending order.
Let’s say the new array is {1,2,4,3,5,4,9,2}, output will be {2,2,3,1,4,4,5,9}. Note that
since 5 and 9 do not occur, they are sorted by actual ascending order at the end.
2. Return the left-view and right-view of an n-ary tree in a single traversal.

4th PI

1. 10 minute discussion about my internship in Cloud Platforms team in Yahoo SDC.


He asked me a few HR questions like what do you think was your biggest screw-up in
college life, etc.
2. Find power(a, n) iteratively without extra space in O(log n) time. He gave me a lot
of hints. But unfortunately I couldn’t solve it.
3. Pre-order traversal of a binary tree without using recursion.

Fortunately, I was selected as an FTE in Amazon.


Suggestions
I would like to give a few suggestions to all the upcoming candidates :-

1. Firstly, mugging up of codes will never take you far. If you find a problem that is
solved in geeksforgeeks, rather than blindly mugging up the code, read the description
properly. Try to understand what is being done and why is it being done. Try
to understand each and every line of code. It is naïve to expect common known
questions in interviews. But, if you can understand the approach of the codes solved
in geeksforgeeks, you can use it to solve a plethora of problems.
2. In an interview, always think out loud. Explain what you are doing and why you are
doing it. If you solve a problem within a few minutes without explaining your steps,
the interviewer will assume (perhaps not incorrectly), that you have mugged up the
code. This creates a very bad impression.
3. Follow proper etiquettes. Shake the interviewer’s hands while entering and while
leaving the room. Also, try to ask proper questions to the interviewer when he gives
you the chance to do so. These are the small things that set you apart from the other
interviewees.
4. Lastly, never be too tensed. Always remember, rejection is a part of life. Luck matters
a lot in job interviews. So don’t be disheartened if you are rejected. You can always
apply later.

A very best of luck to all of you for your upcoming interviews.


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-111-campus/

298
Chapter 113

Set 112 (On-Campus)

Amazon Interview | Set 112 (On-Campus) - GeeksforGeeks


Amazon visited our campus and was hired as intern. These are the questions that I faced.
Online Round (90 minutes)
20 Basic MCQs (Data structure, C, C++, OS, Aptitude, Networks).
2 programs :
1. Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char
txt[]) that prints all occurrences of pat[] and its permutations (or anagrams) in txt[]

E.g. : I/p : txt[] = “BACDGABCDA” pat[] = “ABCD”


o/p :0,5,6

2. There is a matrix mat[m][n] with entries as 0 or 1 When you are at 1 you can move in
all the eight directions and when at 0, you have to return back. Find the number of cluster
of 1’s

e.g. input { {1,1,0,0,0},


{1,0,0,1,0},
{0,0,0,1,1},
{1,0,1,0,0} }
output 3

clusters ((0,0),(0,1),(1,0))
(1,2),(2,2),(2,3),(3,2)
(3,0)

Round 1:
1) Introduce yourself.

299
Chapter 113. Set 112 (On-Campus)

2) Any moment when you worked really really hard to solve a problem.
3) Find the best fit for a packet to be fitted in a rack rack sizes are given in increasing order
in other words find the ceil value of a key in sorted array.
4) Check given binary tree is BST or not
5) Find the lowest common ancestor in binary tree
6) If I have any question to ask him
Round 2:
1) Find largest sum contiguous subarray in goven array
2) If I had any question to ask him
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-112-campus/

300
Chapter 114

Set 113 (On-Campus for


Internship)

Amazon Interview | Set 113 (On-Campus for Internship) - GeeksforGeeks


Amazon visited our campus to offer internship for 6 months. There were 3 rounds – an
online coding round and 2 face to face interviews.
Online coding Round(Duration:1 hr 30 mins)
This round was conducted on hackerrank.com. There were 20 mcq’s related to computer
science and aptitude.Many of these questions are there in the MCQ section of GeeksForGeeks.
And there were 2 coding questions:
1. Given a txt[0..n-1] and pat[0..m-1], write a function search(char txt[],char pat[]) that
prints all occurences of pat[] and its anagrams in txt[].

Assume that n>m.


Example: txt[] = “BACDGABCDA” pat[] = “ABCD”
Ouput: 0 5 6

2. (Cluster Program) You are given a 2d matrix containing 0s and 1s. From a given position
in matrix, you can move in all the 8 directions i.e. (i+-1,j),(i,j+-1),(i+-1,j+-1). You have
to print the number of clusters of 1’s in the matrix. Two 1’s lie in a cluster if and only if
we can move directly from one 1 to another.

Input : m=5,n=5.
Mat[] = 1 1 0 0 0
0 1 0 0 1
1 0 0 1 1
0 0 0 0 0
1 0 1 0 1
Output : 5
First: (0,0),(0,1),(1,1),(2,0)

301
Chapter 114. Set 113 (On-Campus for Internship)

Second: (1,4),(2,3),(2,4)
Third: (4,0)
Fourth: (4,2)
Fifth: (4,4)

Face to Face Interview-1(Duration:1 hr)


Interviewer started asking questions straight away without any introduction. He asked me
the worst case complexities of Quick sort and Merge sort. Then asked me 2 questions related
to trees:
1. Given an array that contains post-order traversal of a binary tree. Can you construct a
single tree? I said no. Then he asked if i can make a binary search tree from the array to
which i said yes. Then after discussing the approach, he asked to write the code.
2. Then he asked me to write the code for level-order traversal of a tree. Also asked me to
calculate the complexity of the code.
Face to Face Interview-2(Duration:about 1hr 30mins)
Interviewer started with the general introduction. Then he started asking questions.
1. Given n appointments with the start time, end time and a boolean variable hasConfilct,
we have to set the boolean variable hasConflict of those appointments that conflict with the
other appointments.

Example: Appointment1: (2:00-3:00)


Appointment2: (2:30-3:30)
Appointment3: (4:00-6:00)

I have to set the the hasConflict of Appointment 1 and 2 as true.


Initially, I did it in O(n^2). But then he asked me to optimize the solution. After some
discussion, I was able to solve it in O(nlogn).
2. Given that at Amazon.in the details page of an item shows only one field that is dynam-
ically picked up from the database, we have to improve the performance according to the
line:
“80% of the users visit details page of 20% of products.”
I said we could store these 20% on the web server so that we don’t have to fetch the item
details from database everytime. He asked me where and how will i store it. I answered
Main memory and will use BST to store it. Then after a lot of discussion(about 30 mins)
on how will the get and put operations be used, he was satisfied with the solution.
3. Given a linked list placed in memory, what problems can arise if simultaneous operations
are performed on the list. From here he started asking about threads because the answer
was related to it.
4. When a single threaded application is converted to multi-threaded applications, what
kind of changes operating system has to make?
5. What steps are taken when the os shifts from one-thread execution to another?
Finally, I was hired. Thanks to GeeksForGeeks for helping me throughout my interview
preparation.
All Practice Problems for Amazon !

302
Chapter 114. Set 113 (On-Campus for Internship)

Source

https://www.geeksforgeeks.org/amazon-interview-set-113-campus-internship/

303
Chapter 115

Set 114 (On-Campus for


Internship)

Amazon Interview | Set 114 (On-Campus for Internship) - GeeksforGeeks


Recently Amazon India visited our campus for 2 months internship. There were three rounds
2 online coding questions + 20 MCQ
The MCQ questions were mainly 6-7 questions on data structures, 7-8 C language output
programs, 4-5 questions on general aptitude, Probability, Permutation and Combinations.
The two questions were:
a. Given a set of intervals, you have to group the overlapping intervals and display all the
intervals in non decreasing order.
Eg: (1,5),(8,11),(3,6),(10,20)
output: (1,6),(8,20)
Tip: Although this is a very easy question and can be found on many online portals, just
remember that the given input is in the form of a string and it needs to be parsed carefully.
For this, instead of converting the string into integers, you could use something like

while(scanf("(%d,%d),",&a,&b))
{
//store a and b as you wish to
}

b. Given a set of integers, negative as well as non negative, You need to rearrange them
such that negative and non negative integers at alternate positions.
Constraints: order of all the negative and nonnegative integers must be the same as before
if there are more negative integers, the integers in excess should occur at the end of the
array and same goes for the non negative integers in case they are more in number.

304
Chapter 115. Set 114 (On-Campus for Internship)

eg: -5,-2,5,2,4,7,1,8,0,-8
output: -5,5,-2,2,-8,4,7,1,8,0

Again, for the input, you can use the above mentioned technique.
About 20 out of 150 students were selected after this round for Personal Interviews.
Following are the interview experiences of two of us.
Person1:

ROUND 1:
1. Given a binary tree having 3 pointers, left, right and sibling out of which all the left
and the right child pointers are already filled, you need to fill the sibling pointers with the
addresses of the next node on the same level. If it is the last node of a level, fill NULL.
I first told him an approach using a level order traversal with a queue. Then he asked me to
do it without a queue using recursion. I told him the approach and when he was satisfied,
he asked me to write a code on paper with all the corner cases covered.
2. Given an array of size 2n+1 where n integers repeat two times and one integer occured
only once, Find that integer. I told him by using XOR. then he changed the question to
Given an array of size 2n+2 where n integers repeat 2 times and 2 integers come only once.
Find both of them. This can also be done using XOR. You can find the solution in the
arrays section of Geeks for Geeks
3. Given any binary tree in which all the leaves had their left and right pointers connected
in a doubly linked list from left to right instead of pointing to NULL. Also, the leftmost
leaf’s left pointer pointed to that node itself and the rightmost leaf’s right pointer pointed
to that leaf itself and if there was an internal node with no left or right child, that particular
pointer will point to that node itself.
You need to find the Inorder Traversal of the tree.
Once I told him the approach, he again asked me to write a code on paper.
4. He asked me about the data structures I knew and then started asking questions on
Graphs. How we represent them?
which is better Adjacency matrix or List?
Then he gave some situations and asked me which of the two implementations should be
used.
ROUND 2:
1. He asked me in detail about my projects for about 15 minutes.
2. Then he asked me about the subjects I had studied in 3rd and 4th semesters.
I forgot what all subjects I had studied � � �
The first subject that came out of my mouth after a lot of thinking was Unix Linux Program-
ming. Then he asked me to write all the commands I knew in 5 minutes. I listed almost 20.
He asked me the functions of a few of them and differences between some of them.
3. Finally he asked me a question on binary trees which was pretty simple.
Replace the data of every node of a Binary Search Tree with the sum of all the nodes greater

305
Chapter 115. Set 114 (On-Campus for Internship)

than it.
I gave him the approach using reverse inorder traversal. He then asked me to write a code
on paper. I had used pointers in the code. He then asked me to write a code that did not
use pointers, static variables or global variables.
I wrote that. Finally he appeared satisfied.
Person 2
ROUND 1:
1. Given a singly linked list and an integer k, I had to write code to reverse the list in pairs
of k handling all base cases as well.
eg. 1->2->3->4->5->6->7->8 k=3
o/p 3->2->1->6->5->4->8->7
She actually tried my code on a number of base cases trying to find bugs �
2. Given 2 arrays one of size n and another of size (n+k) but having k values filled, I was
asked to merge the two into the second array without using any extra space. I quickly gave
her the logic and we moved on to the next question.
3. Given a string of characters, find the index of the first repeating character in the string.
eg. abcba
o/p: 0 (as ‘a’ came initially before ‘b’ did, though both are repeated twice).
Again error free code was required.
4. She then asked me questions on the research project I was currently working on. This
went on for another 10-15 minutes.
ROUND 2:
1. This round started with questions on my research project. Then he asked me which data
structures I liked. We had a long discussion on heaps and the associated time complexities.
2. Given a binary tree, any node in the tree and an integer k, print all the nodes at a
distance k away from the given node.
Mind you, the node may be above or below. We first discussed on an approach and after
he was satisfied with my explanation, he asked for error-free code.
3. Given an integer n, how many BST’s can you make with n no of nodes?
I told him about catalan number and the direct formula – 2^n – n. But he wanted a
derivation, so I built-up a recurrence and showed him the DP to evaluate it.
4. Given n people, you are told all pairs of people who belong to the same country. You are
to tell the number of pairs of people who do not belong to the same country,
I expressed it as a graph and applied dfs to get number of connected components and size
of each. Then it was a simple formula over no of components.
After this he started discussing the life at Amazon, what the company expects from you
and what you should expect to do at the company.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-114-campus-internship/

306
Chapter 116

Set 115 (On-Campus)

Amazon Interview | Set 115 (On-Campus) - GeeksforGeeks


Hai, recently amazon visited our campus for recruitment. Here is my amazon experience.
1000 people attend round 1
Round 1: (1.30 hrs)
20 MCQ’s + 2 coding question
19 MCQ’s were from os,c++,java and single mcq from probability
Coding questions:
1. Find maximum sum in a array,such that no two elements are adjacent.
For example 3,2,7,10 should return 13, sum of 3 and 10. Handle for negative cases too.
2. Given a binary search tree,print the sum of all nodes that are in same axis (Modification
of vertical order traversal)
I attended 12 mcq’s. There was negative marking,so i attended the questions which i was
very confident and did both programs.
I was confident that i will clear the round 1.
Round 2: (Group Fly Activity) ( 1 hr)
Around 36 people were shortlisted for second round.
We were divided into many groups and each group was alloted a mentor.
Two questions were given and we have to discuss the approach with mentor and only after
getting his approval we have to code.
1. Given a monotonically increasing and then decreasing array with duplicates and a key,
return true if key exists in array.
2. Given k sorted arrays of different or equal sizes, merge them into a single sorted array.
Thanks to mentor, he was very cool and helpful, I did both the codes and handled corner
cases too.
Round 3: (30-45 min)
18 people were shortlisted for third round and i was one among them.
First the interviewer asked to tell about myself.
Then he asked why i had low cgpa when compared with my school marks.
Then came the first question

307
Chapter 116. Set 115 (On-Campus)

1) Given n ropes of different length, combine them into a single rope,such that total cost is
minimum. You can tie two ropes at a time,and cost of tying is sum of length of ropes.
First i gave a solution similar to insertion sort in a linked list,he was not satisfied, and then
I gave a min heap approach. He asked for time complexity. I got wrong,so he asked what
steps u will do and time complexity for each step. He added all the step cost and asked me
to arrive at final time complexity.
After this, I got correct.
Then he asked about 2nd code in group fly activity.I used merge sort for it and he asked
why i had used merge sort,and asked to improve the code.
Then i gave a min heap solution (:P we discussed after group round). He asked me to code
it. I was not good at heaps. I tried my best but unable to arrive at working code
So finally he asked if i had any questions for him. I asked about amazon’s environment.After
this i thanked and left.
I was sure that i will be eliminated and i was eliminated.
Only 10 people went to 4th round and 3 people were hired finally.
Here are some mistakes done by me
It was first f2f for me and i was very nervous and had butterflies in stomach, which ultimately
decreased my performance.
I was not confident about the answer i gave.
My communication skills were very poor.
So try to avoid the mistakes done by me.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-115-on-campus/

308
Chapter 117

Set 116 (On-Campus)

Amazon Interview | Set 116 (On-Campus) - GeeksforGeeks


Round 1:-
20 MCQ’s(Majority from OS and Java, C++, 1 aptitude)
2 coding questions.
1. Given an array, find the maximum sum that can be formed from the array such that no
two adjacent elements are taken into consideration..
for ex:- 1,2,3,5 should return 7.
2. Print Vertical axis sum of the given binary tree.
Round 2:-
Group Coding Round
36 people made it to the next round. 2 questions were asked
1. Given an array which initially increases and then decreases, search for an element in the
array.
2. Merge ‘k’ sorted arrays.

Round 3:-
Technical interview
18 people were selected for the next round and they asked me 2 questions
1. Given an infinitely growing sorted array which initially consists of 0’s and then 1’s upto
infinity. Find the transition point where 0 changes to 1 effectively.
2. Given a binary search tree, make 2 separate trees such that difference between the sum
of elements between them is minimum.(After some time he gave me a hint which helped me
solve the problem).
Round 4:-
Technical Interview
1. Some basic OS related questions
2. Implement a data structure which would perform insertion, deletion, search and random-
ize operation with minimum time complexity.
We discussed a lot of data structures and I settled with a data structure (Hashtable with

309
Chapter 117. Set 116 (On-Campus)

DLL). But he gave me clues and improvised my solution.


3. Implement a Queue using 2 stacks. Optimise your implementation
(They didn’t ask me to code in this round. They just checked how efficiently I approached
it )
Round 5:-
Technical interview
I think this is the bar raiser round. We are aware of the game show in which a contestant
will think of a famous personality and the host will try to find the personality within a
finite set of questions. I was asked to design a system which would implement the same.
He asked me to write a code to return the first question (like the deciding factor on which
the elements will be further partioned) so that I can find the celebritry in minimum no. of
questions.
I think they were checking your approach, ideas and patience in this round. Whatever
solution I gave he never seemed to be satisfied. Be confident in your approach and don’t
ever give up.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-116-on-campus/

310
Chapter 118

Set 117 (On-Campus for


Internship)

Amazon Interview | Set 117 (On-Campus for Internship) - GeeksforGeeks


Recently Amazon India visited our campus for 2 months internship. There were four rounds.
2 online coding questions + 20 MCQ :
MCQs had 15 questions(not exactly) on OS (to my surprise) , one aptitude(probability) and
rest on c/c++
2nd Round ( Group Interview / Written round) :
21 were selected for the second round. We had 2 questions.
1. Given two strings, find whether they are anagrams of each other. (too easy).
Its here.. https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/
2. Given a n-ary tree, Convert it into an array and return it. Construct the same n-ary tree
from that array again. (DFS is better here as reconstruction is necessary) –
Push the root to a stack. “pop the stack.store the value of the root node and the number
of children it has in the array.push all the children to a stack from right to left”.. do this
until the stack becomes empty.. the array will have dfs along with the number of children
of each node.
For reconstruction,pass “i” by reference( i is for iterating through the array) take the value
at index 0 .. make it has root. increment i. for all the children of the root, recursively call
the same function. return root. (I hope this works :P)
3rd round (Face to Face):
Only 5 were selected.I was asked only one question and i didnt do well. Find the square
root of a number. i answered that this can be done using Babylonian method. (https:
//www.geeksforgeeks.org/square-root-of-a-perfect-square/) or binary search method.. He
asked me to implement Binary Search method. I did a mistake. then he asked me to correct
it.. i corrected it. I wasn’t able to impress him much.
Remember the floating point arithmetic limitations.. this is where i failed.

311
Chapter 118. Set 117 (On-Campus for Internship)

4th round (Face to Face):


I was called for 4th round. ( Only i had 4th round because of my bad performance in the
3rd round). The interviewer asked a lot of questions. They were easy
1.Given an array of 0s and 1s sorted. Find the first occurrence of 1 ( Binary Search)
2.Given an infinite array of 0s and 1s.(sorted) .Find the first occurence of 1(similar to this..
https://www.geeksforgeeks.org/find-the-point-where-a-function-becomes-negative/ )
3. Given a matrix sorted in ascending order both row and column wise. Search an ele-
ment( https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/
). This is O(n+m). He asked me a better solution.. I tried and he helped me a lot..Though
i wasn’t able to deliver.
4. Given a tree, print the max sum path from root to leaf .. (https://www.geeksforgeeks.
org/find-the-maximum-sum-path-in-a-binary-tree/)
5.Given a tree,print spirally the column order of a tree.

ex : 1
/ \
2 3
/ \ / \
4 5 6 7
o/p : 4 2 6 5 1 3 7

6. Implement a stack using array. Implement two stacks using an array. Implement 3 stacks.
7. You are given an array . You have to create a stack when the user wants to do so
and delete a stack when the user says.You wont be given the number of stacks that will be
created.
I thank geeksforgeeks for providing an excellent platform to learn new things. Check the
interview corner for other company interviews.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-117-campus-internship/

312
Chapter 119

Set 118 (On-Campus for


Internship)

Amazon Interview | Set 118 (On-Campus for Internship) - GeeksforGeeks


The selection procedure consisted of an online round followed by two Personal Interviews.
Online Round:
The first round had 20 MCQs and two coding questions. The MCQs were based on the
concepts from OS, DSA, compilers, architecture etc.
The coding questions were:
1. Given an array of positive and negative numbers, arrange them in an alternate fashion
such that every positive number is followed by negative and vice-versa maintaining the order
of appearance.
2. Given a n x m matrix, print the elements diagonal wise from top to bottom.
First round of PI :
1. Given a number n find the number of balanced parentheses expressions of that length.
Input: 2
Output: 1 which is (),
Input: 4
Output: 2 which are (()) and ()().
I gave a complex solution involving segment tree in which he pointed out the mistakes and
then asked to write a code to check if a given expression is balanced or not.
2. Tell something about LRU. What DS will you use for it? Write pseudo code for it.
(Hint : Quite simple..Use doubly LL)
Second round of PI:

313
Chapter 119. Set 118 (On-Campus for Internship)

The interviewer introduced himself first and then asked me about myself.
We had a discussion on my projects.
1. Given two binary trees, write pseudo code to determine if one is a subtree of the other.
I answered it and then he modified the question to check if the other tree elements are the
subset of the elements of the first tree. (Hint: Inorder traversal)
2. Given a sorted circular linked list which is rotated at some point, write pseudo code to
insert a new node. Ex: 8 1 2 5 7 and insert 6.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-118-campus-internship/

314
Chapter 120

Set 119 (On-Campus for


Internship)

Amazon Interview | Set 119 (On-Campus for Internship) - GeeksforGeeks


The selection procedure consisted of an online round followed by two Personal Interviews.
Online Round:
The first round had 20 mcq consisting of 3-4 questions from aptitude, 2 questions from os
and rest were from Basic C and Data Structure. There were 2 coding questions as well.
Question 1: You are given a phone keypad like following diagram, where each character
corresponds to a digit mentioned in the same box.

You are given n strings and you have to find their decimal representation. You have to print

315
Chapter 120. Set 119 (On-Campus for Internship)

the string and corresponding decimal representation in descending order.


Like if you are given “amazon” then its corresponding decimal notation will be 262966.
If more than one strings have same decimal notation then you have to print them in the
order in which input is given.
(Given that given string consists of lower case alphabets only.)

Test Case 1:
5
Amazon
Microsoft
Facebook
Aa
Bb

Output:
642767638 microsoft
32232665 facebook
262966 amazon
22 aa
22 bb

Question 2: Given a string. Print all Possible permutations of different lengths in sorted
order.

Input: abc
Output:
A
Ab
Ac
Abc
b
Bc
c

Candidate who could solve at least one question out of 2 coding questions was selected for
personal Interviews.
Round 2(P.I. 1) :-
Firstly interviewer had a deep discussion of my project. He also asked me to write code for
one of my mini project (Backtracking).
Then he asked two back to back coding questions –
1. You are given a bst. You have to print the kth smallest element.
(https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/).
2. You are given two sorted arrays and you have to print the median obtained after merging
them in log(n) time complexity.
(https://www.geeksforgeeks.org/median-of-two-sorted-arrays/)
Then he asked the language in which I am comfortable for coding. I said C . Then he asked

316
Chapter 120. Set 119 (On-Campus for Internship)

me to allocate the dynamic memory of 2-d array in C( I used malloc function for this). Then
he asked me the difference b/w malloc and new (c++) function.
Round 2 (P.I. 2):-
Firstly he asked me to tell about my academic background. Then he directly put a coding
question in front of me.
1. You are given a binary tree and two nodes. You have to print the horizontal distance
between them.
Let us say :
Given nodes are B and C : Answer would be 2.
Given nodes are A and E : Answer would be 0.
Given nodes are D and G : Answer would be 4.
We had an long discussion of 45 mins (approx.) on this problem.
One of my friend was asked the following questions:
2. Given a linked list. You have to determine whether or not it is a palindrome in order
O(n) time without using auxiliary space.
3. You are given an array of integers . You have to find the maximum sum sequence.(It
needs not be contiguous).
After all these rounds I and my friend both were selected � :). A total of 16 candidates were
selected.
I really thank to GEEKSFORGEEKS for all the support and help in my preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-119-campus-internship/

317
Chapter 121

Set 120 (On-Campus for


Internship)

Amazon Interview | Set 120 (On-Campus for Internship) - GeeksforGeeks


Recently Amazon visited our college and details are as follows.
Online Round:
There were two questions.
1. N strings are given.Convert all string to corresponding decimal value typed in an Al-
phanumeric Keypad (e.g. “bdg” -> 234). Then print all strings in decreasing order of their
decimal value. If they have same decimal value then print lexicographically smaller first.
Input:

5
Amazon
sun
run

Output:
262966 amazon
786 run
786 sun

2. Write a code to print all possible combinations(order matters) of characters of string in


lexicographical order.
Input: “ABC”
Output: A, AB, ABC, AC, ACB, B, BA, BAC, BC, BCA, C, CA, CAB, CB, CBA
Interview:
Round 1: 45 minutes
This started with a brief discussion on project. She quickly moved on to Coding questions.
She made me write an error free code for “Count all pairs which sum to k in a BST”. Also

318
Chapter 121. Set 120 (On-Campus for Internship)

she added that duplicates may be present but on left side only.
First she discussed for approach and then constrained the space complexity to be O(1). She
checked the code rigorously.
Then there were 3-4 coding questions. She just discussed approach.
-Update all nodes in a bst to be sum of all elements greater than or equal to it.
– Stock problem/ Given an array ‘arr’ find maximum difference between two elements
(max(arr[i]-arr[j]) where i>=j).
-Then there was this awesome question… Given a perfect binary tree.
print nodes in a specific manner. e.g-

15
/ \
13 14
/ \ / \
9 10 11 12
/ \ / \ / \ / \
1 2 3 4 5 6 7 8
print - 1 8 2 7 3 6 4 5 9 12 10 11 13 14 15

I told her approaches having some space complexity. Again she restricted space complexity,
and I got an efficient solution by recognizing some pattern � .
Round 2: 25 minutes
There were just two questions.
1- Given a string having no spaces, and a dictionary.Problem was to find if that string can
be splitted in multiple strings such that all the splitted
strings are in dictionary. I was provided a function search(string str) which will tell if a
particular string str is in the dictionary or not.
I quickly gave a recursive approach.
2- The second question was well known vertical order traversal of a binary tree. She just
discussed how to implement various approaches in C++.
Then there was discussion on types of projects assigned to Interns and blah blah.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-120-campus-internship/

319
Chapter 122

Set 121 (On-Campus for SDE-1)

Amazon Interview | Set 121 (On-Campus for SDE-1) - GeeksforGeeks


5-quant, 15 technical, (no verbal reasoning and English).
1) Given 2 binary trees check if it is symmetric (structure only not data).
2) Remove duplicates in a string in O(n) time (order of input must be preserved)
Round-1
1. Heaps-insertion.
2. Advantages of heaps over arrays.
3. Find 2nd min element from given array
4. Given an array and a sum s find all pairs of numbers which whoose sum=s
(assume array is already sorted)space complexity-O(1),time complexity-O(n)
Round-2
1. Given a tree construct a mirror tree and return root of mirror tree.
2. Level order traversal of a tree.
3. Given a stack output a sorted stack.(hint use recursion).
Round-3
1. Given a tree populate the sibiling of the tree node with the next node in same level.space
complexity-O(1).
2. What happens when you type amazon.com in browser.
Round-4
1. Linked list problem https://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-li
2. A simple problem in linked list.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-121-campus-sde-1/

320
Chapter 123

Set 122 (On-Campus for


Internship)

Amazon Interview | Set 122 (On-Campus for Internship) - GeeksforGeeks


My interview comprised of 3 rounds. 1 Online and 2 face to face rounds.
Online Round
In this round there were 20 MCQ’s to solve and 2 coding question. Of the 20MCQ’s a couple
of questions were on Quantitative aptitude, relationships, OS, DBMS, Data structures etc.
there was negative marking for every wrong answer so I attempted only 15 for which I was
sure.
Q1- find the first non repeating character in a string.
Q2- given a binary tree where each node has some weight. You have to return the max
weight in the binary tree.
Maxweight = value of root node + value in its left subtree and right subtree.

Ex 2
/ \
-1 3
Output = 4

After this round 33 students were selected for face 2 face round. �
Round 1 F2F (40-50 mins)
Q1 – given a binary tree where the left subtree is mirror image of right subtree. So you have
to check whether the tree is symmetric or not (structure wise). O(n)

Ex - 1
/ \
2 3

321
Chapter 123. Set 122 (On-Campus for Internship)

\ /
4 5
Output - Yes

Q2 – given a sorted 2D matrix and you are given a value you have to search that value in
the matrix. I gave him two solutions. O(row + col)
Q3 – given two arrays in sorted form. The first array has some empty space equal to the
size of second array at its end. You have to merge both array in the smartest possible
way in the first array. With constraint that auxiliary space O(1).
Ex – arr1[9] = {2,4,5,7,8,_,_,_,_};
arr2[4] = {3,6,8,9};
after merging arr1 should be = {2,3,4,5,6,7,8,8,9};
For every question I was asked to write a working code with all corner cases handled. I
impressed the interviewer very much in this round :). Then I ask him some questions like –
how an intern contribute to the amazon’s claim to be the most customer centric company
and a few more.

Round 2 F2F (70–80 mins)


This interview was with a senior guy.
Q1 – Given a very large n-ary tree. Where the root node has some information which it
wants to pass to all of its children down to the leaves with the constraint that it can only
pass the information to one of its children at a time (take it as one iteration). Now in the
next iteration the child node can transfer that information to only one of its children and at
the same time instance the child’s parent i.e. root can pass the info to one of its remaining
children. Continuing in this way we have to find the minimum no of iterations required to
pass the information to all nodes in the tree.
Minimum no of iterations for tree below is 6. Consider passing root information first to any
child except A-B answer will come more then 7. So 6 is the minimum answer.

I gave many approaches for this question but he was not satisfied with any approach. I
said I will try to do it in a binary tree then I will generalize it for n-ary tree. He said your

322
Chapter 123. Set 122 (On-Campus for Internship)

binary tree approach is correct but the way you are generalizing it to n-ary is wrong. The
interviewer gave me many hints and said you have almost solved the question but missing
a single point which I was not able to find till the end. Finally he moved to other question.
Q2- given a binary tree you have to check whether it is BST or not.
This question was very easy. I solved it within minutes (one inorder traversal approach
O(n)) but to my surprise the interviewer was saying it is wrong. I explained to him but
again he said it is wrong. His motive was to pressurize me but I stick with my solution and
finally he moved to other question. My answer was correct.
Q3 – given a BST find the Nth maximum and Nth minimum element.
I solved it in O(n). He was fine with it but he said do it in logarithmic time. I did it too
with some preprocessing and coded both the approaches.
Overall it was a very nice experience interviewing with them.
Some tips:

• Be confident. Don’t let the pressure prevail on you.


• Amazon is mainly looking for those who can write code, only telling approach is not
fine. So start practicing as much as you can. There is no barrier of programming
language.
• Please do ask questions to interviewers when they ask and try to ask something which
shows that you are very much interested in working with them
• www.geeksforgeeks.org – my guidebook. Utilize the immense resource available on this
portal for your benefit but don’t mug up the code. Try to first solve it by yourself.

Good Luck !!!


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-122-campus-internship/

323
Chapter 124

Set 123 (On-Campus for


Internship)

Amazon Interview | Set 123 (On-Campus for Internship) - GeeksforGeeks


Online round: In this round there were 20 MCQ’s to solve and 2 coding question. Of the
20MCQ’s a couple of questions were on Quantitative aptitude, relationships, OS, DBMS,
Data structures etc. there was negative marking for every wrong answer so I attempted
only 15 for which I was sure.
Q1- find the first non repeating character in a string.
Q2- given a binary tree where each node has some weight. You have to return the max
weight in the binary tree.
Maxweight = value of root node + value in its left subtree and right subtree.

Ex - 2
/ \
-1 3
Output = 4

1st round(50 mins):


Q1. Reverse link list in k chunks
https://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/
Interviewer was first interested in approach then he asked me to code.
Q2. Spiral order traversal of binary tree
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
I first told him 2 stack approach but he asked me to do without stack .Then I gave him a
solution using one queue and one stack and he finally asked me to code both the approaches.
Q3. Longest palindromic substring
https://www.geeksforgeeks.org/longest-palindromic-substring-set-2/
I first used DP but he asked me to do O(1) space complexity. I was unable to do so.

324
Chapter 124. Set 123 (On-Campus for Internship)

2nd round :
Q1. Connect sibling pointer in a binary tree
https://www.geeksforgeeks.org/connect-nodes-at-same-level/
https://www.geeksforgeeks.org/connect-nodes-at-same-level-with-o1-extra-space/
Q2. Push ,pop and min operations in O(1)
https://www.geeksforgeeks.org/design-and-implement-special-stack-data-structure/
He asked me to do middle operation also and then he asked me to code 2nd problem.
https://www.geeksforgeeks.org/design-a-stack-with-find-middle-operation/
Q3. Given n point in a 2d plane ,find k distant nodes from the origin.
I told him min heap approach and he was satisfied.
Q4. Problem statement was very long but it was topological sorting.
https://www.geeksforgeeks.org/topological-sorting/
I used adjacency list representation, he asked me why
And finally asked me to code it.
Overall it was a very nice experience interviewing with them.
Some tips:

• Never give up
• Don’t start with coding ,first explain the approach.
• Be honest
• www.geeksforgeeks.org – my guidebook.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-123-campus-internship/

325
Chapter 125

Set 124 (On-Campus)

Amazon Interview | Set 124 (On-Campus) - GeeksforGeeks


Hello friends, recently amazon visited our campus selecting 2 FTE and 7 interns for different
roles.
I would like to say about rejections. I’ve got rejected in many companies (even in Amazon)
but finally got placed in a good company. So be strong, there is always a door opened for
us.
Here I share my experience with amazon.
Round 1:
Around 500 people attended this round. As usual 20 MCQ and 2 programming questions.
We need to do at least one programming question to get through this round.
MCQ’s include various topics like OOPS, OS, CN, DBMS etc.
Two coding questions were:
1. Merge two linked lists of different size such that nodes from each list are arranged
alternatively.
2. Finding the minimum difference (I forgot the actual question).
59 people got shortlisted in this round.
Round 2:
It’s a group fly round and people are divided into groups and asked to sit in different class
rooms.
We were given a question in a paper. Here everyone got a standard question. The question
which I got was “Finding the largest contiguous sub array, start and end indexes must be
printed with sum “ (kadene’salgo).
My friends got questions like “Boundary traversal” etc.
So, This round is very simple and if you are strong in standard problems, you can clear it
with ease.
29 got shortlisted to next round.
Round 3:
It was very simple for me because we were running out of time. Only one question was

326
Chapter 125. Set 124 (On-Campus)

asked.
“Find the kth element from the end in a SLL “
Different approaches were discussed and he asked me to code for the best one.
19 got shortlisted to next round.
Round 4:
It was one of toughest round for me. I was very much interested in SDE role but I was
interviewed for SE/QAE role. I dint dare to ask the interviewer about the role. We are not
said before the interview that they are going to interview for that roles. I mean it is in their
hands to decide the role that matches your skills.
Questions were a bit tough for me in this round because am not much good in troubleshoot-
ing and testing. And this round went almost for 1 hr 30 mins.
Questions:
1. Given start and finish times of a youtube video and how do you confirm that the video
is completely watched by the user or not? I gave a solution, we can set flags when the user
watches a particular unit of video. He asked me how discrete? I said it may be in terms of
seconds. He then asked me, If a user is just watching in terms of microseconds? I was not
able to give the right answer. He was not satisfied with my solution. �
2. A web application is running. We have only a text box. If we enter a name in the
text box, we get the details of the person whose name is entered. Now the question is to
troubleshoot the application when it stopped displaying the results after entering a name(
whose details are present in the data base).
I answered many points here, like server is disconnected and there may be locks on the
details such that only one user can access the data at a time. And many other, but he was
not much satisfied.
3. Give the test cases for the Gmail login page. At first I got tensed on hearing this question
but I answered well. I almost gave 10 test cases quickly but, the interviewer want to extract
as many he can. So he started noting down all the points which I said and kept asking me
further points. Finally 25 – 30 test cases were covered.
4. Given a video whose audio is not playing in a video player. Troubleshoot.
I gave many answers here. Like, there may be two major possibilities here. 1. The video
may have some problem 2. The video player software may have some problem. Then I gave
many points in each category. Like OS dependent etc. He was satisfied with my answers.
5. And 2 more questions were asked (I forgot ) They were from testing and troubleshooting.
14 got shortlisted to next round.
Round 5: (Hr + Tech )
This was the round which I dint get through. �
First, Tell me about yourself. I request everyone to be well prepared for this question in
any interview. It looks so simple, but its very difficult to impress the interviewer with your
answer here.
Next was a question from trees. Find the vertical sum in Binary tree. I said I’ve done it
before and I know the solution. He asked me to go ahead. Then I answered the same thing
which was given in GFG. He then asked me to do it in a single traversal. I gave another
solution but it also took 2 traversals. He scolded me that it is also taking 2 traversals. I
was not able to think anymore after this. But it was very simple one. ?

327
Chapter 125. Set 124 (On-Campus)

Next he asked me to find the duplicate chars in a infinite length stream of chars. I gave a
hashmap solution and he asked me about hashmaps. He then extended the question that we
have Integers also. Even then I said hashmap solution suits. He asked me about collisions
here. He asked me how much size of hashmap you need?. And also about the range of
elements that can be mapped? I answered well all these questions because I’ve read a lot
about hashmaps.
Next he asked me a troubleshooting question. I answered this like the one which I faced in
the previous round.
Next he asked me “what happens during withdrawal of cash from ATM “? (only during
withdrawal ?)
I was not able to convince him with my answers. He was expecting a lot in terms of internal
clocks and stuff in ATM.
Next He asked me “what happens when you enter an URL in a web Browser “?
I read this question in many interview experiences, so I answered it well But, He asked few
questions in between. Like what is HTTPS? What does ‘S’ stands for in ‘HTTPS’?
And finally I was in a trap by this final question. What is a Web server? I really don’t
know. But I dared to answer, But to my bad luck I answered DNS server instead of Web
server. He was very much angry with my answer and asked am bluffing? GONE �
All the impression was gone by just one simple mistake of mine and I dint get through.
Finally 9 people got offers out of 14.
2 were FTE and 7 were given INTERN.
TIPS:
If you are aiming for AMAZON then just try to solve as many questions as possible in GFG.
Try to be frank in the interview. If you don’t know the answer, Just accept that you don’t
know.
Finally be Strong. Rejections are inevitable unless you are very cautious.
I hope this will help others.
ALL THE BEST.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-124-campus/

328
Chapter 126

Set 125 (On-Campus for


Internship)

Amazon Interview | Set 125 (On-Campus for Internship) - GeeksforGeeks


Online Round
In this round there were 20 MCQs to solve and 2 coding questions. Of the 20MCQs a couple
of questions were on OS, Quantitative Aptitude, Data structures etc. Most of them are there
on www.geeksquiz.com. In MCQs there was – 0.25 marking for every wrong answer and +1
for right answer. Coding questions were of 10 marks each.
Q1- Given an array of positive and negative numbers, arrange them in an alternate fashion
such that every positive number is followed by negative and vice versa maintaining the order
of appearance.If the count of negative numbers is more keep the extra at last in array
constraint : Space complexity should be O(1).
Q2- Given an array of random numbers, Push all the zero’s of a given array to the right
end of the array in minimum possible swaps. Order of appearance doesn’t matter. Print
the total nonzero numbers and minimum swaps needed to do so.
input : {1, 9, 8, 0, 0, -2, 0, 1, 6}.
output :
nonzero : 6
swaps : 2 (-2 as it is and swap 1 and 6 from first two zeros. )
18 were selected out of 55 for f2f round.

Round 1 F2F :
Q1- Two linked lists merge at one point, return the converging node. Constraint- O(1) space
and O(m+n) ,where m and n are lengths of lists.
Link: http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-
linked-lists/
Q2- Rotate the alternate levels of a binary tree.

329
Chapter 126. Set 125 (On-Campus for Internship)

Input:
1
/ \
2 3
/ \ / \
4 5 6 7
/ / \ / \
8 11 10 12 13
Output:

1
/ \
3 2
/ \ / \
6 7 4 5
/ \ \ / \
13 12 8 11 10

First he asked to do it without recursion and then with recursion. O(n) time complexity.
Q3 – Write an efficient function that takes two strings as arguments and removes the second
string from first string (in place). (Shifting not allowed)
input:
str1: aabcabcb
str2: abc
output: ab
Q4 – Insert an element into a sorted link list which is having loop somewhere and duplicate
elements as well.
Q5 – Make your own data structure. which inserts, deletes and gives a random number in
O(1) time.
Hint : Use hash table and array.
Round 2 F2F :
Q1 – You have n pencils, each having l length. Each can write 4 kilometers. After writing
4 kilometers it has l/4 length. Then you can join 4 pencils which are having l/4 length and
can make 1 pencil. You can’t make pencil of pieces if remaining pieces are 3 or 2 or 1 in
number. And you can include these remaining pieces whenever you need. Write a recursive
relation independent of l,length of given pencil, for how much one can write from n pencils.
Write mathematical equation also.
Q2 – Find the largest sum subtree in a given Binary Tree.
Q3 – Reverse level order traversal.
time complexity : O(n)

Input:
1
/ \

330
Chapter 126. Set 125 (On-Campus for Internship)

2 3
/ \ / \
4 5 6 7
/ / \ / \
8 11 10 12 13
output:
13 12 11 10 8 7 6 5 4 3 2 1

You are permitted to use extra space and now print them in separate levels too.
Output:
13 12 11 10 8
7654
32
1
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-set-125-on-campus-for-internship/

331
Chapter 127

Set 126 (For SDE-1)

Amazon Interview experience | Set 126 (For SDE-1) - GeeksforGeeks


Recently I got interviewed with Amazon for SDE1 position and here is my interview expe-
rience which I would like to share with others.
Telephonic round:
1. An array is given with element name and their respective pH values. Print the combina-
tion of 2 elements which make a neutral compound.
A discussion started and best solution was O(n) time complexity and O(1) space complexity.
Then I got call for F2F interviews and here are those-

Round 1:
1. Print Matrix in spiral form.
2. A store have n customers and any 1 can visit them any time through out the year.Data
is stored in a file.Design a data structure to find given person visited on so n so date or not.
Round 2:
1.There are N packages P1, P2…Pn. A package may depend on another or many other for
its compilation. Given a matrix of dependency, find a sequence of package compilation.
2.A 2D matrix is given, with each elements representing number of gold coin at that position.
I have to travel from (0,0) to last element of matrix collecting maximum no. of coins.I can
travel either right of an element or down of it.
3.In Galaxy there are trillions of stars. I am provide distance of every star from earth. Tell
me nearest 1Million stars to earth, provided with best time and space complexity.

Round 3:
1. Implement LRU.
2.In Android phones we have 3X3 grid for making a pattern. Given a length, find number
of combinations for that length in that grid.
Round 4:
1. Project deep discussion.
2. Few given scenarios and how you will tackle.

332
Chapter 127. Set 126 (For SDE-1)

3. Strengths and weaknesses.


4. Given a file with many statements. Print all the strings with their anagrams through the
file.Logic to check anagrams and to store them.

Round 5(Bar Raiser):


1. Behavioral Questions like
>Why you want to leave your organization?
>What is most challenging work you have done till date?
>Why you want to join Amazon?
etc.
2. Which data structure you know?
3.Say I have few words and their meaning, and I want to store them which DS will you use
and why.
I started with Hashmap and we kept on discussing about pros and cons.Finally ended up
with trie.He asked me to write code for it, for adding new word and for fetching meaning
from Trie.
The whole process started in 1st week and yesterday got a call from HR for I am invited to
be part of Amazon.
Thank you geeksforgeeks for providing such a nice platform to learn and share.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-126-sde-1/

333
Chapter 128

Set 127 (For Internship)

Amazon Interview experience | Set 127 (For Internship) - GeeksforGeeks


Amazon visited our campus for summer internship. I prepared from Amazon Interview Sets
which were pretty helpful!
Here is my experience :
DAY 1
They had an online aptitude test on day 1. It was 90 minutes: 20 MCQs + 2 coding
questions (choice between C/C++/Java for coding). MCQs were based on DSA, OS, and
Math. They were apparently difficult.
Two Coding Questions :
1. Keypad problem – Little difficult problem on backtracking.
2. Given an array, find the count of impossible triangle
Day 2:
Surprise aptitude test:
2 coding questions 60 mins.
Questions involved DSA and strongly based on optimising the code:
1. Given a linked list, reverse K nodes in it
eg :- 1->2->3->4->5->NULL , k = 3
3->2->1->5->4
2. Search for an element in an array which has elements who’s values are first increasing
and then decreasing. (Use modified binary search)
2 One-on-one Interview rounds, both technical.
Try giving THE most optimal algorithm which satisfies edge cases too.
I was told to write the code on the paper.

334
Chapter 128. Set 127 (For Internship)

Questions asked to me were:

First interview round


1. Find the second largest element in an array.
2. Given a sorted array which can have repeated elements, find the occurrence of an element.
(Most optimal solution is O(logn) – Using binary search to find start and end occurrence)
3. Make a data structure and implement an algorithm to print all the files in a directory.
(the root directory can have sub-directories too.)
I used an n-ary tree and BFS to print files. It can also be done using Stack.

Second interview round


1. He asked some question about my CV
2. Print a matrix diagonally.
3. DFS of binary tree, n-ary tree.
4. Then he asked some question from other subjects.
OS – Scheduling
DBMS – Normalization, Transaction
OOPS – Abstraction
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-126-internship/

335
Chapter 129

Set 128 (For SDET)

Amazon Interview experience | Set 128 (For SDET) - GeeksforGeeks


I was interviewed for the position of SDET-1 few days back at Chennai. Here is my interview
experience:
Coding round (Full code required):
1) Given a linked list. Check whether it is a palindrome (without using any extra space).
2) Write a program to return the mirror tree of a given binary tree.
3) Given a 2-D array, Rotate it by 90 degrees.
F2F-I:
1) Given a phone number. Check whether it is unique or not(ie no duplicates)
I gave a o(n^2) TC algo first which he wanted to optimize. After 3 series of optimization ,I
came up with a o(n) solution with o(1) space complexity.
2) The interviewer told me to code a level order traversal in a binary tree.
3) An array of numbers are given such that the absolute difference between adjacent elements
is 1.Given a value…Return the index of the 1st occurrence of that element.
I gave an solution where in the 1st value is subtracted from the search value and hops in
the array by that difference. if the reached value is the search value ,then return the index
or just continue this process. The interviewer was impressed by my solution and told me to
code it.

F2F-2:
1) Brief discussion of work in current company
2) A given array represents a tree in such a way that the array value gives the parent node
of that particular index.The value of the root node index would always be -1.Find the height
of the tree.

Ex: Array: 1 5 5 2 2 -1 3
5

336
Chapter 129. Set 128 (For SDET)

/ \
1 2
/ / \
0 3 4
/
6

I gave a iterative solution which was told to be optimized. I did optimize it using memo-
rization concept. I had to code it too.
3) Write a program to find the median of 2 sorted arrays when merged.
This problem is there in geeksforgeeks.
4)Write an optimised program to find the number of factors for a particular number
This was a very simple qn.
F2F-3:
1) Brief discussion of work in current company. Why Amazon?
2) Why do you want to leave current company? What do you like most and dislike most
about your current company?
3) Design a automation framework to test a simple site with a login page .Give the various
test cases also that should be considered. Later they told me to give some enhancements to
the code too.
4) Design a automation framework to test twitter api’s that is used in a particular site .
5)Give the various automation scripts and tools that I implemented in my current project.
F2F-4(Hiring Manager):
1) Lots of HR, behavioral and team fit questions
2) Describe the most challenging project I have worked on…and why is it challenging.
3) An e-commerce site has a particular functionality created by a group A and another
functionality created by group B. Design a testing framework that could test the work by
A as well as A/\B(intersection).
4) I was working as a security Analyst.So I was asked about 5 critical hacking techniques
that can be used to a e-commerce site and describe each.
F2F-5(Bar raiser):
1)Again behavioral and team fit questions.
2)Write a program to check the validity of sorting algorithms used to sort Linked
lists.Consider the case where 2 nodes have equal values too.
I gave a optimized code using hash table concept. The interviewer was pretty satisfied with
my coding ability and started asking me about my projects.
3)More questions on my projects
Thank you geeksforgeeks for helping me out during my preparation.
All Practice Problems for Amazon !

337
Chapter 129. Set 128 (For SDET)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-128-sdet/

338
Chapter 130

Set 129 (For SDE 1


Off-Campus)

Amazon interview Experience | Set 129 (For SDE 1 Off-Campus) - GeeksforGeeks


In the recent past, I attended interview with Amazon. Here is my interview experience.
Written Round: 1.5 hours
1. Given an array of integers, replace each element with the next immediate greater element.
2. Given a linked list, reverse each 3 nodes.
3. Given a tree, print all the nodes which are K distance from the leaf nodes.
Face to Face Interview 1 (Data structures and Algorithms)
1. Given a source string and destination string, Find the minimum number of edits (op-
erations) required to convert one string into another. At the end of each operation, the
resultant string should be a dictionary word.
2. Given an array of integers where each element represents the max number of steps that
can be made forward from that element. Write a function to return the minimum number
of jumps to reach the end of the array (starting from the first element).
3. Given the coordinates of billion stars in the sky, find the closest 100 stars from our current
position (0,0).
Face to Face Interview 2 (Problem solving)
1. Given a binary tree, write code to check if it is a binary search tree.
2. Given a binary tree and two nodes, write code to find the common parent for the 2 nodes.
Given the below tree, and nodes 18 and 21.

10
5 15
2 3 12 18
16 21

The result should be 15.

339
Chapter 130. Set 129 (For SDE 1 Off-Campus)

Face to Face Interview 3 (CS Fundamentals)


Tell me about yourself.
Why career change ? Why Amazon?
1. What happens when you compose an email and press the send button. How is the mail
delivered?
2. Explain how mail server works.
3. Tell about the routing algorithms you know.
4. How is the data transferred across the network ?
5. Difference between TCP/IP and UDP.
6. What are the functionalities of an Operating System?
7. How does OS schedule processes ?
8. Which type of scheduling algorithm is used widely ?
9. How does OS replace processes in memory ?
10. How does OS detects if a deadlock has happened ?
11. When you type an SQL query in interpreter, what does happen? How is the query
processed?
12. What is Primary Key, Foreign Key ?
13. Should Foreign key needs to be primary key of another table ?
14. What is index ? How it is implemented ?
15. How is the data stored in the database ?
16. Why doesn’t Java support Multiple Inheritance ?
17. What are the advantages and disadvantages of Multiple inheritance ?
18. Tell us about the design patterns you know.
19. Do you know about Factory Design pattern ?
20. Write a simple class which implements Singleton design pattern. Applications of
singleton design pattern. Why don’t we declare the class itself as static class ? Why
don’t we declare all the members as static ?

Face to Face Interview 4 (Hiring Manager)


Tell me about yourself.
Why career change ? Why Amazon ?
1. Discussion about my current project, I am working on. Questions related to schema
design, how can we improve it ? How to make the application scalable if the operations and
data (session creation & data) are going to be increased 100 times. When do we need big
data ?
2. What is your biggest achievement ?
3. What do you expect from your manager and team members ?
4. Given billion numbers in a file, get the top 10 numbers from it.
5. Write code to implement Hashmap in Java. It should accept any datatype and also
objects.
6. Provide a high level class design for cab management system. Finding available car
anytime and booking it, customers, orders, etc.
Face to Face Interview 5 (Bar raiser)
Tell me about yourself.
Why career change ? Why Amazon ?
1. What is your biggest achievement ?
2. Discussion about my project. Discussion about the tasks which I have done.

340
Chapter 130. Set 129 (For SDE 1 Off-Campus)

3. Tell me about a situation where you had a conflict with your manager and how you
resolved it ?
4. What is the biggest bug have you made ?
5. Have you developed any tool, which is used by your colleagues ?
6. Is there any task which you feel, that you could have done better in your project ?
7. Have you suggested any ideas and improvements to your project, beyond your call of
duty ?
8. Given a binary tree, write code to get the vertical sum of all the columns in the tree,
with minimum space complexity. After I told a solution with Hash, he asked me to come
up with a solution without using hash and code it.
Face to Face Interview 6 (Data structures)
1. Given a binary tree, how would you serialize it, store in a file and then recreates it again
from the file ?
2. Given a dataset below,

Name Score Rank


A 50 1
B 40 2
C 30 3
D 20 4
E 10 5.

Name is a string and Rank is inversely proportional to the scores.


What type of data structures would you use to store these data to perform the following
operations ?
1) Given Rank, Get the Name and Score
2) Given Name, Get the Score and Rank
3) Given Name, Update Score.
Though I didn’t get the offer, it was an amazing interview experience with Amazon. Thanks
to GeeksforGeeks, an ultimate portal for learning DS & problem solving and for cracking
the coding interviews.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-130-sde-1-campus/

341
Chapter 131

Set 130 (For SDET 1)

Amazon interview Experience | Set 130 (For SDET 1) - GeeksforGeeks


I attended an interview with Amazon for SDET-I position, about a month back. I did not
clear the interview, but I would like thank GeeksforGeeks for the great learning period before
the interview. GeeksforGeeks helped a real lot in my interview preparation and in general,
my understanding of data structures and algorithms got deeper and stronger. Thank you
very much GeeksforGeeks and all your valuable contributors!
Here is my interview experience:
Telephonic 1:
1. Given an array and a number, check whether there are any 3 elements in the array which
add up to the given number.
For example:
Given an array {1,2,3,4,5} and the number 9, return true, as 2,3,4 add up to 9.
Given an array {1,2,3,4,5} and the number 3, return false, as there are no 3 elements
which add up to 3, in the array.
2. Given a number, find the nearest perfect square(modified binary search)
For example:
Given 50, return 49
Given 25, return 25
Telephonic 2:
1. Write a method to check whether two binary trees are mirrors of each other
https://www.geeksforgeeks.org/check-if-two-trees-are-mirror/
2. Write a method to print the boundaries of a binary tree
https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
F2F 1:
1. Fill an array with the next greater elements (using stack)
https://www.geeksforgeeks.org/next-greater-element/
2. Given a binary tree, count the number of occurrences where there are two nodes with the
same horizontal distance. To make it clearer, if we assume each node in a cell of a matrix,

342
Chapter 131. Set 130 (For SDET 1)

then count the number of occurrences when there is a collision of two nodes in the same
cell.

Here the count is 1 because 5 and 6 occupy the same cell in the matrix
F2F 2:
1. Given a linked list, write a program to check if it is a palindrome
2. Write some test methods for stress testing of Furniture class
3. Some discussion on automation testing

F2F 3: (System automation design)


System: The user gives a book id to be downloaded and the location in which the book is
to be stored. The system downloads the book (if it exists) in the location given by the user
and returns a url through which the user can access the book.
I was asked to design automated test cases for the system. The interviewer kept adding
more and more constraints to the system and we discussed about the pros and cons of my
approach.
Hiring Manager:
1. Discussion about my current job role
2. Several behavioral and team fit questions
3. What are the things you will consider (both from Developer’s perspective and User
perspective) while trying to develop an application for computer aided competitive exami-
nations like CAT, GMAT etc.

Bar Raiser:
1. Given a singly linked list, write a recursive method to reverse every 3 nodes in the list.
I did not write a clean code for this. He moved on because of lack of time.
2. Again discussion of my current job role and about the projects I have worked on.
3. Tell me 3 things that you want to learn/change in yourself
4. Again several team fit questions.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-130-sdet-1/

343
Chapter 132

Set 131 (For SDET 1)

Amazon interview Experience | Set 131 (For SDET 1) - GeeksforGeeks


Amazon visited my college and offered me SDET-I position. GeeksforGeeks helped a real
lot in my interview preparation. Thank you very much GeeksforGeeks!
Here is my interview experience:
Round 1 (On-line Coding Round on HackerRank):
1. Given an array of sorted integers which represent box sizes and an integer representing
an item size
You have to find best fit box for the item (-1 in case of no box found)
For example:
Given 10,20,30,40,50,60,70 and 45
You have to print 50
Given 10,20,30,40,50,60,70 and 75
You have to print -1
Given 10,20,30,40,50,60,70 and 50
You have to print 50
2. https://www.geeksforgeeks.org/forums/topic/find-a-string-inside-a-2-dimensional-array/

F2F 1:
1. Given an array of integers
you have to output sequence a1,a2,a3,a4,a5,a6,a7 such that a1a3a5a7
For example:
Given 10,20,30,40,50,60,70
You have to print 10, 30, 20, 50, 40, 70, 60
At first, I gave answer using sorting. But my interviewer asked me to do this without sorting
the input array, and I did it.
2. A simple question on Tree data structure which i don’t remember.
3. Questions related to my project.

F2F 2:

344
Chapter 132. Set 131 (For SDET 1)

1. A matrix is given which is sorted row wise and column wise


You have to print the sorted order.
For example:
Given
123468
233478
234578
234588
344689
455789
You have to print sorted order
2. Questions related to my project during my internship.
F2F 3:
1.What happens when we type amazon.com
Relating to this the interviewer asked me every step in detail including all 7 layers of
networks.
Protocols like: HTTP, HTTPS, DHCP, DNS, IMAP, POP, TCP, UDP etc. Their uses and
differences.
2. Describe ACID property of a transaction (DBMS).
Bar Raiser(Telephonic):
1. Given a singly linked list, write a recursive method to reverse every 3 nodes in the list.
He asked me to inform if I have seen the question.
And I replied : Yes sir, it is the similar question I faced in coding round of Amazon-internship
last year.
But he didn’t changed the question.
I solved it with a silly mistake which i corrected when mentioned.
2. Long discussion on my internship and about the projects I have worked on.
3. Tell about your criticism.
4. 3 weaknesses currently i am working.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-131-sdet-1/

345
Chapter 133

Set 132 (For SDE Intern)

Amazon interview Experience | Set 132 (For SDE Intern) - GeeksforGeeks


Online Round :(Duration – 90 minutes)
20 MCQs to solve and 2 coding questions. 20MCQs were on Algorithms,Data Struc-
tures, C Output, Quantitative Aptitude, etc.
Coding questions were of 10 marks each.
MCQ’s had negative marking.
Correct : +1
Wrong : -0.25
Q1– Given an array of numbers, arrange them in an alternate fashion such that every
number is followed by a number of opposite sign. Also the order was to be maintained.
If the count of negative numbers is more keep the extra at last in array and same for positive
numbers.

Example :
Input: -3 -2 6 0 7 -1 -8
Output: -3 6 -2 0 -1 7 -8

Q2– String of characters as arranged in a cellphone i.e.


1- NULL
2-a,b,c
3-d,e,f
4-g,h,i
.
.
.
9-w,x,y,z
0-NULL
Print all combinations for given number of digits(k) in lexicographical order .
Constraint : 1<=k<4

346
Chapter 133. Set 132 (For SDE Intern)

For Example : Input = 234


Output : adg adh adi aeg aeh aei afg afh afi bdg bdh bdi beg beh bei bfg bfh bfi cdg cdh
cdi ceg che dei cfg cfh cfi
Round 1 F2F :(Duration – 1 hr)
Introduce Yourself.
Q1– Design a shuffle function which would play songs randomly in your device (unique
song_id) and code it.
After i gave him a solution with hash function , he asked me to improve the algorithm such
that once a song is played it should be played only when all the other songs are played,
Solution’s Complexity : Space – O(n) , Time – O(1) ; n—> number of songs
After that he asked me to improve my solution and do it without using extra space.
Solution’s Complexity : Space – O(1) , Time – O(n) ; n—>number of songs
Hint : Maintain indices and once a song is played shift it in range of played songs index.
After that i was asked about each part of the hash function and how i came up with that.
Q2– Add two linked lists. And code it.

Input : 1->2->3->4->NULL
8->2->NULL
Output : 1->3->1->6->NULL

First he asked to do it without recursion and then with recursion.We also talked about
the problem we face if we store the value of the linked list in an integer or long if the
number of digits were above certain limits in the non-recursive function.
Round 2 F2F :(Duration – 1 hr)
Introduce Yourself.
Q1 – Find the largest subtree which is binary search tree in a given Binary Tree.
Then to optimise it and then asked me to code it.
Q2 – Given a linked list with a next pointer and an arbitrary pointer pointing to any node
in the list , copy the linked list.
After i gave him a solution which changed the links of the initial linked list, he asked me to
do without changing the links.
So i gave him a O(n^2) solution . He asked me to give another way or optimise my solu-
tion.He helped me to figure out the solution.
Hint – Hash map.
The interviewers were really helping and supporting and were more interested in seeing the
efforts you make and the way you get to the logic.They help throughout by giving hints.
Thank You geeksforgeeks for helping me out.
Best of luck .
All Practice Problems for Amazon !

347
Chapter 133. Set 132 (For SDE Intern)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-132-for-sde-intern/

348
Chapter 134

Set 133

Amazon interview Experience | Set 133 - GeeksforGeeks


Recently had a interview with Amazon, through employee referral. All face to face rounds.
I didn’t clear, so no offer. �
1st Technical Round:
Given an integer, find the next biggest integer whose digits are in increasing order.
Example:
Input: 118
Output: 123
Input: 127
Output: 234
Input: 987
Output: 1234
Designing question: Design a parking space to park a car.
2nd Manager Round:
Explain my current project. Architecture and design flows etc. asked.
Any challenges while working on the project.
Any glitches/cases where you completed got it wrong etc.
After two rounds asked to leave. I guess I didn’t answer as per standards.
Thanks anyways GeeksForGeeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-133/

349
Chapter 135

Set 134 (Off-Campus for SDE)

Amazon interview Experience | Set 134 (Off-Campus for SDE) - GeeksforGeeks


I would like to start off by thanking the entire community of GeeksforGeeks for helping me
out.
Attempt 1
Round1:
1. Given a number N, find the number of correct combination of parentheses possible.

Input: N=2 => ()()


Output: 2 [(()),()()]

Input: N=3 => ()()()


Output: 5 [()()(),((())),(())(),(()()),()(())]

2. Print all root to leaf paths using iterative algorithm in linear time.
Round 2:
1. Given ‘m’ and ‘n’ (m < n), print all nodes between levels ‘m’ and ‘n’ in level order.
2. Print a matrix in spiral order.
Round 3:
1. Check if two trees are mirror images of each other.
2. Given inorder and preorder traversals, build a binary search tree.
3. Print all the boundary nodes of a given binary tree.
I was rejected after this round. I applied again after few months.
Attempt 2
Written Round(on HackerRank): It contained 3 simple questions on data structures.
Duration 60 mins.
F2F – Round 1:
1. Given a singly linked list and a value ‘k’ such that kF2F – Round 2:

350
Chapter 135. Set 134 (Off-Campus for SDE)

1. Given a BST and given that 2 nodes are swapped in the tree. Identify the 2 swapped
nodes.
2. Given a BST and 2 nodes. Identify the length between the two nodes of the tree.
F2F – Round 3:
1. Detailed discussion of current projects.
2. How would you design the meeting invite feature of Microsoft Outlook? Considering
each meeting invite as an object and that Web server is the storage space for the invites,
design a data structure to receive and send invites to user in an efficient manner. The
message objects must be received in a sorted manner based on the time of meeting. I gave
an O(NlogN) solution and he was pretty impressed. I was then asked to code it.
3. An array is given whose every ith index is the child node of a[i] as shown in the example
below. The root node is represented by -1. Find the height of the tree.I did it in linear time.

Input: parent[] = {1 2 -1 2}
Output: 4
The given array represents following Binary Tree
2
/ \
1 3
/
0

F2F – Round 4:
1. Cultural info and projects discussion. What errors have you performed in your career
path? What are the major challenges that you faced?…and other such questions.
2. Design a parking lot system. She was very much concerned with all the edge cases.
3. How would detect whether a singly linked list is a palindrome or not?I gave a solution
with O(n) time and space complexity. But she asked to optimize it further with O(1) space
complexity.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-134-campus-sde/

351
Chapter 136

Set 135 (On-Campus for SDE)

Amazon interview Experience | Set 135 (On-Campus for SDE) - GeeksforGeeks


Recently, Amazon visited our campus and I was interviewed for SDE position. Here is my
Interview Experience:
Online Round: (Duration – 90 minutes)
20 MCQs and 2 coding questions. MCQs were on Algorithms, Time Complexity, Quantita-
tive Aptitude, Probability, Operating Systems, Graphs, Data Structures, Recursion outputs
etc.
Coding Questions:
1. In one of Amazon fulfillment centers, there are a no. of empty boxes kept in increasing
order in a row. Kiva robots are designed to put a product in a box. The product size is
given. Design a program to find the best fit box for given product size. First line contains
no. of empty boxes and next line contains size of boxes with space. The next line contains
size of given product. The output shows the best fit box size and -1 otherwise.

For example, Input: 6


2 7 9 11 13 16
12
Output: 13

2. You have to find a string in two-dimensional array. The input contains 2-D array of
characters and given string. You can move in one of eight directions . The output contains
location of first letter of string if string found completely, otherwise return -1. Any one out
of multiple answers is accepted, if possible.
For example, Input:
btg
pad
rkj
String: rat
Output: (2,0)

352
Chapter 136. Set 135 (On-Campus for SDE)

F2F Round 1:
Brief introduction about myself and my project.
1. Given an array of positive and negative integers, rearrange positive and negative numbers
in 0(n) time .
First, I solved it using 2 arrays,each for positive and negative integers and place elements
of array in these 2 arrays and them combine them back by taking one element from each
array. Then he told me to do without extra space. I then segregated positive and negative
elements using quicksort .Below is the link:
https://www.geeksforgeeks.org/rearrange-positive-and-negative-numbers-publish/
2. Program to check whether strings are rotation of each other or not. I approached as below:
https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other-or-not/
He then told to solve without using strstr. I used naive searching method.
F2F Round 2 :
Brief introduction and some behavioral questions.
Given a BST and a key sum, design an algorithm to find all pairs of integers whose sum
equal to key.
I first approached using an array and placing elements into it in inorder fashion and then
find pairs. He told to do in-place and I solved with 2 traversals (inorder and reverse- inorder
).
F2F Round 3 :
Based on CS Fundamentals and also had 15 minutes discussion on my internship project.
1. What happens when we type amazon.com ?
2. Describe transaction process in detail if we want to transfer from one account to other.
Also design schema for it.
3. What happens on server side on receiving HTTP requests and how operating system
interacts and then discussion related with threading, thread pool ,synchronization, hashing
etc.
4. Describe ACID properties in detail .
Bar Raiser Round :
1. Given a Binary tree, full_path_sum is sum of all nodes from root to leaf in a path. Given
a min_sum value, delete nodes if path has full_path_sum less than min_sum . Delete all
such nodes . For example,

Given min_sum =8
1
2 3
4 5 6 7
So we delete 4.

2. How to find kth- smallest element in BST?


https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/
Thank you geeksforgeeks for helping me a lot during my preparation.
All Practice Problems for Amazon !

353
Chapter 136. Set 135 (On-Campus for SDE)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-135-campus-sde/

354
Chapter 137

Set 136 (For SDE-T)

Amazon interview Experience | Set 136 (For SDE-T) - GeeksforGeeks


Phonic Interview
**********************
1. Let’s start with you introduction
In between introduction he asked me about my some project work experience and How have
you done?
2. Take a integer as a input and replace all the ‘0’ with ‘5’.

For example:
102 - 152
1020 - 1525
(Do not use any array for replacing the '0' to '5')

3. You are given two binary tree and write algorithm to check
Are two Binary Trees mirror image of each other?
Amazon Interview for SDET @ Hydrabad Development Center
******************************************************************************
1st Round
************
1. Project Detail & past experience
2. Current Technology i am working in
3. https://www.geeksforgeeks.org/intersection-of-two-sorted-linked-lists/
4. Maximum Subsequent distinct & contiguous sub array in a character array
2nd Round
**************
This round was purely for checking Test Framework and Test Case Knowledge.

355
Chapter 137. Set 136 (For SDE-T)

He has given me some scenario and ask to write test cases for them
1. you are given a web page into that simply one browse button and Image Holder is
their.Write the Test Cases for this.
2. You are given application like Google Analytics. How will you test this application ?
3. what are the basic features you will add into your own test framework.
3rd Round
*************
This round was purely a discussion based on past project experience.Like which project do
you think that was most difficult and you had a nice experience.
He asked me each progress point of the project.
1. how will you check that each page of amazon.com is having its logo or not.he also asked
me to write code for this also.
2. Some Test Framework Based question like
3. Have you worked on any automation framework or not?
4. what happen between, when you enter a URL into a browser address bar and hit enter
to actually page gets loaded ?
In between he asked me few things about DNS Server,Router etc and some discussion was
there.
4th Round
*************
1. https://www.geeksforgeeks.org/level-order-tree-traversal/
2. https://www.geeksforgeeks.org/reverse-level-order-traversal/
3. Make a stack using 2 given queue.
4. Some Project Experience & Automation Framework Discussion,which i have worked on.
5. There was some situational questions also for Team work.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-136-sde-t/

356
Chapter 138

Set 137 (Assessment test for


SDE)

Amazon interview Experience | Set 137 (Assessment test for SDE) - GeeksforGeeks
Coding questions:
1) Given two words, find if second word is the round rotation of first word.
For example: abc, cab
return 1
since cab is round rotation of abc
Example2: ab, aa
return -1
since aa is not round rotation for aa
2) Given two hexadecimal numbers find if they can be consecutive in gray code
For example: 10001000, 10001001
return 1
since they are successive in gray code
Example2: 10001000, 10011001
return -1
since they are not successive in gray code.
Aptitude questions:
1) Some based on finding relationships between given number/strings and find the missing
one
Example: VTS: RPO :: AYX: ____
2) Paragraph reading and inferring information from it.
3) Facts provided and making a decision based on it.
4) Combinations possible based on facts provided.
All Practice Problems for Amazon !

357
Chapter 138. Set 137 (Assessment test for SDE)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-137-assessment-test-sde/

358
Chapter 139

Set 138 (For SDE 1)

Amazon interview Experience | Set 138 (For SDE 1) - GeeksforGeeks


Screening round:
Three coding question on hackerEarth to be comiled against the testcases
1. Merge two sorted linked list into single one
2. https://www.geeksforgeeks.org/difference-between-sums-of-odd-and-even-levels/
3. https://www.geeksforgeeks.org/find-first-non-repeating-character-stream-characters/
Round -1
1. Asked me again the logic for finding first non repeating char from a stream of character.
Then the discussion went how hash map internally works and what is the principle behind
it .
How the hash conflict get resolved and write code for the same.
2. Find three triplet with a given sum in an array.
3. Find an element in an row and column wise sorted matrix.
Round-2
1. Find the majority element in an array.
2. Print out all the numbers in sorted order from row and column wise sorted matrix
3. How to find a given key in a sorted stream of array(less than 0(n) complexity required)
4. One more ques dont remember

Round-3 (HM round)


Lots of situational question being asked.(conflict with ur manager, ur say , leadership
quality in you, ownership of project , problem solving capabiltiy)
Lots of question on your owned projects.(Impact of this on your product and time to
implement it)
two tech ques:
1. https://www.geeksforgeeks.org/stock-buy-sell/
2. write code to find whether the tree is BST or not.

Round-4

359
Chapter 139. Set 138 (For SDE 1)

1. In an array find three number which fits into pythagoras theorem(a^2+b^2=c^2).Find


a,b,c
2. Find the number of island in a matrix of 0,1. The island which starts from edge of the
matrix will not be considered island
eg: no of island are 0 here
0100
0100
0000
0000
Round-5
Lots of in depth question about your project and its impact on the product.
Was asked to draw the architect diagram of the algorithm used in my project and explain
with example.
one tech ques : For a given string and given dictionary. Find all the anagrams of the string
which are also present in the dictionary.ie the string shud be a valid dictionary word.
NOTE : I WAS REQUIRED TO CODE EACH AND EVERY QUESTION WITH PROPER
SYNTAX AND EDGE TEST CASES on piece of paper after discussing the algorithm.
Majority Element
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-138-sde-1/

360
Chapter 140

Set 139

Amazon interview Experience | Set 139 - GeeksforGeeks


3 months Experience Candidate.
1. Written test 90 mins which consisted of 2 coding questions and 18-20 MCQ from varied
computer science concepts.
2. Telephonic Round
1. Find the number of occurrences of a number in sorted array.
2. LCA in a Binary Tree.
3. Clone a Tree, where each node had 3 pointers left, right and random. Random pointer
points to any other node in the tree.
Interview Experience F2F (Onsite):
Round A with HM :
1. Check for a complete cycle in a graph. ( A complete cycle is one that covers all nodes )
2. Construct a tree using Preorder and Inorder Traversal.
3. Evaluate a random function.
Since this round was with a hiring manager he asked a few questions like why do you want
to leave your organization? Why so early? Plans for further studies and basic discussion of
projects.
Round B Tech1:
Half an hour discussion on my projects. Then a question on strings. Write a program to
output the minimum size window which contains all the given characters with at-least the
given frequency. This was followed by Test Case design.
Round C Tech2 :
1. Given a Node in a tree and a value k , print all nodes at K distances from the given node.
2. Given a string and k, arrange the string so that all the same characters are K distance
apart. If not possible print -1.
Round D BR :
1. Given two arrays sort the first array in the order of numbers given in the second array. For

361
Chapter 140. Set 139

the numbers that do not appear in the second array, sort according to face value. Discussed
methods and codes. He always pushed to optimize the code.
This was followed by discussion on sorting techniques, there comparisons. In the end he
asked a few questions from OS mainly the scheduling algorithms.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-139/

362
Chapter 141

Set 140 (Experienced for SDE)

Amazon interview Experience | Set 140 (Experienced for SDE) - GeeksforGeeks


Hi, Recently i had interviews with Amazon.
1st Round (Telephonic):
1. Given an integer array and a constant number X, print all pair of number in the array
whose product is equal to X.
follow ups: how will you do in O(n)? how will you handle duplicate pairs?
Code was required on collabedit.

http://stackoverflow.com/questions/3757393/given-a-number-p-find-two-elements-in-array-
whose-product-p
2. He asked do I know level order traversal of binary tree. He ask me to code then, he
changed the question and asked about spiral order traversal of binary Tree and asked me to
code it.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2nd Round (Telephonic):
1. In a BST two nodes were swapped. Given the pointer to root node find the two nodes
and rectify the tree. He asked the approach then asked me to code the same in collabedit.
https://www.geeksforgeeks.org/fix-two-swapped-nodes-of-bst/
2. Given an integer array, find and print three element in the array whose product is
maximum. Code was required.
http://www.technicalypto.com/2010/05/find-three-numbers-in-array-which-forms.html
3rd Round (face2face onsite)
1. Given a sorted array of n integers, count and display number of triplets such that a[i] <
a[j] < a[k] 0(n) time. Code was required.
2. In a given string some of the characters are replaced by question mark, and you can replace
question mark with any character. Given such a string find total number of palindrome
that can created. String contains only [a-z] characters and question marks can also be only
replaced by [a-z]. Example: Input String: String str=”a??a” Output: 26

363
Chapter 141. Set 140 (Experienced for SDE)

3. Given a binary tree all the leaf nodes in the form of a doubly linked list. Find the height

of the tree.
4th Round (Hiring Manager Round):
Detailed discussion about previous company work?
Why I want to leave my previous employer?
Why Amazon?
What if I don’t like the work?
What are challenges I have faced in my work, how I resolved it?
Weakness and strength?
What does router do, what is static routing? Given a routing table, how would you decrease
the time taken by router to decide to which router packet must be forwarded?
Details of algorithm that could be implemented and discussion time and space complexities.
5Th Round (Face2Face Onsite):
1. Given N sorted LinkList of different length, merge them into a single sorted link list.
Pseudo code was required.
2. Given a number d and size of array N. Print all combination of element in the array such
that first element of array is d and next element in the array can be +1 or -1 the previous
element in the array. Code was required.

E.g. Input: d=4 N=3


Output:
4 3 2
4 3 4
4 5 4
4 5 6

3. What is LRU and implementation of lru? Write pseudo code for the same.
I would like to thanks GeeksforGeeks for providing us such a learning platform.
All Practice Problems for Amazon !

364
Chapter 141. Set 140 (Experienced for SDE)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-140-experienced-sde/

365
Chapter 142

Set 141 (For SDE1)

Amazon interview Experience | Set 141 (For SDE1) - GeeksforGeeks


Online written
20MCQS + 2 coding question in hacker rank
1. Find the pattern in string (Use Kmp)
2. Rotate matrix by 90.
See in this round your code should pass all the test cases given
Telephonic round
Find the loop in linked list and also given the starting node from where the loop starts.
Print the tree in zig zag traversal
They have share the http://collabedit.com/ link, where i was writing the code.
Solution should be optimized.
Face 2 face Interview at Hyderabad(4 rounds)
1. You have given n point in a coordinate system.What you have to do is to find minimum
k distance point from origin.
Sol i have given the solution using insertion sort .i have taken a array of size n and while
calculating the distance, entering the distance in the array in sorted fashion.
second solution i have given using heap, storing the first k distance in heap, then iterating
the n-k element.
2. Print the tree in zig-zag traversal
3. U have given large stream of m size and you have size of n window . you have to find the
k minimum in each window . we are shifting the window by one at every iteration.
sol: I have used self balancing tree.First i have entered n element in tree and do in order
traversal upto k to find k minimum element.Now shift the window by one .Now we to remove
first element(logn time req) and insert the new element(logn time). Initially i was thinking
for solution using big extra space which was not accepted by the interviewer. Assume for
every question they asked what if you have 10 million data so your approach will fail if you
have taken extra o(n) space.Code should be scalable enough
4. N process can write at time in buffer and n process can read through buffer.Design a
system for read and write.

366
Chapter 142. Set 141 (For SDE1)

5. words are coming through a stream , u have to halt the problem when first repeated
words appear.
Used trie data structure.
6. N words are given.u have one source word and one destination word .u have reach to
destination in minimum edit with the constraint that intermediate word should be from
the words given.i have given the solution using graph and used BFS traversal .complexity
discussion
7. what happen when u hit url .I have tried to explain it using Django, he is expecting
something from domain name server. Be prepared
Complexity concept should be clear(Recursive+iterative both)
Other than this a lot of question on my company project and my performance rating. expe-
rience of professional life.
Should know each and every single word of resume.
Good luck
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-141-sde1/

367
Chapter 143

Set 142 (Off-Campus for SDE-1)

Amazon interview Experience | Set 142 (Off-Campus for SDE-1) - GeeksforGeeks


Round 1: Telephonic
Q1. Implement some functionalities of Minesweeper like connected component search and
game termination check etc.
Q2. Linked list random pointer question.
https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
Q3. Given a matrix of 0s and 1s find the row that contains maximum number of 1s.
Q4. Given a node in a binary tree, find all the nodes which are at distance K from it. Root
node is also given.
Next day, I got the call for onsite interviews.
Round 2: Onsite round by SDE – 1
Q1. Given very large number of empty crates of varying sizes, we need to find the best fit
crate for the given item and allocate it. Need to design a data structure for this scenario.
Operations involved:

1. Insert a crate
2. Search the best fit crate
3. Delete the crate after allocating it.

e.g. 3 crates of weight 10, 20 and 30 are there. An item of size 15 appears then we’ll allocate
crate of size 20 and delete it.
Sol. Use binary search tree (balanced using red-black criteria or any) and implement ceil
function.
All operations will be O (log(n)).
Q2. Optimize above data structure for weekends where amazon have lots of crates but very
less search operations.

368
Chapter 143. Set 142 (Off-Campus for SDE-1)

Q3. Given a function boolisValidWord(string str) you need to check whether a string is a
proper string or not. E.g. iloveicecream is valid : I love ice cream.
Round 3: Manager of some other Team
Deep discussion on projects.
In one project I used EC2 service so he asked me many details and why I preferred EC2
over other possible options.
Buy and sell stock question.
https://www.geeksforgeeks.org/stock-buy-sell/
https://www.geeksforgeeks.org/connect-nodes-at-same-level/
General discussion on virtual memory.
Round 4: 2 SDE-1s
Q1. Given matrix of 1s and 0s where 0 is water and 1 is land. Find number of islands.
Q2. Give the size of all islands in above question.
Q3. https://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/
Round 5: Dev Manager, 6yrs exp. (May be bar raiser round still I am not sure :P)
Q1. We started our discussion for very general problem where we have a long stream of
characters and we need to extract all the patters from that stream. There can be integers,
fractions, words or anything.
I explained the entire process which is used in lexical analysis phase of compiler design where
we give regular expressions and finally they are converted to NFAs and finally a single DFA.
Then a discussion went on how we’ll implement this system from scratch.
There are many algorithms for converting regular expressions to NFAs and finally DFAs and
some general discussion over Natural Language Processing.
http://algs4.cs.princeton.edu/54regexp/
Q2. Given M sorted linked lists of each of size N, we need to merge them to single linked
list of size M x N using no extra space.
Next day I got the call that they would like to extend me the offer for SDE-1 profile.
Important Tips:

1. Prepare data structures thoroughly.


2. Less efficient solution is much better than no solution.
3. Adopt incremental approach for problem solving.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-142-campus-sde-1/

369
Chapter 144

Set 143 (Off-Campus for SDE-1)

Amazon Interview Experience | Set 143 (Off-Campus for SDE-1) - GeeksforGeeks


Experience: 5 months
F2F: 1st round
1. Tell me about your college project.
2. Write a Code to check if linked list is a palindrome without using extra space.
3. Write a Code to print zizzag traversal of tree.
F2F: 2nd round
1. Tell me about your college project.
2. Tell me about your current project.
3. Nodes of a binary tree are randomly inserted in to an array Write a Code to tell the
index in array where root of tree is present.
4. Given an array whose size is <=10^8 and each element of an array is in the range 10^-
18 to 10^+18 Write a Code to find the largest subset of consecutive integers. F2F: 3rd
round(Hiring manager)
1. Deep discussion about my current project i am working on.
2. Discussion on my college project and how its useful for company like Amazon.
3. write a code to insert an element in sorted circular linked list.
4. write a code to find the nth Fibonacci number.
5. Design an linux file system.
6. Puzzle:Given 9 coins out of which 8 are of same weight except one and you are given
a Beam balance.you have to find that one coin in minimum no. of comparasions.
F2F: 4th round (senior Technical manager)
1. Deep Discussion on my current Project.he asked every minute detail of my project.
2. given an sorted array of integers and an element x write a code to find the number of
occurrences of x in array if not present return -1.
3. write a code to find the median in a running stream of integers.
4. Some behavioral questions like: why do you want to leave your previous company so
early?
Tell me some incidents when you haven’t meet the deadline and what do you have learn
from that? etc

370
Chapter 144. Set 143 (Off-Campus for SDE-1)

I would like to thanks GeeksforGeeks for providing us such a useful platform for interview
Preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-143-campus-sde-1/

371
Chapter 145

Set 144 (Off-Campus For


SDE-1)

Amazon Interview Experience | Set 144 (Off-Campus For SDE-1) - GeeksforGeeks


F2F Round 1:
1. Tell me about yourself.
2. Tell me about any challenging work you did in any of your past projects, why was it
challenging?
3. Given an unsorted array find maximum distance between two elements considering the
following condition:
Arr[i]https://www.geeksforgeeks.org/add-greater-values-every-node-given-bst/
After this was done, he asked to do it without using pointer variable parameter.
F2F Round 2:
1. Given an array of words, print all the words which are not anagram of any other word.
For example, Input {“cat”, “dog”, “tac”, “god”, ”rat”, ”toy”, “act”}, Output{“rat”, ”toy”}.
Variation of this https://www.geeksforgeeks.org/given-a-sequence-of-words-print-all-anagrams-together-set-2/
2. Given a tree connect all the nodes at same level in both directions
Variation of this https://www.geeksforgeeks.org/connect-nodes-at-same-level-with-o1-extra-
space/

F2F round 3(Hiring Manager):


1. Tell me about self.
2. Why do you want to change your current company? Why Amazon?
3. Tell me about your current Projects. What is your role? Tell me architecture of this
project?
4. Design a class to implement Linux File system.
5. Have you used twitter? Tell me working procedure of tiny URL.
6. How facebook works for following:
What data structure will you use to store friends and friends of friends?
Design structure for friends list, friend request sent list, received friend request list, store
message, notification etc.

372
Chapter 145. Set 144 (Off-Campus For SDE-1)

7. What happens when we type www.amazon.in ?


8. How does DNS work, what protocol does it use DNS what is difference between UDP in
TCP. Which protocol will you use when I will ask to design DNS
9. Insert a node in linked list in sorted order; again modify the same code to work for
circular linked list.

F2F round 4(Senior Technical Manager):


1. Tell me about yourself.
2. Why do you want to change in your current company. Give two reasons why do you want
join Amazon.
3. Deep Discussion on Projects I have worked on, Challenging part in these projects, why
was it challenging?
4. Tell me a situation where you did not complete your work in given time.
5. Have you made any mistake any time in your project and what was its impact on projects?
6. Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of
first 1
Ex 0000111 o/p : 4
Again he modified it . Do the same if stream is coming 00000000……..1111111……
In less than O(N)
Thanks to GeeksforGeeks for providing such a wonderful resource for interview preparation.
All Practice Problems for Amazon !
Group Anagrams Together

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-144-campus-sde-1/

373
Chapter 146

Set 145 (Off-Campus)

Amazon Interview Experience | Set 145 (Off-Campus) - GeeksforGeeks


I have been working with Amazon for last 2 years and 4 months. Here, is my interview
experience when I was the interviewee:
Off Campus Drive (DCE) – 2012
Written test:
1-> WAP to merge two linked lists like:

list1: 1->2->3->4
list2: 5->6->7
o/p list: 1->5->2->6->3->7->4

2-> Given two trees T1 and T2. WAP to check whether T1 is a subtree of T2 or T2 is a
subtree of T1
3-> WAP to find maximum sum sub-matrix from a give matrix.
Round 1:
1->You are given a sorted but rotated array of integer like: 6 7 8 1 2 3 4 5
You have to search an element…
I answered with an O(logn) solution…
then he asked me to write the code…
2->What is the diameter of a tree?
I answered…
then he asked me to write the complete code…
3->He asked me a design problem “you have to design a class “DeckofCards”…with 2 oper-
ations: 1:Shuffle 2:Pick”
Pick would pick a random card from the deck and Shuffle will shuffle the cards and give you
back the deck of cards.

374
Chapter 146. Set 145 (Off-Campus)

I answered with 2 options 1.LinkedList 2:Array…then there was a discussion around 15 mins
over both the solutions…
Round 2:(I guess it was the bar-raiser round)
1-> My Introduction and My Projects (all 1 by 1 except the last)
2-> How to compute all possible solution of A^3+B^3=C^3, where A,B,C belongs to (0 to
N)?
Write code…
3-> How to compute A^n where n<1 million Write code... 4-> A tough “matrix with a
mask” problem…I took around 20 mins to solve it.
5-> Why Amazon, what is scalability and questions from my answers…like how would you
manage millions of requests…
Round 3:
1-> You r given a matrix of 0s and 1s. WAP that check if an element is 0 or not and places
zeros to all the col and row of that element.

eg: i/p: 1 1 1 1 o/p : 1 1 0 1


1 1 0 1 0 0 0 0
1 1 1 1 1 1 0 1
1 1 1 1 1 1 0 1

2-> How to find a largest palindrome from a given string? Write code….
3-> How many Data Structures you have implemented by yourself?
4-> Given some words(written in lexical order) of some unknown language…You have to
find lexical ordering of all the alphabets…
Like in english lexical ordering is A B C…Z
Round 4
Forth round was just related to my projects and subjects…(Paging, Deadlock, Trashing,
JAVA and C, Synchronization, etc) + 1 final algo question “How to find all anagrams in a
dictionary” Solution was in O(1)..
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-145-campus/

375
Chapter 147

Set 146

Amazon Interview Questions | Set 146 - GeeksforGeeks


I am happy to contribute to a community that helped me learn so much � This mail contains
info about a recent interview I had with Amazon.
Question 1
Problem statement: Given an Amazon reviews paragraph containing several words, find
the minimum distance between two given words.
Example: Following is a hypothetical paragraph in an amazon review –
“Amazon is the best company to work for. The amazon is a beautiful forest.”
Find the minimum distance between ‘Amazon’ and ‘The’
Given: You are given the position of each word in the paragraph. Meaning, you know that
word ‘Amazon’ occurs at positions 1 and 10, and ‘The’ occurs at 3 and 9. You do not have
to parse the paragraph to gather this info.
Sub questions :
*Which data structure will you use to store the given info?
*Compute the minimum distance in the most efficient way.
*Give a working code for the same.
Question 2
Problem statement: In a binary tree, a chain can be defined as sum of length of the left
node series, right node series, and 1. Find the length of longest chain in the tree.
Example: Refer to the image given below –
Chain length of node 1 = 3 + 2 + 1 = {count of 3 corresponds to node 2 , node 4, node 8 ;
count of 2 corresponds to node 3, node 7 ; 1 corresponds to node 1 itself}
Similarly, chain length of node 2 = 2 + 1 + 1
The max chain length here is of node 1 which is 5. So, the output should be 5.

376
Chapter 147. Set 146

Sub questions:
* Provide a solution, optimize it, give a working code or pseudo code or an algorithm for
the same.
Question 1: Given two valid dictionary words, find the minimum number of steps required
to transform first word to second word. Following are the transformation rules –
1. You can, in a single step, change a single letter in the word.
2. Each transition should result in a valid word. Assume you have been provided a helper
function boolean isValid (String word) which tells you if a word is valid or not.
3. This must be done with minimum transitions.
Example: Transform CAT to TOY. One of the several possible transformations is CAT ->
CAR -> TAR -> TOR -> TOY
Question 2 : Assume you have been given a binary tree such that the angle between
horizontal and the line joining node to it’s left child (or right child) is 45 degree. This
essentially means node 5 and 6 in the tree figure above collapse into a single node. A
vertical for a tree is defined as shown in the figure below. Given a binary tree of the kind
defined above, find the number of verticals that can be drawn.
Example: Refer to the diagram below to get an idea on verticals.

377
Chapter 147. Set 146

?
Sub questions:
* Provide a solution and also provide a working code for the same.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-questions-set-146/

378
Chapter 148

Set 147

Amazon Interview Questions | Set 147 - GeeksforGeeks


Written round:
1- Given a sorted array.Make a balanced binary tree from this array.
2- A row and column wise 2d sorted array is given which only contains 0s and 1s in each
row. Find the row which is having maximum number of ones.
3- Find the next greater elements in array.
Face to Face 1
1- Given a row and column wise 2d sorted array. FInd an elements in it.
2- Given a row and column wise 2d sorted array.Find the kth element in this array.
3. Given a tree T1 and T2.Find whether T2 is subtree of T1 or not.If not return -1.
Face to Face 2
1. Given a 2D rectangle.In this rectangle there is some blocked areas which are shown in
shaded part.Find the area which is left.Ex-like in this image one unbounded area is T1 and
second is T2.You have to find both areas differently and print it. Hint-Take each block as
1*1 and apply dfs for all blocks.

379
Chapter 148. Set 147

2. A big unsorted array of numbers are given.Each number is big of almost 10bits.How to
sort these numbers?
Ans-Counting sort
3- An Adjacency matrix is given which is represented by 2d array.and each field is having
cost associated.You are also given source and destination points.Find the maximum cost to
reach from source to destination.
Face to Face 3
1. Discussion on work in my current company.
2. What is memory corruption,stack overflow,memory not available.
3. what is difference between multiprocessing and multithreading? Do all threads of one
process is having there own code,bss,stack and heap or it is common for all.
4. what is Tail recursion.How tail recursion works.
5. Can we overload a function by only changing its return type?
6. How virtual table works and lots of c++ concepts.
Face to Face 4 (With Manager)
1. Tell me about yourself.
2. What is the most challenging condition you have tackled in your life.
3. What you will do if you have conflict with your manager.
4. Guys this question brainf**cked me.The question was based on “20 question game”.I
never played this game. This was the actual question-

380
Chapter 148. Set 147

Given a set of words like Modi,MJ,Obama,Hillary Clinton.We need to create a intelligent


computer game so that it will popup minimum questions to find out the answer the player
thought. For ex- If give user choices to chose any word from Modi,MJ,Obama,Hillary Clin-
ton.Now computer will show popup from any of the tags.Like if user chose Modi then in
this case computer should ask minimum questions to find out what will be the guess.so in
this case computer only askd “PM” tag and computer will show the popup “Modi”.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-questions-set-147/

381
Chapter 149

Set 148

Amazon Interview Experience | Set 148 - GeeksforGeeks


Round 1:
1. Incoming stream of characters () defines an onion of depth 1, (()) of 2. Find all onions
with their in an incoming stream of characters. Discuss complexity.
Stream can be (()) () )) ((( (
2. Biggest challenge faced / where you innovated?
Resume Project:
i. Demonstrate High Level Design
3. Parking Lot Problem A, B , C lots with different car sizes. Efficient way of allocating
available slot.
A: Maintain linked list of available slots. Complexity discussion.
Round 2:
1. Matrix of 1s and 0s. 1s are sorted in beginning of each row. Find
an efficient way of finding the row with maximum 0s in it.
A: Find row which has lowest sum. Complexity discussion.

e.g.
1 1 1 0 0 0
1 1 0 0 0 0
1 1 1 1 1 1
1 1 1 0 0 0
1 1 1 1 0 0

2. How to find two sets(of size m,n) are dis-joint(have no elements common) efficiently
A: Use hash map. Complexity is O(n) in worst case.
Follow up Q: How are hash maps stored in memory?
All Practice Problems for Amazon !

382
Chapter 149. Set 148

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-148/

383
Chapter 150

Set 149 (On-Campus for


Internship)

Amazon Interview Experience | Set 149 (On-Campus for Internship) - GeeksforGeeks


Round 1 (Online):
It had 20 MCQs and 2 coding questions for 90 minutes. Questions were from Oper-
ating Systems, Data structures, Aptitude etc. Most of them were exactly same as
on www.geeksquiz.com.
In MCQs there was – 0.25 marking for every wrong answer and +1 for right answer. Coding
questions were of 10 marks each.
Coding Questions:
Q1. Find the first non-repeating character in a string.
Q2. You are given a phone keypad like following diagram, where each character corresponds
to a digit mentioned in the same box.

384
Chapter 150. Set 149 (On-Campus for Internship)

You are given n strings and you have to find their decimal representation. You have to print
the string and corresponding decimal representation in descending order. For example, if
you are given “amazon” then its corresponding decimal notation will be 262966. If more
than one strings have same decimal notation then you have to print them in the order in
which input is given. The given string consists of lower case alphabets only.

Test Case 1:
5
Amazon
Microsoft
Facebook
Aa
Bb

Output:
642767638 microsoft
32232665 facebook
262966 amazon
22 aa
22 bb

Round 2 (Face to Face):


Q1. Given a linked list, write a function to reverse every k nodes.

385
Chapter 150. Set 149 (On-Campus for Internship)

Example:
Inputs: 1->2->3->4->5->6->7->8 and k = 3
Output: 3->2->1->6->5->4->8->7

Inputs: 1->2->3->4->5->6->7->80 and k = 5


Output: 5->4->3->2->1->8->7->6

Q2. Given an array arr[] of integers, find out the maximum difference between any two
elements such that larger element appears after the smaller number in arr[]. Print the
indices of the two elements also.
Example: If array is [2, 3, 10, 6, 4, 8, 1] then returned value should be 8 (difference between
10 and 2). If array is [ 7, 9, 5, 6, 3, 2 ] then returned value should be 2 (difference between
7 and 9).
Round 3 (Face to Face):

There was brief introduction. Then he asked some questions from my resume. He asked me
to tell about a project which I loved the most and felt proud after doing it successfully. He
was interested in knowing the details of the implementation in that project.
After that there were 2 coding questions:
Q1. Given a string, find the longest substring without repeating characters. For example, the
longest substrings without repeating characters for “ABDEFGABEF” are “BDEFGA” and
“DEFGAB”.
Q2. Given a log file of page visits of a website by different users for a day.
Entry in the log file is like this:
User 1 visited Page 4
User 3 visited Page 2
User 7 visited Page 9
.
.
.
Design an efficient data structure which supports queries like the following:
Which page was visited by exactly 2 users in day?
Which page was visited by only one user exactly 2 times in a day?
Which page was visited by ‘User 3? more than 5 times in a day?
In 2nd and 3rd round, we had to write code on paper.
The overall interview experience was quite good. They wanted the most optimal solutions
and gave hints to think in that direction.
I was finally selected �
Tips:

1. First explain the approach, then start coding.


2. Try to interact with the interviewer while coding on paper. They don’t want to get
bored while interviewing.

386
Chapter 150. Set 149 (On-Campus for Internship)

3. In case of any doubt, clarify it asap.


4. Never ignore the hints given by the interviewer.
5. Be 100% honest.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-149-campus-internship/

387
Chapter 151

Set 150 (SDE1 for 1 Year


Experienced)

Amazon Interview Experience | Set 150 (SDE1 for 1 Year Experienced) - GeeksforGeeks
Telephonic:
1. http://www.geeksforgeeks.org/write-c-code-to-determine-if-two-trees-are-identical/
2. http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/
Round 1
1. https://www.geeksforgeeks.org/print-left-view-binary-tree/

2. http://www.geeksforgeeks.org/find-a-peak-in-a-given-array/
Round 2

1. http://www.geeksforgeeks.org/find-number-of-islands/ (all 8 corners)


2. Dont remember
Round 3
1.word frequency of a stream of words (no code required, explain trie method)
2.code to count no of words in a stream of characters
Round 4
1. https://www.geeksforgeeks.org/next-greater-element/ (use stacks)
2. http://www.geeksforgeeks.org/array-rotation/
Time and space complexity must for all questions
Start from brute force and go to optimized solution.
All edge cases are to be covered in code?

388
Chapter 151. Set 150 (SDE1 for 1 Year Experienced)

Think out loud all the time (so that even when questions are easy they will catch your
thinking with greater importance)
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-150-sde1-1-year-experienced/

389
Chapter 152

Set 151 (For SDE)

Amazon Interview Experience | Set 151 (For SDE) - GeeksforGeeks


Online Round
1. Convert Binary tree to linked list.
2. Rotate a matrix by 90 degree.
There were 2 more questions. But I forgot what were they?
Telephonic Interview
Overview of my resume, current role responsibilities and asked to explain internship project
in brief.
1. What is the definition of tree ?
2. What are the differences between graph and tree?
3. When can you say a graph to be a tree?
4. Write a program to show whether a graph is a tree or not using adjacency matrix.
Its always good to ask questions at the end. It shows our interest towards the company.
F2F 1
Overview of current job responsibilities and internship project.
1. Convert a tree to a sum tree.

Example :
1 27
/ \ / \
2 3 -------> 9 13
/ \ / \ / \ / \
4 5 6 7 0 0 0 0

Always take care of all the corner cases


2. Print a pascal tree .
3. Given a 2D matrix sorted row wise and column wise . Print the matrix in sorted way.
(Can be done using Min Heap).

390
Chapter 152. Set 151 (For SDE)

For all the questions, complexity of the program was asked and was being asked to improve
both time and space complexity.
F2F 2
Many questions regarding my current project, tools and technology I am working on.
1. Convert a binary tree to a sum tree . Here he had a new meaning of sum tree.
Example :

Example :
1 1
/ \ / \
2 3 -------> 2 5
/ \ / \ / \ / \
4 5 6 7 4 9 15 22

(I did it with Level Order Traversal) (Complete working code was required)
2. Given an array of integers. Find the largest 3 element. (Can be done using Max Heap in
less time complexity)
F2F 3
Lots of questions on my current work and tools which I was using.
Why do I want to leave my current company on such a short interval of 5 months.
Why Amazon ?
What inspires you to join Amazon? Why dream company ?
1. Connect Sibling pointers. I gave a Level Order Traversal solution. He asked to do it
in O(1) space complexity. I explained the approach but messed up In writing the working
code for that.
2. Explain the approach of LRU cache and implement using object oriented language.
F2F 4
Why Amazon?
Why do you want to leave your current company in such a short interval?
Did u ask your current company to provide that type of work as u r looking in Amazon?
1. Design a system for finding the costliest element always whenever we pick up an element
from a box.(concept of Max Heap)
2. A stream of data is coming. Maintain records in a page and mechanism to see previous
and next page. (Concept of Doubly Linked List)
(It is always advisable to ask questions in design questions. The interviewers expect that
we will be asking questions for clarification)
What is thread?
What is the meaning of memory leakage?
Followed by many OS questions but I forgot.
In every round , after each question , complexity of the algorithm was asked. Its good to
ask questions to get more clarification about the question.
I want to thank the entire team of geeksforgeeks. It is a great portal and it helped me a lot
in preparing for Amazon interview.
Reference – GeeksForGeeks and Cracking The Coding Interview
All Practice Problems for Amazon !

391
Chapter 152. Set 151 (For SDE)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-151-sde/

392
Chapter 153

Set 152 (Kindle Team SDE-1 )

Amazon Interview Experience | Set 152 (Kindle Team SDE-1 ) - GeeksforGeeks


Recently I have participated in Amazon SDE interview for Chennai location Kindle team.
Kindle team has arrived Bangalore location to take drive.
I have given 8 rounds
Questions- Answers are as below
R-1) Written Test 1 :
Three codes were asked :
1) Find whether given LinkedList is Palindrome or not
2) Find Whether given Binary Tree is Binary Search Tree or not
Code : www.gohired.in/2014/07/check-binary-tree-is-binary-search-tree.html
3) Create Regular expression and String Matching program for ? and *, where. * means
any null or character may appear instead *. and ? means one or more previous character
may appear in string.
example
input :
AM*AZO?N*, AMAZON
AM*AZO?N*, ABAZOO
Both are matching as per rules of ? and *.
After removing several candidates from process they conducted second round written.
R-2 ) Written Test 2 :
1) Stoke prices are given in array. Find for which duration I can buy and sell Shares to get
maximum profit.
We need to first explain our method and then star writing code.
– After this round some 20 candidates left.
R-3) Face to Face Round 1 :

393
Chapter 153. Set 152 (Kindle Team SDE-1 )

They discussed for all this 4 questions and why I choose to write this answer, some modifi-
cation in question to see whether u can think more in deep , or several conditions changed,
and they asked to redesign/rewrite answer.
R-4) Face to Face Round 2 :
Q1) Class diagram of one system ( don’t remember question)
Q2) Find Leader in Array ( Leader means an element which is higher than all number which
are indexed higher than element )
Solution Traverse array from behind to find such elements (simple method)
Q3) K sorted Linked Lists are given sort them in one ( write sudeo code )
Then he told me to give logic to solve question without using auxiliary array ( result array
)
I did with in-place method, searching and storing nodes in one linkedlist only.
R-5) Face to Face Round 3 :
Only One question was asked : Rotate Array “D”times.
Different strategies discueed, He was impressed with my another method to find new array
location based upon array size N and D.
R-6) Face to Face Round 4 :
Questions were from different topics like
-OS fundamentals
like fork, child process creation and output if I use fork().
What is deadlock, write sample C code to create deadlock.
What is mutex, etc.
SQL Fundamentals.
Data Structure used in Query,
Sample Query like finding Manger’s name and Fundamentals of join
-Other General Quesions
How Google Search engine works. Where Query goes their server, data storing etc
What happens when you click on website address.
-Design GAME.
GAME is like two players are fighting and ( kind of street fighter ) and design class diagrams
and methods for this GAME, I can think any functionalists(like health, power, help from
friend, etc ) any extra thing apart from which he mentioned.
– API is given, and this API servers different clients,
Now one client has requirement so that functionality changes, but other clients dont need
such functionality, how will you design your system.
– OOPS fundamentals were discussed like
Static, Class can be protected or not, overloading and overriding difference and implemen-
tation of them,
Software patters discussed like Factory and Abstract Factory
Singleton and how to implement it.

394
Chapter 153. Set 152 (Kindle Team SDE-1 )

Last Question was, If I want to store student data such that some students took Physics,
some took Chemistry and some took both. I want to know all details of students, mark,
name etc also. which way I’ll implement this system, which Data Structure will be used,
and which design pattern.
After All this round I was told to go home and Hiring Manager Round will be taken onsite
at Chennai, I was told.
for One month my rounds were not scheduled.
One fine day I got change to give Project Manager round over phone ( they said Senior
Manager will take onsite round and then HR round will be there)
Round 7) Hiring Manager Round.
Over call he asked me first question
Q1) Array is given which is of 0 and 1, all connected 1 forms island.
Find largest size island in given Array,
I have provided working code, He then asked me to optimize and again writing code.
Q2) Design LRU system. I have explained this
and also class diagram and pseudo working code was submitted.
Again for 20 days I didnt got call from HR and when I used to mail him, He simply replied
that my candidature is on hold as Senior Manager is not free to take my next round.
And Today Again I got call that I am rejected. because Hiring Manager is not convinced
from my approach in round,
I still don’t know what went wrong as both code given to HM were working.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-152-kindle-team-sde-1/

395
Chapter 154

Set 152

Amazon Interview Experience | Set 152 - GeeksforGeeks


Amazon written round – Time 1 hour.
1. Given an array of 0s and 1s, find the position of 0 to be replaced with 1 to get longest
continuous sequence of 1s.

Eg: Array- 1,1,0,0,1,0,1,1,1,0,1,1,1


Output - index 9
Assuming array index starts from 0.

2. Given an unsorted array, find the k smallest elements

Array {9, 5, 1, 4, 13, 6}


k = 3
Output: 1, 4, 5

3. Find the minimum distance between any 2 given nodes in a tree.

396
Chapter 154. Set 152

Minimum distance between 2 and 11 is 3


2–>5–>6–>11
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-152/

397
Chapter 155

Set 153 (For SDE1)

Amazon Interview Experience | Set 153 (For SDE1) - GeeksforGeeks


Recently I had interview with amazon.com for SDE1 position for 1+ year experience. It
was kindle team.
Round 1: 1 hour – written test at amazon office.
Q1. Given two link list that represents no. write a program to add two given two link list
and return new link list that represents sum of no. represented by given two link lists.
Q2. Given a string, write a program to find longest length palindrome from that given
string. You can swap the characters of given string.
Q3. https://www.geeksforgeeks.org/count-possible-decodings-given-digit-sequence/

Round 2: 1 hour – with SDE1


Q1. find longest common prefix of given set of strings.
Q2. Check whether given link list represents palindrome.
Q3. Given sorted array, write program to generate balanced binary search tree from given
array.
Round 3: 2.5 hour – with SDE1 + SDE2
Q1. Count no. of inversion in a given array.
Q2. In a party there are total n persons are there. every person is having one gift with him.
Every person will give his gift to another such that every person at the end has exactly one
gift. Any one can give his gift to anyone. say 5 people (A,B,C,D,E).
A–>D
D–>C
C–>E
B–>A
E–>B
write a program to generate a random sequence. for every run, code should generate different
sequence with equal probability. lots of discussion was there on various approaches. finally

398
Chapter 155. Set 153 (For SDE1)

with the help of interviewer i wrote O(n) time solution with O(1) space. Hint: selection sort
Round 4: 1.5 hour – with SDE2
Q1. Given a file having many words. Given K, find the words appearing >=K times. Lots
of discussion was there, discussed many approaches.
Q2. Design data structure that supports insert(), remove(), find-max(), delete-max() opera-
tions. All operations should run in O(1) time. Lots of discussion was there, discussed many
approaches.
Q3. Given two link-list that represents polynomial. Write program to multiply both poly-
nomial , return result as new link-list.
Q4. Write program to find max size BST from given binary tree. Algorithm and full
working code was required for all the problems. Discussed space and time complexity of
every problem.
Still hiring manager round and senior manager rounds are there. Once completed i will post
Tips: Discuss various approaches with interviewer. Try to interact continuously with in-
terviewer. they were very friendly during interview.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-153-sde1/

399
Chapter 156

Set 154 (For SDE2)

Amazon Interview Experience | Set 154 (For SDE2) - GeeksforGeeks


Round 1:
1. Print level order traversal of binary tree in iterative & recursive way.
Print each level in next line. –> I used 2 variables for this.
2. convert HEAD -> TAIL and print all words in successful transformation path.
constraints: Only one character can be changed at a time.
Transformed words should be valid. It can be checked using dictionary.
Round 2:
1. Check if tree T1 is a subset of tree T2.
2. find Kth minimum element in a row-wise and column-wise sorted 2-d array.
Round 3:
1. Project Role and related discussion
2. Find distance between two nodes in a binary tree.
Round 4:
1. Design an Email client. should be having all features of email-client.
2. Transfer one file data from one PC to another PC. To transfer data some network entity
is being used which cost some value. You need to reduce this cost of transferring the data.
—> I used compression technique to replace repetitive data with some key on first PC and
put it back on another PC.
3. How smart mobile/tv apps gets updated
4. Project role.
Round 5 (Hiring Manager):
1. Project Role deeply.
2. Any critical problem you have faced.
3. C++ -> polymorphism, abstract class, abstraction, overloading, compiler given default
n copy constructor.
4. Spiral matrix puzzle.
All Practice Problems for Amazon !

400
Chapter 156. Set 154 (For SDE2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-154-sde2/

401
Chapter 157

Set 155 (On-Campus)

Amazon Interview Experience | Set 155 (On-Campus) - GeeksforGeeks


Recently Amazon came to our campus as a part of our campus recruitment.
Online Round:
1) Given a linked list of zeros and ones, sort the list.
2) You are given three numbers. Each number is represented by a linked list. Write a
function that returns sum list.
Example: 1->2->3 + 2->1->3 + 3->2->1 = 6->5->7.
This was conducted on hacker rank. Test duration was 1.5 hrs
There were around 22 MCQs related to OS, OOPs C Input/Output questions. GeeksQuiz
is sufficient to answer these questions.
They shortlisted 25 people for the interviews.
There were 4 technical rounds in total. Every round is an elimination round. In each round
interviewer asks you to explain the algorithm as well as implement it on the paper.
First Round:
Started off with a basic “Tell me about yourself” question. This round is just to check if
you really are capable. He asked me three questions and asked me to implement all of them
on paper.
1) You are given an array and a number c. Ouput all pairs a, b whose sum is equal to c.
O(n) is expected.
2) You are given a number represented by a linked list add one to it.
I told him the obvious reversing the list and add one to it. But he wanted me to do it
without reversing and using recursion.
3) You are given a sorted array, find majority element in it. If there is no such element
output -1. You have to do it in single o(logn) operation.
Extension to the third question: What if the array is not sorted? Provide an o(n) solution.
Second round:

402
Chapter 157. Set 155 (On-Campus)

This was for about 2 hours. Although there were only two questions but the interviewer is
checking if we have enough knowledge on all the data structures.
1) You are given a long array and window size w. You can only view elements that are
currently in the window. Window starts at the extreme left and moves one position at a
time to the right. You are required to output minimum numbers in the current window.
All the possible approaches were discussed. Starting from brute force, o(nw) to o(nlogw)
using heaps, BSTs. He asked me to implement them. But he was not satisfied with o(nlogw)
solution. He wanted me to give a o(n) solution. Finally after few hints I’ve solved it using
doubly linked lists.
2) You are given a binary tree. Print the vertical order traversal starting from the root
element.
Third Round:
Started off with the question “Explain one project of yours”. Few technical questions were
asked on the project.
Few questions on OS, Multithreading vs Multiprocessing were asked. Also he asked me
to tell if I have implemented any program that used multi threading. Few questions on
semaphores and mutexes were asked.
Only one coding question in this round
1) You are given a very large binary tree, return the root node of the largest BST in the
given tree. Single traversal solution is expected. Implementing it on paper was little difficult
than expected.
Fourth Round:
By this time, job offer was almost confirm.
He asked questions on my projects. He asked me to implement few algorithms from my
project on a paper.
1) Implement a graph and one graph traversal using oops.
2) Given an immutable(non editable) linked list and a number k, remove all occurrences of
the number in the list.
Few questions on OOPs were asked.
They gave me the result after 20 minutes �
I would like to thank geeksforgeeks which helped me enormously in getting placed.
Majority Element
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-155-campus/

403
Chapter 158

Set 156 (On-Campus)

Amazon Interview Experience | Set 156 (On-Campus) - GeeksforGeeks


Written Round:
There were 21 mcqs and 2 coding questions hosted on hackkerank.
Time: 1 hr 30 mns.
The mcqs were from c, c++, os, networks for example
1. LDAP stands for ?
2. 2^30+2^30+2^30+2^30 = ?
3. Given three process P, Q, R . P requests resources A, B, C, Q requests B, C, D and R
requests C, D, A which of the following orders is deadlock free
4. Given a postfix expresion find the value of expresion
5. Which of the following is the inorder traversal for the given pre order traversal
6 Question based on the precedence order of operators
Coding questions:
1) Given a graph. Find if a cycle exists and print the nodes in the cycle. If multiple cycles
exists print the cycle starting from the lowest index
2) Given a string S and a string T, count the number of distinct subsequences of T in S.
S = “rabbbit”, T = “rabbit”
3
Interview 1:
1) Find the diameter in given tree which can start at any node and can end
at any node and should have only single turn.

10
/ \
5 8
5-10-8 has two turns
10
/ \

404
Chapter 158. Set 156 (On-Campus)

45 56
/ \ \
10 20 45

10-45-10-56-45 has 1 turn


20-45-10-56 has 2 turns
2) https://www.geeksforgeeks.org/find-number-of-islands/
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-156-campus/

405
Chapter 159

Set 157 (On-Campus)

Amazon Interview Experience | Set 157 (On-Campus) - GeeksforGeeks


Online Round
Initially a test was conducted on hackerrank on the basis of which students were shortlisted.
The test contained 22 questions, 20 Gate like MCQ’s and 2 Programming questions. The
MCQ’s were on OS(page replacement policies), output, trees etc.
The programming questions are as follows :
1) https://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/
10 Bonus marks were there if one could solve in O(n) time.
2) Given 3 numbers in the form of linked list. Give the sum of the 3 numbers as another
linked list.
Example: 1->2->3 + 2->1->3 + 3->2->1 = 6->5->7.
A slight variation to this question :
https://www.geeksforgeeks.org/sum-of-two-linked-lists/
They shortlisted around 30 people for the interviews. Since some of them got placed on day
1, they were extending the shortlist on realtime also. There were 4 rounds in total. Every
round was an elimination round. In each round, I was asked to explain the algorithm as
well as implement it on
the paper. Every interview started with the typical “tell me about yourself” ice-breaker.
Round 1 (Technical)
1) Finding LCA in BST.
https://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/
2) Finding LCA in Binary tree
https://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/
3) https://www.geeksforgeeks.org/a-product-array-puzzle/
Round 2 (Technical)
1) https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
2) You are given ‘n’ appointments. Each appointment contains startime and endtime. You

406
Chapter 159. Set 157 (On-Campus)

have to return all conflicting appointments.


3) Some basic discussion on memoization and dynamic programming.
Round 3 (HR + Technical)
1) Tell me about yourself.
2) Why Amazon?
3) Where do you see yourself after 3 years.
4) What are your weaknessess? I said one, he asked me one more?
5) Lot of questions on my intership project and on the technology used in it, challenges that
I faced, best thing I liked about the technology etc etc.
6) Some question on my hobbies.
7) Finding LCA of a tree whose nodes has only parent pointers.
8) Implement a stack from 2 queues.
9) Implement a queue from 2 stacks.
10) Design classes for a Snake and Ladder game. The focus was on OOPS concepts.
11) Some more question on my projects and resume that I don’t remember.
Round 4 (Technical)
1) Rotating an array. (All approaches)
https://www.geeksforgeeks.org/program-for-array-rotation-continued-reversal-algorithm/
https://www.geeksforgeeks.org/array-rotation/
2) https://www.geeksforgeeks.org/search-an-element-i n-a-sorted-and-pivoted-array/
In all the interviews, the approach is seen, so taking out loud what you are thinking is must.
Its good to point out the problem(s) that are the crux of the question and solving it would
lead to the final solution. The interviewers are always very helpful, they give hints whenever
required. Just being calm, composed and patient during & between interviews and studying
geeksforgeeks will do the work.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-157-campus/

407
Chapter 160

Set 158 (Off-Campus)

Amazon Interview Experience | Set 158 (Off-Campus) - GeeksforGeeks


Recently I appeared in for off-campus Amazon Interviews for SDE position and here is my
experience.
Round 1: 1 hour written test
Q1. Given a string you need to print all possible strings that can be made by placing spaces
(zero or one) in between them. For example : ABC -> A BC, AB C, ABC, A B C
Q2. Given a tree where there are three pointers (left_pointer, right_pointer and a
next_right_pointer). Left and right pointers are set like that of any general binary tree.
We were asked to set the next_right_pointer to the next node in the level order traversal
for the same level. This implies means for the last node in every level it will be null for rest
it will be pointer to the next node in level order traversal.
Round 2: 1 hour technical
Q1. There is a 12 km road and a contractor who is in-charge of repairing it. Contractor
updates you about the work which is done in patches. Like “Road between 3.2 km to 7.9 km
repaired ”, “Road between 1.21 km to 3.2 km repaired”. You have a manager who enquires
about the longest continuous patch so far. It was a long discussion and I gave solution in
O(nlogn) where n is the number of updates by the contractor.
Q2. Several Questions were asked from my project.
Round 3: 1 hours 20 mins
Q1. There are billions and billions of stars and at any point of time you need to tell the
closest million to earth. In what way I should take input for the stars and what all do I
need to represent one. I used heap of a million size. Then he also asked about the different
approach when I can’t use so much of physical memory for heap.
Q2. Implementation of Least Recently Used Cache. I started with O(n) solution using
queue and ended up with O(1) solution using heap and doubly linked list.
Q3. Basically it was from snakes and ladders game. There is n x n matrix and you are at
starting position. What is the no. of ways to reach n-square position if your next move will

408
Chapter 160. Set 158 (Off-Campus)

be dependent on number on dice? You have been given information about ladders (there
are no snakes J ). I used DP.
There were few others that we didn’t discuss as I told him that I know solution to them.
Round 4: 1 hour
Q1. Write an efficient program to count number tree structures that can be made using n
number of nodes.
Basically T(n)=summation (T(i) * T(n-i-1)). I used DP as there are a lot of sub-problems
used again and again. O(n2) .
Q2. There are n nuts and n bolts represented in two different arrays and a function
is_fit(nut_i, bolt_j) which returns 0 if its perfectly fit, 1 if it’s a tight fit and -1 if its
loose fit. I was asked to arrange them so that every nut fits perfectly with the bolt in the
same position (there is one nut for every bolt that fits perfectly). I suggested O(nlogn)
solution.
Q3. Find the kth largest element in a BST. Well that was easy J
We discussed about projects and he asked reasons for leaving present company.
Round 5: 1 hour hiring manager round
Most of the questions were behavioral questions like dealing with manager in case of conflicts,
reasons for leaving present company, why would you choose Amazon and not Flipkart if you
have offers from both, about my projects and contribution to present company.
Round 6: Technical + Behavioral
Q1. How to know the time between someone writes Amazon.com and the page appears
on his browser for a particular user. I impressed him by suggesting to use dummy request
packets after the page is loaded completely sending the time J.
Q2. He showed me the Amazon page they were working at that time and I asked me to
suggest 5 changes in 5 minutes.
Q3. https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations/
I messed up with the solution in the beginning but reached to solution eventually.
Many behavioral questions were asked too.
TIPS:
1. Don’t jump into solutions, ask about the type of input that is given and output that is
expected.
2. The interviewer always tries to take you to the most optimal solution so listen to what
all he says. Many a times they are big hints !!!
3.Be honest.
4. Keep believing that you will get the job J.
I would like to thank geeksforgeeks team for such an amazing platform to learn and discuss
with other geeks.
All Practice Problems for Amazon !

409
Chapter 160. Set 158 (Off-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-158-off-campus/

410
Chapter 161

Set 159 (Off-Campus)

Amazon Interview Experience | Set 159 (Off-Campus) - GeeksforGeeks


I recently got an offer from Amazon Delhi. Here goes my interview experience.
Telephonic Round
Q1. Find kth element from the end of a singly linked list.
Q2. Given an array (not sorted) of integers and a number S, find a pair in the array whose
sum is equal to S. I gave the sorting solution and was asked to write the code for the sorting
algorithm I used. I had used in-place merge sort.
F2F Delhi
1st round:
Q1. Detailed discussion on all possible data structures which can be used to implement
a set with no duplicates and which supports add, delete and find operations in minimum
space & time complexity. I suggested using hashing, BST or array. They asked me to give
an example of a hash function which supports uniform distribution but is not collision free.
Was asked to write codes for add, delete and find operations using BST.
2nd Round:
Q1. Rotate an image represented by a 2D matrix by 90 degree.
Q2. Given a singly linked list of 0s and 1s, sort it keeping the order intact. I gave O(N)
time and O(1) space complexity solution.
3rd Round:
Q1. Discussion on projects and previous work.
Q2. Given stock prices of several days, find the two days so that buying the stock on 1
and selling it on another gives the maximum profit. O(N) time and O(1) space soln was
expected.
Q3. Given a doubly linked list, reverse every 2 nodes. E.g. 1->2->3->4 will become 2->1-
>4->3
Q4. Several questions on OS, OOP, A few are what is segmentation fault, describe the
design patterns you know.
4th Round:
This round was Bar-raiser round. A bit tricky.

411
Chapter 161. Set 159 (Off-Campus)

Q1. Detailed discussion on projects, best project you have got, the most challenging work,
strengths, weaknesses etc.
Q2. Given a dump of items sold in a file (not organized), give the top n items sold. Eg. the
file looks like:
< item1 sold >
< item2 sold >
< item1 sold >
< item9 sold >
Also, there might be same items sold but they might have different names because of different
vendors. So you also need to count them together (Hint: Use ids of the items).
Hint: Use grep command to get the counts.
Q3. Collect email-ids of all the persons above 18 yrs in a city. He wanted to see my way of
thinking and how do I use software approach towards daily life problems.
Q4. There is a signal and two way traffic. Cars are coming @rate 10 cars/sec. Signal remains
green/red for 10 secs and when the signal is green, 10 cars/min can cross the signal. You
need to tell how many cars are in the line waiting behind the signal on both sides during a
particular time. Say you run the simulator at time 0, now after 1 hour you need to tell the
no. of cars waiting on both the sides.
I didn’t get selected after this but got a call after 1 month as they wanted to reconsider my
profile.
F2F Hyderabad
1st Round:
Q1. Some discussion on previous work.
Q2. Given a sorted array S of characters say S= {‘a’,’d’,’g’}, you need to find the insertion
point of a given character in it such that if it is less than ‘a’, insertion point is 0, if between
‘a’ and ‘d’, insertion point is 1 and if greater than ‘g’, again the insertion point should be 0.
O(log n) time soln was expected.
Q3. Given a complete binary tree, connect nodes at the same level without using any extra
space.
Q4. Given a dictionary of unknown language, you need to give the sorted sequence of
characters in it.
E.g.
Dictionary looks like:
ABCDE
CF
DG
so the output may look like: ABCDEFG
Hint: Topological sort
2nd Round:
Q1. Given two arrays S1 and S2 of characters. You need to find the smallest length of
substring in S1 which contains all the characters of S2. Characters need not be in the same
order as in S2. Characters might be repeating in S1.
Q2. Given a dictionary like text file, find n top occurring words in it i.e. n words whose
count is the maximum. Hint: Use Hashing and Min-Heap.
I would like to thank geeksforgeeks as it helped me a lot while preparing for the interviews.
All Practice Problems for Amazon !

412
Chapter 161. Set 159 (Off-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-159-off-campus/

413
Chapter 162

Set 160 (For SDE 2)

Amazon Interview Experience | Set 160 (For SDE 2) - GeeksforGeeks


Amazon sde2 experience:

Telephonic round :
Design a site similar to junglee.com. Assume you are given a crawler, design a distributed
system , what ds will you use , some basic api’s etc.
Onsite:
coding round 1:
1. zig zag traversal of binary tree O(n) algo
2. matrix question:
given matrix like :
abed
bcfe
abdd
….
find the longest path of consecutive alphabets given a starting alphabet. You can move in
all 8 directions. for eg. a->b(right)->c(down)->d(diagnal down)… len = 4 , find max such
len
coding round 2:
1. is binary tree balanced : O(n) time algo
2. given a pre and post order kindof a traversal (2 arrays) create an n-ary treee out of it
with struct of the form :

struct node {
int data;
struct node *child[MAX];

414
Chapter 162. Set 160 (For SDE 2)

int child_num;
}

did it using a hash table of linked lists and storing parents . Might be a btr way not sure.

design round + hiring mgr 3:


Design the most recently viewed item for amazon , say 15 most recently viewed item which
are scrollable for millions of products and users . scalable and extensible model. give apis ,
distributed systems, caching , reduce latency : critical
design round 4:
1. Give Object oriented design for the snake game (that was in old nokia phones) . only
class and obj diag was needed, no code/implementation. it should have extensibility to
accomodate different types of fruits, (eg one gives + 5 len + 10 pts) it should be scalable
to diff platforms
2. Give an architecture diagram with all entities and relationships of a multi user wysiwyg
editor . basically a web interface to multiple authors who can edit and store their docs
. multiple ppl should be able to save it at once . also ownership should be present for
documents.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-160-sde-2/

415
Chapter 163

Set 161 (Off Campus for SDE-1,


Bangalore)

Amazon Interview Experience | Set 161 (Off Campus for SDE-1, Bangalore) - GeeksforGeeks
Off campus- Delhi drive (SDE-1 Bangalore)
1st round: f2f
Tell me about yourself.
Most challenging task.
https://www.geeksforgeeks.org/connect-leaves-doubly-linked-list/
https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
Small modification in it. Parenthesis pairs are given in a separate list. You have to optimize
the problem by suggesting the method you will need to store the pairs.
2nd round: Hiring manager
What is the angle between hour and minute hand at 12:15. I said 90’ but corrected myself
immediately.
So he told me the importance that for huge no of clients this small mistake can create a
blunder.
He asked me a scenario where I faced this thing and thereby improved the time complexity.
Lot of behavioural questions like conflicts with manager, team collaboration etc.
3rd round: f2f
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
http://stackoverflow.com/questions/20026243/find-2-missing-numbers-in-an-array-of-integers-with-two-missing-va
He asked me if have heard of nut and bolt problem. I didn’t so he moved to next question.
Given an array. Find the maximum number of groups of size of 2 or 3 that can be formed
such that sum of the numbers in group is divisible by 3. No number can be reused.

416
Chapter 163. Set 161 (Off Campus for SDE-1, Bangalore)

4rd round: Bar raiser


Convert an integer to its roman. He asked me to consider cases with integers containing 4
and 9. I didn’t understand properly.
He asked me if I I did anything extraordinary apart from my daily work in the office and
what challenges I faced.
https://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/
He did not accept this solution and asked me to optimize. This round didn’t go well, so I
was not selected.

Tips: Solve all the data structures related problems from geeksforgeeks and start practicing
to write perfect code for any problem.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-161-off-campus-sde-1-banglore/

417
Chapter 164

Set 162

Amazon Interview Experience | Set 162 - GeeksforGeeks


Round 1:
Q-1: https://www.geeksforgeeks.org/dynamic-programming-set-32-word-break-problem/
Round 2:
Q-1: https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/
Q-2: Given a string of 0s and 1s, count the number of substring which start and end with
1.
I was rejected after round 2 because I did not do well in round 1, was put on hold.
Was called again
Round 1:
Q-1: https://www.geeksforgeeks.org/write-c-code-to-determine-if-two-trees-are-identical/
Q-2: https://www.geeksforgeeks.org/convert-an-arbitrary-binary-tree-to-a-tree-that-holds-children-sum-property/
Round 2:
Q-1: In a tennis tournament of N players every player plays with every other player.
The following condition always hold-
If player P1 has won the match with P2 and player P2 has won from P3, then Player P1
has also defeated P3.
Find winner of tournament in O(N) time and O(1) space. Find rank of players in O(NlogN)
time.
Q-2: Given N scientists and K black holes, each scientist can query on radius, size and
temperature of a black hole, what data structure would you use?
Following queries are important.
Which scientist had queried on which black hole.
What were the queries made by that scientist.

418
Chapter 164. Set 162

Round 3.
Q-1: https://www.geeksforgeeks.org/maximum-sum-path-across-two-arrays/
Q-2: https://www.geeksforgeeks.org/dice-throw-problem/
Round 4:
Discussion on current project in company and college problem.
Questions on OS.
Q-1: Given 2 files find common words.
Both files are too large to be loaded in memory.
Q-2: Point of inflexion in an infinite mathematical graph which is strictly increasing then
strictly decreasing. Simple binary search was not the solution.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-162/

419
Chapter 165

Set 163 (For SDE II)

Amazon Interview Experience | Set 163 (For SDE II) - GeeksforGeeks


Recently I attended amazon bangalore interview for SDE 2 position. All f2f and no
phone/written screening as i had attended one before and cleared those. Total 5 rounds
and below are the details.
1) Coding
Given 2 nodes in a binary tree, find the length of the path connecting them (standard)
2) Coding
Given an continuous input stream of characters, find a method to get the earliest/oldest non
repeated character at any time in O(1).(solved using a doubly linked list and array combo)
3) Hiring Manager
Questions regarding the past projects, challenges (Important! please search google for prepa-
ration grid and fill it up, be honest, be consize, your interviewer has gone through hundreds
of filmsy, shaky and all kinds of project descriptions and don’t think you can fool him.)
4) Design round
Design a system where a buyer puts a notification to the social networking site about his
transaction.
5) Bar raiser
Past project discussion, design a cab service system, how would you define the standerds to
be ahead of your customers, how to handle scalability issue.
Note:
Brush up coding style, you may know the logic, but don’t keep much hope if the code is
messy, lengthy and without boundary checks, practice writing code on paper which can run
without any modification.
Think loud, the interviewer is ready to help you, even to the extent of going into your code
and finding bugs, and that does not make you look bad.
Think all possible angles when designing. if the line goes down, if there’s a meteor hitting
the server, someone is using the design after 20 years, so what might happen. scalability

420
Chapter 165. Set 163 (For SDE II)

is important for amazon. Prepare your project details and think of your real fault, real
problems to tell the manager.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-163-sde-ii/

421
Chapter 166

Set 164 (For SDE I)

Amazon Interview Experience | Set 164 (For SDE I) - GeeksforGeeks


Applied for Chennai Kindle team, cleared few rounds but not happy with the overall in-
terview process. Contacted again by Hyderabad office and scheduled an interview, asked
me about my previous experience with Amazon. No telephonic, all F2F as I have already
cleared few rounds earlier.
Round 1
1. Questions on my project with previous employer
2. https://www.geeksforgeeks.org/add-two-numbers-without-using-arithmetic-operators/
3. Given an unsorted array of integers, assume the elements are inserted into BST. Search
for an element and print the path if found. If the element is left of previous in BST then
path variable is 1 else 0. Eg:

Input: Given array[] = {8, 2, 4, 9, 12, 3, 1}

422
Chapter 166. Set 164 (For SDE I)

Corresponding BST would be

Output: Search key = 3 should print “101”,


key = 11 shouldn’t print any.

Round 2
1. Count the decoding for a given digit string. Let say ‘A’ -> 1, B -> 2 and so on
Eg :

Input: digits[] = “123”


Output: 3 //”ABC”, “ LC” , “AW”

2. There is a printer printing characters continuously on paper, you need to cut the required
message character by character from the printed paper efficiently
Round 3
1. https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
2. Given a 2D matrix consists of only 0’s and 1’s find the longest diagonal of all 1’s
3. Optimization on above question with slight variations.

Round 4 (Bar Riser from US telephonic)


1. Given an array and an integer k, find the maximum for each and every contiguous sub
array of size k Eg:

423
Chapter 166. Set 164 (For SDE I)

Input: array[] = [1,2,3,4,5,6], k = 3


Output: 6, 9, 12, 15

2. https://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/ asked for minimum


instead of maximum
3. Given an array of positive integers, form a largest decimal number by concatenating
integers. Such that the largest number should be divided by 2, 3 and 5.
Final Round (Manager)
1. Given a BST and a node (say target), find K nearest neighbors (https://www.
geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/)
2. As my work with previous employer is very similar to the team I am interviewed for, not
much questions rather it was more like a discussion
Production level code on paper with all corner cases handled is expected in all rounds. The
interviewers especially Hyderabad team are very friendly and helpful, talk out loud, they
are ready to help and guide you to right direction.
Finally, I would like to thank GeeksforGeeks as it helped me a lot in cracking algorithm
questions. It’s a great portal, keep up the great work, cheers �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-164-sde/

424
Chapter 167

Set 165 (For SDE I)

Amazon Interview Experience | Set 165 (For SDE I) - GeeksforGeeks


Each of the rounds were of more than 1 hour and they mainly focused on logical thinking
and approach. DS and algorithms were the topics asked.
First round –
At first round, there were two interviewers. First, they asked about me. Why do you want
to leave your present company and join Amazon?
Then after brief discussion, he went on to questions.
There is a 2-d matrix with rows sorted. Convert it into 1-d sorted array. Also specify space
and time complexity.
Given two binary trees, check whether two trees are identical or not. Write working code
for it.
Using the previous solution, check whether one tree is subtree of another or not. Also specify
time complexity (Average and worst case) with proper code.
Second round –
General discussion about present company’s work.
Given a number of friends who has to give or take some amount of money from one another.
Design an algorithm by which the total cash flow among all the friends is minimized. Specify
the data structure which you will use and write the code for it.
Given an array, find the index of first occurrence of a number ‘x’. First, I gave O(n) solution,
after that he asked to optimize it and find it in less than O(n). There was long discussion
in this question.
Third Round –
General questions like – tell me about yourself.
What are your strengths?
Why Amazon?
Why do you want to leave your current company so soon?

425
Chapter 167. Set 165 (For SDE I)

Did you ever been in any kind of disagreement with your management?
Work in current company ?
Design snake and ladder game. What data structure would you use, with design was needed.
He then asked to optimize it further.
Given two linked list , find the sum of those linked list . With recursion and without
recursion. Lists may be same or different lengths. Complete code was needed with space
and time complexity.
Fourth round –
General discussion and Introduction. Work about current company?
What is the major challenging task that you have faced till date? Then more discussions
and questions on the task.
Any disagreement with manager and any good or innovative idea that you have come up
with and worked on it?
One technical question – Given a word and the dictionary, find all the anagrams of the
particular word present in dictionary (That are valid words). Propose the data structure
you have used and time complexity of the solution.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-165-sde/

426
Chapter 168

Set 166 (For SDE I)

Amazon Interview Experience | Set 166 (For SDE I) - GeeksforGeeks


Telephonic 1:-
1. Light is falling on a tree from left side you have to find all the nodes on which this light
will fall.
2. Check whether a link list is palindrome or not.
3. Minimum Edit Distance.

Telephonic 2:-
1. ZigZag traversal of tree
2. Pair wise elements which sum to a given value
3. Intersection point of two linklists
F2F round 1:-
1. Maximum in sliding window
F2F round 2:-
1. You have a list of program files, how will you decide which file to compile first and which
later, what data structure you will use for storing these dependencies.
2. Best Fit
3. You have been given time intervals of a you tube video watched mostly. You have to find
out the most watched time interval, so that you can put an ad in between that section.
F2F round 3:-
1. Find a number in an infinite stream of sorted numbers.
2. What happens when a computer starts?
3. Write a hashing function for storing stream of words.

427
Chapter 168. Set 166 (For SDE I)

F2F round 4:-


1. A lot about my projects, what is the best thing you have done so far.
2. Populate sibling pointers in a tree.
3. TCP/IP, http/https, how to establish a secure connection or send an encrypted data,
PPP protocol.
4. Virtual memory.
Thanks a lot geeksforgeeks for helping me a lot in my interview preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-166-sde/

428
Chapter 169

Set 167 (SDE I for 1 year 6


months experience)

Amazon Interview Experience | Set 167 (SDE I for 1 year 6 months experience) - Geeks-
forGeeks
Round1: Online Coding Round
There were 4 coding question. Was asked to answer 2 out of 4.
1) Given a list of N coins, their values (V1, V2, … , VN), and the total sum S. Find the
minimum number of coins the sum of which is S (we can use as many coins of one type as
we want), or report that it’s not possible to select coins in such a way that they sum up to
S.
Example: Given coins with values 1, 3, and 5.
And the sum S is 11.
Output: 3, 2 coins of 3 and 1 coin of 5.
2) Given two rectangles, find if the given two rectangles overlap or not
3) Given two strings string1 and string2, find the smallest substring in string1 containing
all characters of string2 efficiently.
For Example:
Input string1: “this is a test string”
Input string2: “tist”
Output string: “t stri”
4) I don’t remember the question.
Round 2: F2F Technical (Hyd)
1) Print zig zag of tree
2) Longest Palindromic subsequence of a given string.
Was asked to write complete code.

Round3: F2F Technical (hyd)


1) Lots of Question on my projects.

429
Chapter 169. Set 167 (SDE I for 1 year 6 months experience)

Since my project relates to multiprocessing, lots of questions were asked why multiprocess-
ing/why not multithreading, difference, what is thread/process, producer consumer problem,
etc.
2) Design a file structure in Linux.
3) I was asked to write flawless code for inserting an element in sorted linked list which
should cover all corner cases.

Round3: F2F Technical (hyd)


1) Given an array of words, print all anagrams together.
2) You have an array which the ith value is the price of a given stock on day. You can buy
only one share of the stock and sell one. Design an algo to find the best times to buy and
sell. Also he asked me to give start date and end date.
3) Graph problem:
Critical node: If a node reaches another node only through one node.
Eg: A-C-B and A-E-B are critical nodes. (A reach B through one node which is C or E)
If A reaches B through more than one node, then they are not critical nodes.
1) A-C-B
A-D-E-B (A reach B thro c which might lead to critical node but A has another path to B
thro D and E, so they are not critical nodes).
2) X-Y-Z
X-A-Z (X and Z are critical nodes)
Now find all critical nodes.

Round4: F2F Technical (hyd)


1) Many questions on my projects. He asked me to write pseudo code for one of my project.
2) Outlook:
A server receives meeting objects from multiple senders. Meeting object contains meeting
time, sent time, recipient(s), sender id,etc. When recipient comes and checks the server,
he/she should get requests based on meeting time and not based on sent time. Many
discussions on space complexity and time complexity.
Eg:

12 PM From: A To: B,C,D meeting time: 4 PM meeting Id: 1


12.30 PM from: A To C,D meeting time : 2 PM meeting Id:2
1:PM From B To: C meeting time: 1.30PM meeting Id:3

When C requests the server, C should get ID3 as 1st, ID2 as 2nd and ID1 as 3rd meeting.
3) Many behavioural questions.
I would like to thank geeksforgeeks for helping me to crack the interview.
All Practice Problems for Amazon !

430
Chapter 169. Set 167 (SDE I for 1 year 6 months experience)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-167-sde-1-year-6-months-experience/

431
Chapter 170

Set 168

Amazon Interview Experience | Set 168 - GeeksforGeeks


Interview 1:
The interviewer asked me about my resume which was followed by the following ques-
tion.Given a function mapped from integers to real numbers, which strictly increases upto
a certain point say A and strictly decreases after it, write a function to find this point.The
solution was a simple binary search, the trick being to reach the other side of the peak. This
can be achieved iteratively increasing ‘x’ and checking for a downward slope condition. The
step could be constant, but an exponential increase would let to the point faster. I was
asked to prove this by giving the recurrence relation and hence showing the complexity. I
was further asked to code the entire algorithm using any language of my choice where I used
c.

Interview 2
The interviewer asked me about networks in relation to sockets and ports when he saw an
academic project that was mentioned in my resume.
The interview questions were as follows:
1) Given a binary tree where value at each node is a single digit, find the sum of numbers
generated by each root to leaf path. He also asked to code the primary function for the
same. I couldn’t find the exact question on geeksforgeeks, but this one is close enough
https://www.geeksforgeeks.org/find-the-maximum-sum-path-in-a-binary-tree/
2) Given a numpad such that every number is associated with a set of letters, give all
combinations of strings that could be formed given a string of numbers. He also asked to
code the primary function for the same.
Solution: https://www.geeksforgeeks.org/find-possible-words-phone-digits/

Interview 3
1) Given an array of integers, find a subset of numbers from this array such that, after
negating the elements of this set, the total sum of all elements would be equal to zero.
I could not solve the problem and he moved on to the next one after giving me a hint to
use Dynamic Programming

432
Chapter 170. Set 168

2) Given two sorted arrays find the median of the merged array without using extra space.
I gave an O(N) Solution and he asked me to give an O(log(N)) solution,which I gave after
I put in some thought
3) Print a binary tree in a zigzag order level wise. I gave an implementation using a doubly
ended queue, he wasn’t satisfied as this would lead to extra space complexity for storing
the levels in the d-queue. He was pleased when I decided to use 2 queues for the same. He
further asked me to code it up
Interview 4
1) The interviewer asked me about the types of database I knew and elaborated a bit on
non-relational databases like mongodb and JSON.
2) Next, he asked me the need for indexing in databases and it’s implementation.
3) In an auctioning system, the bidder with the highest bid wins but charged at kth highest
price. Develop a system for it. Solved it using a hashmap. Was asked to write a code for
the same.
4) Given an array such that all elements except one are duplicate, find this element. He
tweaked the problem to add the condition that in stead of one there are 2 such elements. I
couldn’t arrive to a solution even after he gave me some hints. In the end he gave me the
answer but immediately said that it may not work. I realized why it did work and explained
the reason for the same.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-168/

433
Chapter 171

Set 169 (For SDE 2)

Amazon Interview Experience | Set 169 (For SDE 2) - GeeksforGeeks


Recently I was interviewed for the position of SDE 2 I have 4 years of work experience
.Following were the asked.
Note: For all of the question production level code was required.
Round 1:
1.Write a program to convert a integer to its form in a given language .
For example 112345 Could be one hundred twelve thousand three hundred forty five or One
lac twelve thousand three hundred forty five.
2.Find the top k frequent items in a stream of numbers Space O(k)
Round 2:
It was basically a design round .
1.Design a Chess board so that two players can play.Each of the play can make any warrior
move.Class Diagram and basic functions were asked to be written.
2.Design a key value pair storing system in a distributed system
Questions on types of caching in distributed systems , Sharding
How will you be handling scalability , failover and latency.
Round 3:
Given a 2 D array with m Entry points (which are on the edges) and n exit points which
are on the edges give the total number of paths that are possible .Complete production level
code was to be written

Round 4: Bar Raiser Round


1.given a large file with contents like
1.CAT
2.DOG
3.TAC
4.ACT
5.GOD

434
Chapter 171. Set 169 (For SDE 2)

6.ODG
Re-arrange it such that every line has the index of all of its anagrams
Eg Output
1.CAT 1,3,4
2.DOG 2,5,6
3.TAC 1,3,4
4.ACT 1,3,4
5.GOD 2,5,6
6.ODG 2,5,6
2. Given inorder and postorder traversal of a tree give the preorder traversal without creating
the tree.
Round 5 Hiring Manager Round
1.Nut and Bolts Problem
2.Given a million list of co-ordinates in the form of longitude and latitude just as Google
maps .How will you print closest k cities to a given location .
After that a few behavioural questions
I was not able to come up with a good answer for second question.
I thank geeksforgeeks for creating this amazing platform.Great job guys.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-169-sde-2/

435
Chapter 172

Set 170

Amazon Interview Experience | Set 170 - GeeksforGeeks


Round 1 – Telephonic
1. Find element in an array which have elements in first increasing and then decreasing
order. (code)
2. Find if two nodes in a tree are cousins or not. (code)
Round 2
1. Find sum of all numbers that are formed from root to leaf path (code) expected time
complexity O(n)
2. Zig-Zag level order traversal.
3. Preorder traversal without using recursion.
Other questions related to my work in my current company
Round 3
1. Grilled me about my current company and current work.
2. Print top view of a binary tree (code)
3. Why amazon?
Round 4
1. Find median of an unsorted array. (code)
2. General discussion on heaps
3. A stream of characters is coming, at any moment you have to tell ‘k’ elements closest to
a given number (code)
Round 5 (Bar raiser)
1. Design a system which would make a schedule for a user to complete a book in given
number of days. A pre condition is that the schedule for every day should end at the end
of some chapter.

436
Chapter 172. Set 170

Ex – 3 chapter with 10 pages each and user has to complete this book in 2 days, then the
schedule should be either be 2 chapters on first day and 1 chapter on second or 1 chapter
on first day and 2 chapters on second. (code)
2. Tell me about a time when you couldn’t implement the best solution because of a close
deadline.
3. What did you do about it afterwards.
4. General design pattern related questions like what if we use singleton design pattern for
question 1
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-170/

437
Chapter 173

Set 171

Amazon Interview Experience | Set 171 - GeeksforGeeks


Hi, I recently got an offer from Amazon, here is my interview experience:
Round-1: (Written)
Q-1: Search element in infinite sorted array.
Q-2: Fine LCA (lowest common ancestor) of given two nodes in Binary Tree. Handle
all corner cases like one element exists and other not. https://www.geeksforgeeks.org/
lowest-common-ancestor-binary-tree-set-1/
Q-3: Find next greater number with same digits. Handle corner cases. https://www.
geeksforgeeks.org/find-next-greater-number-set-digits/
Round-2: (F2F)
Q-1 : https://www.geeksforgeeks.org/median-of-stream-of-integers-running-integers/
Discussed corner cases. Proper code was required.
Q-2 : https://www.geeksforgeeks.org/clone-binary-tree-random-pointers/
Discussed different approaches. Proper code was required.
Round -3 (F2F)
Q-1: https://www.geeksforgeeks.org/dynamic-programming-set-32-word-break-problem/
I don’t have Idea about problem initially then he asked to make some test cases, some tricky
one. I gave recursive algorithm then, after this came on DP solution but time doesn’t permit
so moved to second question. Code was required.
Q-2: Given inference rules and some input tokens find all tokens which can be possible with
given rules. Example :
Rules :
AàB
BàD

438
Chapter 173. Set 171

CàE
DàF
Input Tokens :
1. A,C then all A,B,C,D,E,F are possible.
2. A then A,B,D,F are possible.
Ask me what data structure you will use, how processing will happen. Pseudo code was
required.
Round -4 (F2F)
Long discussion on my current work. Biggest challenge and how you solve it. Technology
challenge.
Q-1: Suppose you receive 10 million mails in 10 seconds. How will you process them and
find whatis problem to receive these many mails. Discussed different approaches.
Q-2: longest palindromic substring of given string. I gave DP solution, he ask me don’t use
DP. Proper code was required.
https://www.geeksforgeeks.org/longest-palindrome-substring-set-1/
Round-5 ( Telephonic)
Long discussion on my current work again, Challenges faced. What you did when some
mess-up happens and deadline is very strict. Conflict with manager.
Q-1 : Outlook:
A server receives meeting objects from multiple senders. Meeting object contains meeting
time, sent time, recipient(s), sender id,etc. When recipient comes and checks the server,
he/she should get requests based on meeting time and not based on sent time. Many
discussions on space complexity and time complexity.
Eg:

12 PM From: A To: B,C,D meeting time: 4 PM meeting Id: 1

12.30 PM from: A To C,D meeting time : 2 PM meeting Id:2

1:PM From B To: C meeting time: 1.30PM meeting Id:3

When C requests the server, C should get ID3 as 1st, ID2 as 2nd and ID1 as 3rd meeting.
Q-2 : https://www.geeksforgeeks.org/add-greater-values-every-node-given-bst/
I gave solution using temp array, then he ask me to do in constant space in single traversal.
Condition don’t use pointer for sum or call me reference. Proper code was required.
Tips: Be yourself . Practice writing code on paper. Never give up.
Thanks Geeksforgeeks for providing very good platform to well prepare. A knowledge
repository J

All Practice Problems for Amazon !

439
Chapter 173. Set 171

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-171/

440
Chapter 174

Set 173 (On-Campus)

Amazon Interview Experience | Set 173 (On-Campus) - GeeksforGeeks


Recently I appeared for Oncampus Amazon Interviews for SDE position and here is my
experience.
Round 1: 1.30 hour Online Written Test
It had 20 MCQ questions on C/C++ and 2 coding questions. The coding questions were:
Q1. You are given a string that represent an expression of digits and operands. Eg. 1+2*3
, 1-2+4. You need to evaluate the string or the expression. NO BODMAS is followed. If
the expression is of incorrect syntax return -1.
Test cases :
a) 1+2*3 will be evaluated to 9.
b) 4-2+6*3 will be evaluated to 24.
c) 1++2 will be evaluated to -1(INVALID).
Also, in the string spaces can occur. For that case we need to ignore the spaces. Like :- 1*2
-1 is equals to 1.
Q2. You are given an array of both negative and positive integers. You need to rearrange
the array such that positive and negative numbers alternate. Also, the order should be same
as previous array and only O(1) auxiliary space can be used and time complexity O(n).
eg. -2 3 4 5 -1 -6 7 9 1
result – 3 -2 4 -1 5 -6 7 9 1.
Round 2:
Q1. Given a Linked list , print yes if it is palindrome else print no.
Q2. Print the level order traversal of the binary tree in the spiral form.
Round 3(F2F):
Discussion about project.
Some question on DBMS, OS.
Q1: Maximum of all subarrays of size k(Expected Time Complexity O(N).
Input :

441
Chapter 174. Set 173 (On-Campus)

arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6}
k=3
Output :
3345556
Q2: Given Two sorted array of size size n each. Find the Kth largest element in these two
array (Expected Time Complexity Log(n))
Round 4(F2F)
Detail Discussion about project
Q1.website having several web-pages. And also there are lot many user who are accessing
the web-site.
say user 1 has access pattern : x->y->z->a->b->c->d->e->f
user 2 has access pattern : z->a->b->c->d
user 3 has access pattern : y->z->a->b->c->d
user 4 has access pattern : a->b->c->d
and list goes on for lot many users which are finite and numbered.
Now the question is we have to determine the top 3 most occurring k-Page-sequence.
for the above example result will be : (k=3) a->b->c , b->c->d , z->a->b.
Q2: Given two array , one of size m+n and contains m element and other position are empty
, 2nd array is of size n and contains n element.
both array are sorted , now merge the second array to first one such that the resultant array
is sorted. Expexte time complexity(m+n).
I would like to thanks geeksforgeeks for providing such a platform to learn algorithm and
data structures… � �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-173-campus/

442
Chapter 175

Set 174 (For SDE)

Amazon Interview Experience | Set 174 (For SDE) - GeeksforGeeks


Recently I went through Interviews for SDE position in Amazon Development Centre, Chen-
nai. Here is my Interview experience:
Telephonic round:
1) Given an array with lengths, you have to select 3 lengths (a, b and c) for a triangle such
that it satisfies condition a+b>c,b+c>a, a+c>b. Find the number of possible triangles can
be created from the given array.
ex: 3 5 6 9 10
(3,9,10), (3 5 6), (5 6 10), (5 9 10), (5 6 9), (6 9 10)
so number of possible triangles is 6
2) Count Inversions in an array
Inversion Count for an array indicates – how far (or close) the array is from being sorted.
If array is already sorted then inversion count is 0. If array is sorted in reverse order that
inversion count is the maximum.
Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j Example:
The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3).
In house Interview 1(F2F):
3)Next Greater Element
Given an array, print the Next Greater Element (NGE) for every element. The Next greater
Element for an element x is the first greater element on the right side of x in array. Elements
for which no greater element exist, consider next greater element as -1.
Examples:
a) For any array, rightmost element always has next greater element as -1.
b) For an array which is sorted in decreasing order, all elements have next greater element
as -1.
c) For the input array [4, 5, 2, 25}, the next greater elements for each element are as follows.

Element NGE
4 --> 5

443
Chapter 175. Set 174 (For SDE)

5 --> 25
2 --> 25
25 --> -1

d) For the input array [13, 7, 6, 12}, the next greater elements for each element are as
follows.

Element NGE
13 --> -1
7 --> 12
6 --> 12
12 --> -1

4)Sorted Array to Balanced BST


Given a sorted array. Write a function that creates a Balanced Binary Search Tree using
array elements.
Examples:

Input: Array {1, 2, 3}


Output: A Balanced BST
2
/ \
1 3

Input: Array {1, 2, 3, 4}


Output: A Balanced BST
3
/ \
2 4
/
1

Inhouse Interview 2(F2F):


5) Detect Cycle in a Directed Graph
Given a directed graph, check whether the graph contains a cycle or not. Your function
should return true if the given graph contains at least one cycle, else return false. For
example, the following graph contains three cycles 0->2->0, 0->1->2->0 and 3->3, so your
function must return true.
6) Convert a BST to a sorted circular doubly-linked list in-place.
Telephonic Round with Hiring Manager:
Introduction about me.
Then he asked about my college project. we discussed the OO design for the project.
Then he asked me about my current company’s latest Invention
Then he asked me about Virtual memory and some in depth discusion on that.

444
Chapter 175. Set 174 (For SDE)

Then he came to my current project I am working


Then he asked me why are you coming out of my current company??
Then he gave a question to solve.
7)Given an array A[] and a number x, check for pair in A[] with sum as x
Given an array A[] of n numbers and another number x, determines whether or not there
exist two elements in S whose sum is exactly x.
He asked about various possible solutions for the above one.
Bar raiser round(F2F):
8)Given a binary tree, find the diameter of the tree.
The diameter of a tree (sometimes called the width) is the number of nodes on the longest
path between two leaves in the tree.
After solving the above one, he added a constraint on the above problem: (i.e) To find the
diameter of the tree with atmost one turn
Examples of turns in tree:
In tree1-> start from 1 and there is a turn at root 2 towards right,
In tree2-> starts from 3 goes in left and there is a turn at 1 towards right ,
In tree3-> starts from 1 goes in right and there is a turn at 3 towards left,

2 3 1
/ \ / \
1 3 1 3
\ /
2 2

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-174-sde/

445
Chapter 176

Set 175 (For SDE)

Amazon Interview Experience | Set 175 (For SDE) - GeeksforGeeks


Here’s my interview experience for Amazon, Bangalore for SDE
Round 1 (F2F)
Q1.) Given a function rev(int i) which reverses the segment of array ar[] from 0-i, Implement
a function sort() using rev().
Q2.) Given an array ar[] of length ‘n’ and an integer ‘k’ such that k < n. You need to
maintain a window of size ’k’ starting from i=0 to i=k and print the MAX of that segment.
The window moves forward by 1 element. Round 2 (F2F)
Q1.) (Variant of Children-Sum Problem)
Given a tree, implement a function which replaces a node’s value with the sum of all its
childrens’ value, considering only those children whose value is less than than the main
node’s value.
Eg: input = 60->50->80->40 , output = 90->40->40->0
Q2.) There are millions of string in the database. How would you store them for efficient
searching. You also need to print all anagrams together many times, now how would you
store them and insert if a new string is added to database ?
Round 3 (F2F – Hiring Manager Round)
* Why are you leaving the company so early ?
* Discussions on project and current work in the previous company.
* Discussion on college projects.
* Design a game ‘fifteen’ – http://en.wikipedia.org/wiki/15_puzzle
Game me to write code of various moves, discussed optimization strategies and time-
complexity if computer is given to solve it.
* Behavioral questions.
Round 4 (Telephonic)
Q1.) Most challenging problem faced (obviously in projects), how you solved it.

446
Chapter 176. Set 175 (For SDE)

Q2.) Discussion on Design patterns.


Q3.) Design Uber – http://en.wikipedia.org/wiki/Uber_(company)
He was trying to judge what all aspects the person considers
Classes, Objects, search and booking cab algorithms, implementation and technology
Q4.) Extension of previous question – Write code to search nearest 10 cabs.
Code is required in all questions. Practice code on paper.
Thanks Geeksforgeeks for providing such a good platform to prepare.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-175-sde/

447
Chapter 177

Set 176 (For SDE 1)

Amazon Interview Experience | Set 176 (For SDE 1) - GeeksforGeeks


Telephonic Round 1:
1) You are given an integer array. Create a Binary Search Tree from it.
2) You are given a Binary Search Tree. Write an algorithm to print the Path Array of a
given key.
PATH ARRAY:
a) If the given key is not present in the tree than the Path Array is equal to “-1”
b) If the given key is present in the BST, path array tells you the path (in terms of left &
right direction) that you take from root to reach the given key. If you go towards right add
“0” to the path array and if you go towards left add “1” to Path Array.
Telephonic Round 2:
1) You are given an array as an input. The array is organized in such a way that its element
are arranged in increasing order up till a certain index and in decreasing order after that.
Write an algorithm to search an element in such a array.
https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/
Face To Face 1:
1) You are given two array of “n” length. First array contains the arrival time of various
trains on a particular station. Second array contains the departure time of those trains.
Write an algorithm to find out the minimum number of platforms that will be required to
accommodate all the trains.
https://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/
2) You are given a binary tree. A light source is placed on the right of the tree. Print the
list of all the nodes over which the light is falling directly.
Face To Face 2:
1) A new feature is to be implemented in Kindle. FEATURE : The user inputs the no.
of days in which he would like to complete a particular book and the Kindle will create a
reading plan for the user.
Write an algorithm which will output the reading plan to the user. The reading plan should
be created keeping in mind that the user would like to begin and end reading a particular
“chapter” of the book on the same day.

448
Chapter 177. Set 176 (For SDE 1)

2) Some general questions:


a) Tell a project where you had faced tight deadlines and you had to skip a few things.
b) How did you decide, which things should be skipped?
c) If given a chance to implement the same project again, how will you implement it?
I gave all the answers with respect to a college project.
Face To Face 3:
1) A very brief discussion of what my current responsibilities are. It was a 5-10 minutes
discussion only. I feel that the discussion was brief as my experience was just a little over 1
year.
2) Given a binary tree write an algorithm for spiral traversal of the tree.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
3) You have N documents, where N is very large. Each document has a set of words lets say
w1,w2..wm where m might differ for each document. Now you are given a list to K words
lets say q1,q2…qk.
Write an algorithm to print the list of document which have the K words in them.
This question required a number of hints. I finally came up with the solution of creating a
combined trie for all the documents. After listening to my solution he said that it was good
but could have been better with B-Tree. I told that as of now I am not able to memorize
the concept of B-Tree and he said he was satisfied with the trie solution that I had given.
Face To Face 4:
1)
a) What are various types of tree traversals and diff between them?
b) Which of the traversals would you require for creating the tree (unique) back?
2) You have a very large array, but the array can contain only three elements: 0,1& 2. Write
an algorithm to sort the array.
Count Sort was one option, but it didn’t strike to me at that point of time. So I came up
with a trivial algorithm which sorts by putting all the 2’s to the right and all the 0’s to the
left, 1’s get sorted by themselves.
For all the questions in all the interviews I was asked for the time complexity of the problems.
However they didn’t expected me to do some calculation and then come up with a very tight
bound solution. They just wanted a rough estimate of the time complexity of the solutions.
Allocated time for all the interviews was 1 hour.
I would like to thank GeeksForGeeks for helping me with the preparations.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-176-sde-1/

449
Chapter 178

Set 177 (First Round in Pool


Campus)

Amazon Interview Experience | Set 177 (First Round in Pool Campus) - GeeksforGeeks
Today Amazon Took a Pool campus drive, including our college and many other. In which
the First round was Online in our campus itself, those selected students would go for further
rounds in other campus.
The First Round Was very Standard, first we had to open its Hiring test portal, in which it
had 20 MCQ and 2 coding questions, which we had to complete in 1:30 Hrs.
MCQ:

• It had question from OS, DBMS, Algorithm, Infix, postfix


• OS basically from scheduling, and process management in UNIX
• DBMS questions some simple query in my SQL
• questions asking Complexity of some give Algo. number of swaps in Bubble sort, best
technique to sort partial sorted list etc
• finding output of prefix expression, given Postfix finding prefix of BST etc
• full form of LDAP, qustions including privileges of User, kernel in UNIX etc

Coding:
1: given 3 Numbers in Linked list, we had to return the Linked List of representing sum of
all three, covering all base and condition of addition.

eg: for addition of


234+993+1 :
input Linked Lists are: 4->3->2->NULL, 3->9->NULL, 1->NULL
output linked list : 8->2->2->1->NULL

2: Simple and same Vertical traversal of a BST as given in Geeksforgeeks.org


All Practice Problems for Amazon !

450
Chapter 178. Set 177 (First Round in Pool Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-177-first-round-pool-campus/

451
Chapter 179

Set 178 (For SDE-1)

Amazon Interview Experience | Set 178 (For SDE-1) - GeeksforGeeks


In-house interview with Amazon Bangalore for SDE 1. Here’s my experience.
Round 1:
My first round was the HM round because no other panel members were free.
1. Lots of questions my current project. Why I am looking for a job change.
2. Write a calculator web application just like the one that comes with MS windows.
Trick was to evaluate the expression according to the BODMAS
Lots of dicussion on different approach using 2 stacks, arrays, lists, Tree
with and without postfix conversion.
Asked to explain all the approach on the White Board.
Round 2:
1. Link all the level order nodes to makes a linked list with the first node of each level acting
as the root of that linklist.

10
/ \
6 17
/ / \
4 14 19
So the Linklist will be
10->null
6->17->null
4->14->19->null

Gave the answer using the 2 queue. (Level order transversal) with alternate queue for the
alternate level
Than interviewer asked to solve the problem without using any other data structure (No
stack or queue)

452
Chapter 179. Set 178 (For SDE-1)

2. Question on Baggage claim token generations.


You have three containers, small, medium and large. Passenger comes in, checkin the
luggage. You have to store the baggage in the appropriate container and generate a unique
token number. Then passenger should get back the bag using the same token number. Trick
was if small container is full store in medium if available or large. Now if the large bag comes
in and there is now a empty space in small, than move the small bag back to small & store
the large bag. How to generate the unique token number and move the baagage internally
without changing the token number?
Lookup should be in constant time complexity and insertion in minimum complexity.
It looks easy but kind of tricky if you start solving because token number shouldn’t get
changed if you move the baggage internally and space should not get wasted in the memory
if baggage is removed.
Round 3:
1. Find the size of the smallest substring in a given string that contains all the characters
in given set in any order.

Ex:
INPUT:
String: "abfugtabecddcca"
Character Set: a,b,c
Output: 4 ("abec")

2. Convert a sorted doubly linklist into Binary search tree (Inplace)


Round 4(Bar Raiser Round):
1. Again Lots of questions on current project. My contributions.
Most complicated problem I have ever encountered in my recent project and how I
solved it.
Subject I liked the most in the college and why and what I learnt from it.
In my previous rounds, which question I found the most difficult one and why?
If I will be given a chance to change any of the my answers to the questions asked in
previous round, what question it will be and why?
Was I satisfied with my interview.
Technical question:
Do a spiral transversal of a 2D matrix

Ex:
a b c d
l m n e
k p o f
j i h g

output: a b c d e f g h i j k l m n o p

Both iterative and recursive approach.


Lots of discussion on Complexity.

453
Chapter 179. Set 178 (For SDE-1)

Thank you geeksforgeeks for providing the awesome platform for preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-178-sde-1/

454
Chapter 180

Set 179 (For SDE-1)

Amazon Interview Experience | Set 179 (For SDE-1) - GeeksforGeeks


Telephonic
1) Given an array which has elements in increasing order first , and then decreasing, suggest
an algorithm for searching an element in it.
2) Check whether a given tree is a BST or not.
3) do not remember
F2F 1
1) Number of hops required to reach the end of an array , where the maximum hop is the
value at index.
Tweaked question after this, to reach any node.
2) print the path between any two given nodes in a binary tree
F2F2
1) Project and resume discussion.
Problems faced and how you approached them.
2) A large number of emails coming into the system, at any given time find the top k issues
being faced by the users. Problem reduced to find the top k trending words in a large file.
3) Implement a vector in c, using any available data structure
F2F3
1) Given a pre-order traversal of a binary tree represented by , I for internal node and L for
leaf, build the tree.
2) Find the next smallest element for all the elements in a given array.
F2F4
Started off with a lengthy discussion on current project, was asked to draw a schematic of
the same, and then was asked to discuss my roles and responsibilities as well as suggest
what improvements could be made to it.

455
Chapter 180. Set 179 (For SDE-1)

1) Given a 2-D array, in which all the elements are either 0’s or 1’s, and all the rows are
sorted, Give an algorithm for finding the row having the maximum number of 1’s. Was
asked to code and analyse time complexity as well.
2) There is a given set of colours , say [1-N]. Now , people are coming into a stadium wearing
t-shirts of any of these colors. Write an algorithm to find the first person to come in, to
have worn an unique color.
The question wasn’t clear to me at first, so after a few examples , got what he was trying
to ask.
For eg. Suppose we have colors R G B
and the stream of people are as,
GRBGGGG
the output should be R.
Hope this helps some people.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-179-for-sde-1/

456
Chapter 181

Set 180 (Telephonic Interview )

Amazon Interview Experience | Set 180 (Telephonic Interview ) - GeeksforGeeks


I had a telephonic interview. It was of 90 minutes.
Questions asked by me.
1. Tell me about yourself.
2. What was your college project as well as what type of platforms used?
3. What is TRIE?
4. Write the function for insert and search for TRIE?
5. DFS and BFS .
6. How to get the shortest path from (0 , 0) to (r , c) in a rectangular grid in which some
cells are blocked.
Overall awesome telephonic interview.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-180-telephonic-interview/

457
Chapter 182

Set 181 (For SDE 1)

Amazon Interview Experience | Set 181 (For SDE 1) - GeeksforGeeks


Recently I was interviewed by Amazon for SDE 1, here is my Experience. Hope this will
help others:
Written Round :
there where 3 coding question , out of which 2 where DS related and 3 rd one was Problem
solving
1. Count no of words in given string .
2. Find first non repeating character in a stream of characters
3. related to slot machine and its working
Interviews
F2F 1.
1. firstly some non technical questions where there , such as
tell me about yourself ,
Why Amazon etc
2. followed by 2 coding questions
1. Given a sorted dictionary of alien language , find order of characters.
2. find minimum number of characters needed to be added to the end of a string to
make it palindrome.
F2F 2.
was a senior guy ,
1.started with discussion on previous interview questions , as I had used DP in second
question so a brief discussion on DP , tried to test me that does I really know the concept
of DP.
2. asked few puzzles , One should be prepared for some out of box questions as they want
to check the thought process . even they change puzzles and try to get different solutions.
Think loud always.
F2F 3.
was also a senior guy,
1. Started with general induction and asked about till then my interview experience and

458
Chapter 182. Set 181 (For SDE 1)

related stuff.
2. Simple Matrix multiplication problem ,with only 2 double pointer are given , we need to
check sizes of both matrix , multiplication feasibility and then do multiplication .
3. Design Question from DataBase point of view , asked about table structure for the
problem and had a good discussion on it , concept such as normalisation was discussed .
Telephonic 4th
He was a very senior guy from different team ,
1. Started with general introduction followed by many Behavioural hr questions .
2. Followed by Design Question, a feature of Outlook
A Server receives meeting objects from multiple senders. Meeting object contains meeting
time, sent time, recipient(s), sender id,etc. When recipient comes and checks the server,
he/she should get requests based on meeting time and not based on sent time. Many
discussions on space complexity and time complexity.?Eg:
12 PM From: A To: B,C,D meeting time: 4 PM meeting Id: 1
12.30 PM from: A To C,D meeting time : 2 PM meeting Id:2
1:PM From B To: C meeting time: 1.30PM meeting Id:3
When C requests the server, C should get ID3 as 1st, ID2 as 2nd and ID1 as 3rd meeting.
Small set of Suggestions :
1. Practice writing code using pen and paper .
2. Try to be interactive as they are very much interested in candidate’s thought process ,
think loud , be confident .
3. Firstly explain the logic and when interviewer is satisfied then start coding .
4. Have few questions prepared for the interviewer as it shows interest of candidate towards
the company .Do proper home work about the company.
Thanks GeeksforGeeks for such a great content , Keep doing the great work �

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-181-for-sde-1/

459
Chapter 183

Set 182 (For SDET 1)

Amazon Interview Experience | Set 182 (For SDET 1) - GeeksforGeeks


Round 1: (Written Test)
1. Given a sorted array construct a Balanced Binary Search Tree.
2. Given a linked list, find whether linked list is palindrome or not without using any extra
space.
3. Given set of strings find longest common prefix. If no common prefix present print null
Example: {abcd, abbd, abdy, az}
Answer: a
Round 2: (F2F – Problem Solving)
1. Given sorted array of unique elements. Find an element which is having value equal to
its index.
{-4,-2,2,4,6,9}
Ans: 2
2. Given a brick of size 1 x 4, how many ways you can construct a wall of size N x 4
Round 3: (F2F – Data structures and Algorithms)
1. Give a binary tree, print all the nodes in spiral order with constant space
2. Give a binary tree and a light source fixed placed right side of the tree. Print all the
nodes where the light directly falls.
Refer : Right View of a binary tree.

3. Merge two sorted linked lists without using extra space


Round 4: (Telephonic – Hiring Manager from Seatle – All Questions on Testing
and Projects)
1. Tell me about yourself
2. Roles and responsibilities of your current role
3. How do you test a search box
4. Did you ever have a fight with developer over a defect? If you had how did you solved ?
5. Few behavioral questions

460
Chapter 183. Set 182 (For SDET 1)

Round 5: (F2F – Test Automation and Testing)


1. Design an automation framework
2. Given a function InsertNode() which inserts a node to a linked list. Write all scenario’s
to test the function.
Round 6: (F2F –Bar Raiser)
1. Tell me about yourself
2. Why Amazon
3. Hardest bug you found
4. Given an array of integers. Write a program to find interval with largest producing
maximum sum. You should print sum as well as first and last index of the interval.
5. Your strengths
6. Your weakness
Useful sources for Technical Preparation:
1. GeeksForGeeks
2. Data Structures and Algorithms Made Easy by NarasimhaKarumanchi
3. Data Strucutures videos by Prof Naveen Garg from IIT Delhi
Use Cracking the Coding Interview book by McDowell Lakmen for behavioral as well as
technical questions.
Tips:
1. Think loud in front of interviewer.
2. Never keep quiet during interview
3. Prepare well on the projects which you are currently working on.
4. Be honest in behavioral questions
The beautiful part of the entire interview process was in none of the interviewer looked at
my resume.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-182-for-sdet-1/

461
Chapter 184

Set 183 (SDE – New Grad


Position)

Amazon Interview Experience | Set 183 (SDE - New Grad Position) - GeeksforGeeks
Following is my experience. I hope it helps people out there, as I got help from other posts
here before my interview.
Duration: 4 hours
interviewer #1: 8 am – 9 am
Q1) tell me your interest
-> Big Data
Q2) what’s latest thing you follow in it
-> Apache Spark
Q3) What is it and explain
-> told the standard MapRed and Hadoop vs Spark
Q4) what more features
-> told graph processing and MLLIB
Q5) Actual question starts here, given the binary tree, how will you serialize and deserialize
it to the file?
->
answer1: Serialize => do in-order traversal and pre-order traversal and write it to a file
Deserialize => build the binary tree using pre-order and in-order traversal
he was not satisfied, gave me hint of no need to do complex in-order, pre-order thing
answer2: BFS clicked me, told him to do BFS and write to a file level wise
But he found a bug in deserialize method, I changed the serialize method for null
values to speial character in file
he was okay with it, and asked me to write a code for it
asked the complexity
told him, was not convinced wholly, then finally told him, was still not
left the room with think over it �

462
Chapter 184. Set 183 (SDE – New Grad Position)

interviewer #2: 9am – 10 am


Q1) bang on target, given 2 timeframes, check if they overlap
-> s1, e1, s2, e2
ep1 = epoch(s1),
ep2
ep3
ep4
if ep1 <= ep3 <= e2 OR ep3<= ep1 <= ep4: return T return F Q2) LCA in
doubly binary tree !!! -> I frowned, what is doubly binary tree!!
it’s just every node has access to the parent
but you need to find the LCA and you do not have access to root of tree!
some brainstorm, and I got it
what is time complexity:
worst case: O(n^2) in skewed tree
average case: was not sure, gave me hint, and I told him, was okay
told him the 1st way, was convinced but hinted me the better way
Got his hint, and gave the answer, was satisfied
Q3) given 2 strings, how would you find if they are anagrams of each other
-> solution 1: 2 hash ( was okay but asked the better way)
hinted me that no of characters are limited
solution 2: told him the way of count sort, i.e. use 2 count sort arrays
but he said no need of other array, you can do in single array
told him the way, was satisfied
Interviewer #3:
– started with his long intro
– asked mine, and then stopped me as I was talking at length
– asked me amour my search project
– asked me the basic design
– how did you deal with data when you cannot fit in memory
– how did you do intersection of posting lists
– what is time complexity
then asked me to design the chase game
stumbled like hell, i guess this is going to be my rejection factor
Interviewer #4: (manager) behavioral round
– gave his long intro
– asked about myself
– when did you feel that something could have been done in better way after delivering it in
project
– when did you perform best way, as in what did you come up with that other could not do
– when did you go out of the way i.e. against your managers, or higher authority and deliver
the best according to you
– asked the system architecture question: design the TINYURL system in terms of server
architecture i.e. HA, scalability and request processing

463
Chapter 184. Set 183 (SDE – New Grad Position)

– was satisfied, and left with good note.


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-183-sde-new-grad-position/

464
Chapter 185

Set 184 (Off Campus for SDE1)

Amazon Interview Experience | Set 184 (Off Campus for SDE1) - GeeksforGeeks
I interviewed with Amazon, Hyderabad. Interview was in October, 2014. I was 4 months
experienced, and was applying for SDE-1 position.
I had 4 interviews, and my experiences are as follows.
1st Round
Q1 – Clone a graph. ( Similar Question -> https://www.geeksforgeeks.org/clone-linked-list-next-arbit-pointer-set-2/)
Basically while cloning, when you create a new node in the cloned graph, have a hashmap
which maps the old node to new node.
So in the hashmap key = old node, value = new node.
Q2 – Given an array of numbers, for each number print the first number to it’s left which
is greater than the current number.

Example
Input -> 5,3,2,4,8,6
Output-> -1, 5,3,5,-1,8
Use stacks. Simple O(n) solution.

2nd Round
Q1 – Find the row number according to the excel nomenclature –> (the opposite of this,
https://www.geeksforgeeks.org/find-excel-column-name-given-number/)

i.e given Z, Output -> 26


Given AX, Output -> 50

Q2 – Find the number of islands in a 2d Array -> https://www.geeksforgeeks.org/


find-number-of-islands/
3rd Round(Hiring Manager)
Q1 – Given a number in words, print the number.

465
Chapter 185. Set 184 (Off Campus for SDE1)

Example 1) Input - "One Hundred and Five", Output should be "105"


Example 2) Input - "One Thousand and two hundred", Output should be "1200"
Example 3) Input - "Twelve hundred", Output should be "1200"
Example 4) Input - "Five Lacs", Output should be "500000"
Example 5) Input - "Five Hundred Thousand", Output should be "500000"

There were a lot of edge cases, and discussion with regards to this. ( I took a lot of time
and the manager did not seem to pleased. � )
Q2- In a sorted array, find two numbers who’s difference is k.

Given -> 1,2, 3,4,7,8,9,11 and k=7


Ouput -> 1,8 or 2,9, or 4,11 (Print any one)

https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/
A lot of questions as to Why Amazon, Why do you want to leave so early.
4th Round(Bar Raiser)
Q1 – Given a sorted array find a number. (Simple Binary Search)
Now consider repetitions and find the left most occurrence. (Binary Search to first find
number, then again Binary Search to find left most occurrence)
Similarly find the right most occurrence. (Binary Search to first find number, then again
Binary Search to find right most occurrence)
Now using the above two functions, find the number of times the element is present.
Note – Cases like where number is NOT present,
Q2- Assembly Line Scheduling. (Very Simple DP.)
https://www.geeksforgeeks.org/dynamic-programming-set-34-assembly-line-scheduling/
Result
After three weeks, I got a generic email saying that I could not clear it. I had a really
irresponsible recruiter who did not have the courtesy to give me a call and just convey some
feedback. Eventually, I think I took too much time with the first question in the manager
round.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-184-off-campus-for-sde1/

466
Chapter 186

Set 185 (For SDE1)

Amazon Interview Experience | Set 185 (For SDE1) - GeeksforGeeks


Hi, Recently i was interviewed for Amazon SDE-1 Position in Hyderabad.There a telephonic
round followed by 4 F2F rounds.
Telephonic Round:
1. Inserting an element into a BST
2. A array is increasing and then decreasing find the point where it stops increasing.
F2F Round 1:
1. Replace all the elements in the array with its next highest element to its right
Expected O(n) Solution.
2. Given a binary tree and a value k. A path is called heavy path if the sum of the elements
in the path (path from root to leaf) > k remove all the paths from the tree which are not
heavy i.e., tree should contain only heavy paths.
F2F Round 2:
1. Given a array find all the triplets which satisfy the triangle preoperty(sum of 2 sides
should be greater than third side)
Sol: sort then o(n^2 log(n)) using binary search.
2. Given a dependency where for example process p1,p2,p3
p1:{p2,p3}
p2:{p3}
p3:{}
This means p1 starts once p2 and p3 are complete
p2 starts p3 is complete
p3 can start as it does not have any dependence.
Figure out strategy to find the order of execution of processes.
Ans:Topological sorting.
F2F Round 3:
1. Design a stack with push pop and find min operations in o(1) time.
Ans:can be done using 2 Stacks

467
Chapter 186. Set 185 (For SDE1)

2. Given an input string and a dictionary of words, find out if the input string can be
segmented into a space-separated sequence of dictionary words.
Solution https://www.geeksforgeeks.org/dynamic-programming-set-32-word-break-problem/
F2F Round 4:
Discussion of projects and current work experience.
Diameter of a binary tree in o(n).
First devised o(n^2) then optimized to o(n)
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-185-for-sde1/

468
Chapter 187

Set 186 (For SDE1)

Amazon Interview Experience | Set 186 (For SDE1) - GeeksforGeeks


Hi, Recently I was interviewed for the SDE-I for Amazon, Chennai.
Round 1(Online Round):
1. Given two linked lists. Add them.
e.g 1–>2–>3
3–>4
Output: 1–>5–>7
2. Find if the binary tree has the given sum.
I cleared the online coding round and I was asked to come down for the face to face discus-
sions.

Round 2(F2F):
1. Find if the given binary tree is height balanced.

Round 3(F2F):
1. Find if the given tree is the subtree of the big tree.
2. Given a sorted matrix (row-wise and column wise) , find kth smallest element.
3. Given an array. Pop min element in O(1) time.
4. Implement increment operator for the array.

Round 4(F2F):
1. Print the level-order traversal from bottom to up in a given binary tree.
2. What is process and thread?
3. What is copy constructor?
4. Design parking lot.

Round 5(F2F) (Hiring manager round):


1. Questions on achievements, challenges faced, area of improvement.,etc.

469
Chapter 187. Set 186 (For SDE1)

2. Given a file with millions of URLs. Some URLs repeating , some unique. Find the first
unique URL.
Coding was required in each and every round. Think loud. Tell the interviewers what you
think. Give them different approaches. Be confident about your solution.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-186-for-sde1/

470
Chapter 188

Set 187 (For SDE1)

Amazon Interview Experience | Set 187 (For SDE1) - GeeksforGeeks


Hi, Recently i was interviewed for Amazon SDE-1 Position in Hyderabad.There a telephonic
round followed by 4 F2F rounds.
Telephonic Round:
1. Given a array find all the triplets which satisfy the triangle property(sum of 2 sides should
be greater than third side)
https://www.geeksforgeeks.org/find-number-of-triangles-possible/
2. Given a array find whether it is majority array or not.
Complexity: O(n) Space complexity O(1)
https://www.geeksforgeeks.org/majority-element/
F2F Round 1:
1. Given a dependency where for java packages p1,p2,p3
p1:{p2,p3}
p2:{p3}
p3:{}
This means p1 can be compiled when compilation of p2 and p3 done
p2 can compile when p3 is compiled
p3 can start as it does not have any dependence.
Figure out strategy to find the order of compilation of processes.
Ans:Topological sorting
2. Discussion on project
Asked all concept related to my final year project.
3. Current project in company
Challenges faced at company
2F Round 2:
1. Given a binary tree print its side view from left from bottom to top and right side view
as up to downward .
Eg. For image 1 output will be 3, 1, 2, 5, 6, 7, 8

471
Chapter 188. Set 187 (For SDE1)

and for Example 2( image 2) output should be C, B, A, D, F, I, L

2. Given a string find largest palindrome sub string in it.


I gave him https://www.geeksforgeeks.org/longest-palindromic-substring-set-2/ this answer
.
then he asked me using DP
https://www.geeksforgeeks.org/longest-palindrome-substring-set-1/
3. What is virtual memory?
4. What is paging in OS?
2F Round 3:
1. Why are you looking for change in 6 months of experience .
2. Discussion on how to send notification to friends when a user post on social network like
facebook
The discussion was on when to load friend list of user and he was expecting we should load
friend list when user login.
2F Round 4:
1. Discussion on current project challenges faced
Situation when you have to take decision in absence of your team lead/Manager
2. Why are you looking for change in 6 months of experience

472
Chapter 188. Set 187 (For SDE1)

3. Given a special binary tree structure given in image 3


A node have 3 node pointers left,right and next
Two adjacent node share there left and right as shown in tree
Give tree whose node are set with next pointer as null.
you have to set the next pointer as shown in the figure .
If any node is null then the next of its prev node should be next of that eg. a -> b -> c (a’s
next is b ,b’s next is c) if b is null then a’s next should be c.

4. What is virtual memory?


5. What is segmentation fault?
Note :- They expect fully working code in all round.
Tips:

473
Chapter 188. Set 187 (For SDE1)

1. Think loud they always support you


2. Ask for hint if not getting.
Majority Element
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-187-for-sde1/

474
Chapter 189

Set 188 (For SDE1)

Amazon Interview Experience | Set 188 (For SDE1) - GeeksforGeeks


Recently I am interviewed for Amazon SDE-1 position for Bangalore. There are 3 F2F
rounds followed by a telephonic round.
As it was a drive, they asked everyone to write code for these problems
1. https://www.geeksforgeeks.org/add-two-numbers-represented-by-linked-lists/
2. https://www.geeksforgeeks.org/longest-palindrome-substring-set-1/
1st F2F:
1. Why do you want to leave your current company?
2. Why Amazon?
3. https://www.geeksforgeeks.org/median-of-stream-of-integers-running-integers/
I told him min heap & max heap method, then he asked me who can you do it using trees.
4. There is a mxn matrix which contains only 1 & 0’s. You have to print the unique rows. I
solved it using tries, then he asked why cannot I use hash map and asked to write the code
using tries.
2nd F2F (Managerial Round):
1. Why Amazon?
2. Why leaving your current company so early?
3. Areas of Improvement , strengths & weakness
4. Given a prefix expression , convert into prefix tree and extended the qtsn for infix
expression, time complexities etc.
5. Given a dictionary , and we have to query for anagrams for the word. extended the qstn
to while typing the word we have to provide the autotype. Gave him a solun using tries.
3rd F2F:
1. In a stack pop fn will return you the value & pop the value and push fn will push the
value into stack , so how do you implement top fn. asked for O(1) solun.
2. Write a fun to check whether a given tree is a BST or not.
Telephonic Round (Bar Riser):
1. Why Amazon?
2. Asked about current projects and college projects.

475
Chapter 189. Set 188 (For SDE1)

3. Asked me which is the best project I have done and asked me how do I improve its
functionality, discussion went on this.
Tips:
They will help you are struck just think loud.
Practice writing code on paper.
I thank GeeksForGeeks for this great work. �
All Practice Problems for Amazon !
Group Anagrams Together

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-188-for-sde1/

476
Chapter 190

Set 189 (For SDE-1)

Amazon Interview Experience | Set 189 (For SDE-1) - GeeksforGeeks


Recently, I was interviewed for Amazon SDE-1 Position. There were two telephonic rounds
followed by 4 F2F rounds.
Telephonic Round 1 :
—————————
He seemed a bit unprepared for the interview. He started with some introduction and
knowledge transfer about current work and then created a binary tree and asked me to
write the level order, preorder, postorder and inorder traversals for that tree.
Then, the coding questions followed.
1) Flattening a multi-level linked list.
1st approach –> Using a queue : T = O(n), S = O(n). Coded it.
2nd approach –> Same as on GeeksForGeeks < https://www.geeksforgeeks.org/
flatten-a-linked-list-with-next-and-child-pointers/> : Didnt ask me to code. But
this one requires changing the structure of data.
2) Flattening a multi-level linked list but the nodes in depth should be printed first. So, ba-
sically the 1st question resembles BFS and this one resembles DFS. Did this using recursion
very easily.
3) Process vs Threads. What happens when you type in a URL? High-level design. Hand-
shaking protocol. HTTPS protocol, etc

Telephonic Round 2 :
—————————
I must say this guy who interviewed me was really smart. This round was a little more than
1 hour and there were 3 questions.
1) BST to Singly Linked List in place. A slight modification of this problem — https:
//www.geeksforgeeks.org/convert-given-binary-tree-doubly-linked-list-set-3/. Coded it.

477
Chapter 190. Set 189 (For SDE-1)

2) Finding Squares on the chessboard attackable by a rook


There is an NxN chessboard. Each square on the chessboard can be either empty or can
have a rook. A rook as we know can attack either horizontally or vertically. Given a 2D
matrix where 0 represents an empty square and 1 represents a rook, we have to fill in all the
cells in the matrix with 1 which represent squares that can be attacked by any rook present
on the chessboard. One can find a much simpler version of this problem here —
https://www.geeksforgeeks.org/a-boolean-matrix-question/
3) An array of buildings is facing the sun. The heights of the building is given in an
array. You have to tell which all buildings will see the sunset. This is pretty easy. The
first building will definitely see the sunset and for the rest of the buildings, just maintain
a variable max_height_seen_so_far and check with the height of the current building.
However, he then twisted the question and asked what my approach would be if I was to
scan the buildings from back to front rather than front to end. I used a stack and applied
the logic similar to that used in Next Greater Element problem.

F2F R1:
————–
Started with introduction. A lot of questions about current company, current work, current
project and then a design question.
How would you design the meeting invite feature of Microsoft Outlook? Considering each
meeting invite as an object and that Web server is the storage space for the invites, design
a data structure to receive and send invites to user in an efficient manner. The message
objects must be received in a sorted manner based on the time of meeting. I suggested using
a Binary Search Tree and justified the use of this DS. I gave an O(NlogN) solution. I was
then asked to code it. I coded it in C#.
Followed with a lot of HR questions.

478
Chapter 190. Set 189 (For SDE-1)

F2F R2:
————–
1) Reverse a sub array in an array. Pretty easy.
2) Rotate a subarray in an array where start and end indices of the sub array are provided
and ‘k’ is provided which is the number of rotations to be done. The interviewer behaved
really dumb in this question. All he wanted was a solution. He made me dry run the code
again and again and he wasn’t really bothered about the concept or the approach. I don’t
think he could relate to my solution which was O(n) in time and O(1) in space.
3) Find if a linked list has a loop. Old question. Take a fast and a slow pointer. But to get
this solution wasn’t really his motive. He asked why slow pointer should move by one node
at a time and why the fast pointer should move at the speed of two nodes at a time. As led
by the discussion, I was then asked to find the optimal speeds of slow and fast pointers for
a given linked list. Again, led by the discussion, he asked if it’s given that the linked list
has a loop and the size of the loop is given, can I find the optimal speeds of the slow and
fast pointers?

F2F R3:
————–
1) Same question as Q3 asked in telephonic round with the only difference that the heights
of the buildings was provided in a linked list. Coded it in C. Then, the interviewer twisted
the question by placing the sun after the last building(previously the sun was placed before
the first building). Used a stack. However, this can simply be done by the reversing the
heights array and using the same function written for the first part of the problem.
2) Design a data structure to represent the hierarchy of employees in an organization. Also,
the design should be such that, you can retrieve the no. of reportees of a manager(not just
the direct reportees but all the employees under him) very fast(O(1) was expected). Also,
insertion of a new employee and removal of an employee should be fast too.
I suggested using a n-ary tree of hash tables. Also, used an additional hash table where key
was employeeId and value was the address of the hash table (or the node) in the n-ary tree.
My solution did give no. of reportees in O(1) and addition and removal of employees was
in O(n) time, where n is the total number of employees. There wasn’t enough time to code
though.

F2F R4:
————–
This round had a lot of HR questions. Cultural info. Current project. He also asked coding
questions but he wasn’t really bothered about the optimality of the solution.
1) Two nodes in a BST are swapped. Find them. Told my approach. Didn’t ask me to code
it.
2) Print all the permutations of a string in lexicographic order. Coded it. Took me a lot of
dry runs to make him understand that the code is correct �
All Practice Problems for Amazon !

479
Chapter 190. Set 189 (For SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-189-for-sde1/

480
Chapter 191

Set 190 (Delhi Drive)

Amazon Interview Experience | Set 190 (Delhi Drive) - GeeksforGeeks


It was Amazon Delhi drive held in Jan 2015. This was conducted for various openings for
Bangalore location.
Round 1: Conducted by SDE-1
1) Tell me about your work experience.
2) Store deepest right leaf nodes in a list. There can be more than one right leaf which are
deepest and at same level. Approach was to find deepest right leaf node level and connecting
all right leafs at that level in a linked list by inserting new node at beginning.
3) Count number of balanced brackets ().
Round 2: Conducted by SDE-2:
1) Stock buy sell to maximize profit
2) In running stream of integers find k largest integers at any point of time. (hashtable plus
min heap approach made by day)
Round 3: Conducted by SDM:
1) Print matrix spirally from any point and using given direction. (This was very difficult
to solve because usually the problem is simply print matrix spirally)
2) He asked about most challenging faced so far. (At some point of time I realized I was
telling conflict but soon concentrated to tell a challenge. Please prepare behavioral questions
beforehand and be specific. Nobody is sitting there to listen a story)
Round 4: Conducted by SDM:
1) Tell me about your entire work experience briefing each project starting from latest. He
stopped at some points and asked tech questions.
2) What is the most conflicting situation faced and how you handles it?
3) What is the most innovative input you provided where you were appreciated by your
manager?

481
Chapter 191. Set 190 (Delhi Drive)

4) Implement garbage collector. (Had no idea how to do that, but took some time and was
able to tell an approach to maintain reference count in hashtable. He asked to code the
approach)
Three rounds were completed on a day and fourth and final round was telephonic. My last
round turned out to be negative because I was not able to write complete code in given
time.
Still the problem asked in round 1 and round 2 were new to me and was able to solve those
using different approaches which I have learned from Geeks for Geeks. �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-190-delhi-drive/

482
Chapter 192

Set 191

Amazon Interview Experience | 191 - GeeksforGeeks


1st round (data structures and algorithm)
1) Ladder of n steps is given.Find the number number of ways to reach the end point.I can
take either 1 step or two steps at a time.
2) Find the k largest number in running stream of words.
couldn’t write the running program for the second question.
2nd round (problem solving)
1) Every path from root to leaf add to a certain number,delete all the nodes which do not
satisfy this condition.
2) Hash problem.To implement put(key,value) and get(key) in log(n) time.
Suppose there are key and value pairs like
(1001, 233) (2001, 3340) (8776, 9)
you have to perform get and put operations using function

hash(key)
{
return key%1000;
}

and your own hash operations. Did it using hashmap with pointer to an avl tree.

divided the key with 1000.


suppose 1001%1000 = 1;
put 233 in 1st AVL tree, AVL tree will have structure like
node {
int index;
int value;
}

483
Chapter 192. Set 191

AVL will be constructed on the basis of index. index will be 1001/1000;


ie. if I have to put(3004,996)
3004%1000 = 4;
then go to 4th AVL tree using hashmap.Now compute 3004/1000=3;
My node will have index = 3 and value = 996. Insert this node in 4th AVL tree on the
basis of index. Thus time complexity will be log(n) where n is the number of elements in
Key%1000 AVL tree.
3rd round (Hiring manager round)
1) About current company, explained everything in detail.
2) Then a large file is given you have to find all the panagrams. Told him to divide the file
in chunks for parallel processing. Maintain an array of size 26 or instead of that, you can
set the bits of a 32 bit number. Set the bit of a number so that you can easily check the
panagram condition.
4th round (data structures and algorithm)
1) 2-d matrix service tax of different cities are given in the form of the 2-D matrix.Find the
least cost to go from one city to another.you can travel only in two directions right or down.
2) Find all the nodes at a distance r from the given node n.
3) Find the sum of all bits from numbers 1 to n.
Bar raiser
1) About work experience,projects and current company
2) To find the shortest sub-sequence with maximum sum.
Practice writing code on paper and take care of corner cases.
You won’t want interviewer to find faults in your code.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-191/

484
Chapter 193

Set 192

Amazon Interview Experience | 192 - GeeksforGeeks


1st Round –
1. Write code to create a copy of linked list with random pointer.
2. Print left side view of a binary tree.
2nd round –
1. There is a stream of integers incoming. You are only concerned about finding whether
a number exists in a window of k numbers. Write code to find the number with minimum
number of comparisons.
2. Imagine you have four operations. ‘K’ (types k on screen), ‘select all’, ‘copy’, ‘paste’.
Find out maximum number of K’s possible for given number of keystrokes.
3rd round (Hiring Manager)-
1. Current position and work. Any challenges faced.
2. Why do you want to move and join Amazon ?
3. Suppose there is new UI feature given to you by Product Manager but you dont like it.
If he insists that you implement it anyway, how will you handle this situation ?
4. An array of numbers is give. Write algorithm to divide this array in two subarrays such
that difference of sum between these subarrays is minimum.https://en.wikipedia.org/wiki/Partition_problem
4th round (Senior manager) –
1. Questions around current job, challenges faced. Any instance of conflict and how you
resolved it.
2. Find out whether a tree is a balanced tree or not.
3. Given an array of strings, sort it so that all anagrams come together.

5th round ( team member )-


1. Find out whether a tree is BST.
2. Print all permutations of given string.
6th round-
1. Rotate a 2D array by 90 degrees.
2. Print tree nodes in a level order. Each level on a newline.

485
Chapter 193. Set 192

Result- HR said that you will offered a job. But a week later I got rejected. I found their
process highly arbitrary.
Practice code on paper and get to know on what criteria you are getting selected.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-192/

486
Chapter 194

Set 193 (For SDE-1)

Amazon Interview Experience | 193 (For SDE-1) - GeeksforGeeks


I had interview with amazon.com for SDE1 position.
1st Round – (Written Round)-
25 Multiple choice questions(Networking, OS, DBMS, C concepts)
2 coding questions were also asked, for which paper code was required.
2nd round –
1. Placing N chess queens on an N×N chessboard so that no two queens attack each other.
For example, following is a solution for 4 Queen problem.

https://www.geeksforgeeks.org/backtracking-set-3-n-queen-problem/
I had a long discussion on this question finally he was satisfied with my solution.
2. Write a program to find the sum of maximum sum subsequence of the given array such
that the intgers in the subsequence are sorted in increasing order.
https://www.geeksforgeeks.org/dynamic-programming-set-14-maximum-sum-increasing-subsequence/
3. Given a Binary Tree, check if all leaves are at same level or not.
https://www.geeksforgeeks.org/check-leaves-level/
3rd round –
Given a sorted array arr[] and a number x, write a function that counts the occurrences of
x in arr[]. Expected time complexity is O(Logn)

487
Chapter 194. Set 193 (For SDE-1)

https://www.geeksforgeeks.org/count-number-of-occurrences-in-a-sorted-array/
Find k largest elements in an array. Elements in array can be in any order.
4th round(Hiring manager)-
1. Questions around current job, challenges faced. Any instance of conflict and how you
resolved it.
2. A lot of discussion on projects and work experience.
3. A large file is given you have to find all the anagrams. Told him to divide the file in
chunks for parallel processing and then check anagrams using heap.
5th round(Bar Raiser)-
1. Why you are leaving your current company so early?
2. An integer is given to you,first convert it into binary then reverse this binary string and
print decimal corresponding to this reversed string.
3. He asked one question related to REALLOC function.
In every round, after each question, complexity of the algorithm was asked. Its good to ask
questions to get more clarification about the question.
I want to thank the entire team of geeksforgeeks. It is a great portal and it helped me a lot
in preparing for Amazon interview.
Tips: Discuss various approaches with interviewer. Try to interact continuously with in-
terviewer. they were very friendly during interview.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-193-for-sde-1/

488
Chapter 195

Set 194 (For Software Support


Engineer)

Amazon Interview Experience | 194 (For Software Support Engineer) - GeeksforGeeks


It was a usual Job Application at Amazon’s Job Site, I got their call few days later.
Process:- 1 Written Aptitude(Coding) + 3 Technical Round + 1 HR Round
1) One Written Test – 8 Problem statement – 1 Hour Time – from Basic to Mid-level
difficulty, for which we have to write the Logic/Algorithms
Some which I remember were good enough are –
i) Given a Folder path in a Directory Structure. E.g. “temp/reg”; you need to find all the
files with extensions “.c” in this folder as well as in the sub-folders.
ii) Finding the Longest Palindrome Sub-String in the given string.
iii) From the given string, print the Alphabets which occur more than once in the string.
iv) Given two Integers A & B, Print the number of bits to be flipped in order to convert ‘A’
to ‘B’.
v) Implement EnQueue() and DeQueue() of Queue DS using Push() and Pop() of Stack DS.
Write Steps and Sequence.
Possible Solutions:- (Logic)
i) Use Linked-List DS to store the Folder Path in a Node. Open the Folder with First Node,
filter all the “.c” extension files, and add the sub-folders in the linked-list, until all the nodes
in the linked-list are explored.
ii) Use ‘frame’ variable with value starting from 2, increasing till size ‘n’, and check by
shifting this frame by one position, if the sub-string is a Palindrome or not.
iii) Basic Char to ASCII conversion and back to Characters. Create an Array of 26 slots for
alphabets. Convert the input string to UpperCase before proceeding.
iv) Convert to Binary Representation and Compare as String Characters. If not same, then
increment the counter. Remember, we have to only display the Number of bits flipped.
v) Use Operational Logic for Priority Queue, and for –
a) EnQueue – Push everything in Stack1.
b) DeQueue – (Check if Stack1 is Not empty)Pop everything from Stack1 and Push them

489
Chapter 195. Set 194 (For Software Support Engineer)

one by one to Stack2. Then Pop top element from Stack2 as Result. For Next DeQueue do
reverse, i.e. from Stack2 to Stack1.
2) 1st Technical Round
i) Write Program to Reverse a Linked List.
ii) Discussion on a Scenario and Debugging/Troubleshooting the error.
3) 2nd Technical Round
i) The similar Debugging/Troubleshooting scenario.
ii) Add the Numbers present in the String and display.
E.g. “abc123def-567ghi89jk”
Here take ‘-‘ as negative number symbol.
iii) Find the Pair of Array elements summing up to value ‘k’, in a Sorted Array. Optimize
it from Complexity ‘N^2’ to ‘NlogN’ using Binary Search.
4) 3rd Technical + Managerial Round
i) Some OS Related Questions.
ii) UNIX Commands – Which I couldn’t recall!
iii) Project Experience and Why want to Join Amazon and similar ones.
Though I couldn’t clear the 3rd Round, the overall experience was good.
## Remember:-
—————————
>> Please check their Technical Requirement, and revise your concepts of OS(How Process
works, Process Life Cycle, RAM, Virtual Memory, DeadLocks etc.), UNIX(Revise Basic
Commands like ‘grep’ etc.).
>> Practice basic Problems like, Searching, Sorting, Fibonacci, Factorial, Recursion, Stack,
Queue, Linked List and their Application.
Hope it helps for the new Applicants!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-194-for-software-support-engineer/

490
Chapter 196

Set 195 (On-Campus For


SDE-1)

Amazon Interview Experience | 195 (On-Campus For SDE-1) - GeeksforGeeks


20 mcqs – OS, Apti, Puzzles, C, DSA
2 coding –
1. Merge intervals given in array
2. Variation of josephus problem with k=2
Interview round 1
1. Find Largest Sub-Matrix With All 1s (Not Necessarily Square)
2. Search element in a sorted rotated array in only one (logn).
Some of my friends were asked –
1. Merge 2 BSTs
2. Diameter of Binary Tree
3. first positive element not in array(unsorted)
4. check binary tree is BST
5. search an element in a very large array, you don’t know it’s size
6. Decreasing sorted array given , make a balanced BST.
7. Generate all permutations of string.
8. 2 unsorted arrays given, find if there BSTs will be same.
9. Find a triplet a, b, c such that a2 = b2 + c2.
10. Convert a BST into a DLL and DLL to BST in place.
Interview Round 2
1. Delete half nodes from binary tree
2. kth largest element in large array
3. All strings possible from a no. for example 26, Ans – “B”,”Z”,”BF”
4. Implement a stack with push(), pop() and min() in O(1) time, using Class concept.
Tips –

491
Chapter 196. Set 195 (On-Campus For SDE-1)

Only Hardwork and practice helps. And of course your luck on interview day �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-195-on-campus-for-sde-1/

492
Chapter 197

Set 196 (On-Campus)

Amazon Interview Experience | 196 (On-Campus) - GeeksforGeeks


20 mcqs – OS, Apti, Puzzles, C, DSA
2 coding –
1. Merge intervals given in array
2. Variation of josephus problem with k=2
Interview Round 1:
A detailed discussion on my summer intern project . Questions testing the knowledge of
N/W layer. I was asked to explain all the layers of TCP/IP model using the analogy of post
office.
Program to find whether a BT is BST or not. (Handle duplicates as well).
Interview Round 2
1. Discussion of previous round interview questions.
2. Merge two BSTs(examine all cover cases)
3. Search in a rotated and sorted array.
4. Find maximum distance between two leaves in a BT.
Tips –
Only Hard work and Practice helps.Please be thorough with the OS,DBMS,N/W.
Luck plays its role too on interview day �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-196-on-campus/

493
Chapter 198

Set 197 (On-Campus for


Internship)

Amazon Interview Experience | 197 (On-Campus for Internship) - GeeksforGeeks


Hi folks, Amazon recently visited our campus hiring for SDE. They are usually the first or
second company to visit our campus, but this time, they came in much later, which gave
me lots of time to prepare (by prepare I mean go through g4g)
I had great fun preparing for the Amazon visit, and really enjoyed myself through the
interview process. The process spanned across two days, and was definitely among the most
comprehensive interview sets one could ever have. The interviewers were really chill and I
really felt really comfortable throughout the interview.
Let me share my experience with you.
First round (1 hour 30 mins) (Apti + coding)
this was the standard Amazon first round contest.
20 apti questions from C/C++/Java outputs, OS, DS, Algorithms, Time and speed, mix-
tures, etc.:-
As long as you are able to solve the coding questions you should be fine.
Q1) Given a set of time intervals in any order, merge all overlapping intervals into one and
output the result which should have only mutually exclusive intervals. Let the intervals be
represented as pairs of integers for simplicity.
Q2) Josephus problem with k = 2
The use of IDEs were disallowed, so be comfortable with coding on the HackerRank editor.
The error reports there are a little difficult to comprehend, and so make sure you are
comfortable with that.
Quite a few people were selected in 4 categories based on the scores.
Round2: (1 hour 15 mins) Hand/paper coding round.
1) Find the largest rectangular area possible in a given histogram where the largest rectangle
can be made of a number of contiguous bars. For simplicity, assume that all bars have same

494
Chapter 198. Set 197 (On-Campus for Internship)

width and the width is 1 unit.


They wanted a solution better than n^2
2) Border traversal of a complete binary tree.
They wanted an efficient code, which traverses the tree only once.
They got the algos from us, and if they were satisfied, asked us to write code on the paper.
A lot of my friends who came up with efficient algos didn’t make it through this round, as
I believe they didn’t get noticed enough �
Amazon’s hiring policy was to rather miss out a good candidate than hire a bad one, which
was evident here. Around 20 people made it through this round (They also considered the
previous round score (to an extent) for this round)
This is where the real challenge began.

F2F 1: ( 1 hour 30 mins)


we began with a little bit of chatting introductions etc.
We then directly moved on to the only technical question I was asked this round, which was
not particularly an easy one.
Given a 2D array, find the maximum sum sub-matrix in it, also display it.
Working code was required, which was then tested with a couple of inputs, so there is no
getting away.
F2F 2(Manager round ~1 hour 45 mins)
We started with a discussion about my projects. He wanted a detailed description along
with all the technical problems faced and solutions used to counter them.
This went on for more than half an hour.
Then he gave me a couple of question on trees, one of them was finding the vertical sum of
nodes, given a tree, and working code for the same.
Questions on database management systems, and some other technical questions from my
projects.
Then more questions, which I don’t remember now.
Then it was my turn to ask him questions. He really liked the questions I asked him.
F2F 3: Advanced Data structures and algorithms round. (~1 hour 30 mins)
This was easily the most enjoyable interviews I have ever had for a variety of reasons.
It started off with a small discussion, and a “Tell me about yourself”.
1) The first question was, “What are trees?” I said, “When people think of trees, they only
conceive of binary trees, but trees can have more than 2 children… and so on”
So then he tells me that all his questions were going to from whatever hints I give him from
my answers to his previous questions.
So the next half an hour was spent on n-ary trees.
Serialization of n-ary trees.

495
Chapter 198. Set 197 (On-Campus for Internship)

Serialization of n-ary trees, where n is not known beforehand.


2) Some question, which reduced to finding the smallest element in a sorted-rotated array.
Code for the same, along with all corner cases. Make sure you write all the corner cases, in
your first attempt itself.
3) Examples where trees are used in Real life, and in computers. This was a very lively
discussion. He didn’t accept “Family trees” as an answer, claiming that families these days
do not follow tree structures any more.
One question lead to another, and some where I said graphs.
4) So next few questions were on graphs.
5) Given three strings A, B and C. Write a function that checks whether C is an interleaving
of A and B. C is said to be interleaving A and B, if it contains all characters of A and B
and order of all characters in individual strings is preserved.
6) So, after all that, He wanted an ELI5 (explain like how you would to a kid) version for
all my projects, and the technology stacks I had used for them.
This meant that whatever answer I gave was ‘too complicated’ for him, and I had to simplify
it, without using synonyms of “Somehow”. Again, super fun.
I gave him a solution for a case where letters aren’t repeated.
Then gave a solution by cloning and checking the strings as and when necessary, he wanted
a better approach, and gave me quite a bit of time.
I then gave a DP solution, and he was happy with it.
After this, it was my turn to ask him questions. Again, a bunch of questions, to which I got
some really great answers.
And finally, we concluded the interview with a nice talk about Snooker, and how the Chennai
centre has a new brand new table �
Final Round (Telephonic) ~2 hours.
Other than the telephonic conversation, we also used an online collaborator, which let him
see what ever code I wrote on my laptop.
We started with a bit of introductions, (turned out that, we were from the same school),
and general introductions, “Tell me about yourself”.
He didn’t have a copy of my resume, and he wanted me to make sure that didn’t affect
anything.
Lots of questions, like “Give me an instance where you and your teammate had a disagree-
ment during a project, and how you resolved it”
“Give me a place where you showed some leadership quality to resolve conflicts”, many other
similar questions.
We then moved on to the technical questions.
1) Given a huge array which is stored across 100 computers, with no way to bring them all
together, find the median of the above array.

496
Chapter 198. Set 197 (On-Campus for Internship)

I had already seen the problem with 2 instead of 100, and when I told him the answer
immediately, it was evident, and so we moved on to the next question.
2) Given a chess board, and a starting position, and a set number of moves, find the
probability that the knight will remain on the board after the moves are done.
Handle all the corner cases, like when if during the first move, the knight goes outside the
board, that traversal ends there.
I had to code the entire thing, on the collaborator, and by habit I kept pressing ctrl+s, and
hence, it kept disconnecting. *facepalm*
He was in a real hurry, but he still made sure he answered all the questions I had for him.
But he was not too satisfied my solution, and gave me time to improve and said he’d come
back in 5 mins, but he didn’t �
General tips:
1) Prepare well, and concentrate on DBMS and OS as well.
2) Be confident, and be interactive.
3) Ask a lot of questions when you are asked to. This is a good time to show them you are
interested in the company, and that you think beyond the coding aspects of the company.
Some of my questions were:
a) What makes Amazon any more customer centric than the other similar e-commerce
websites?
b) How do programmers contribute to how the customer actually feels about the company?
because coders do after all only implement what their managers tell them.
c) Given that this is such a tough interview, how many of such tough questions do you
actually see in production?
4) Having a good resume’ can help you guide your interviews.
Try to be original with your questions
And, all the best �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-197-on-campus-for-internship/

497
Chapter 199

Set 198 (For SDE1)

Amazon Interview Experience | 198 (For SDE1) - GeeksforGeeks


I have recently attended an interview with Amazon Hyderabad, for SDE-I position. All 4
rounds are conducted by different people from different teams.
There are 4 rounds in total.
1st and 2nd are on DS, Algos, PS
3rd is partially coding and partially design round
4th is managerial round.
Here are the questions that are asked in each interview:
1st Round:
1. What are the traversals required to serialize and deserialize a binary tree?
And what about for BST?
Given InOrder and Post Order of a binary tree, construct the original tree back. Write the
code.
2. From a large stream of integers coming continuously, Find the k smallest elements always
at any particular time?
3. There is a Binary Tree.
Now you have to replace each node’s data with the sum of its left and right child’s data.
But the condition is that:
You should replace the node’s data with sum, only if the sum > data
If the sum < data, then keep some value on the node and adjust its left and right child’s
accordingly. For eg: node=20, left=4, right = 6. Now sum = 10. Since 20 > 10, you should
not replace.
Instead keep the node’s data as it is and replace left data as (20-6)=14.
Now root=20, left = 14, right=6. Now check the condition again from left, till you reach
leaf nodes.
2nd Round:
1. Given a set of strings. We are required to merge all these strings into a single string.
You are given with a merge(str1, str2) function, whose cost is sum of lengths of the strings
passed.

498
Chapter 199. Set 198 (For SDE1)

How can you merge the strings, by making the cost as low as possible?
Write code of deleteMin, insert, percolateDown operations in Heap.
Solution:
Initially sort the strings in ascending order wrt their lengths. Now take out the first two
strings and concatenate them.
Keep the resultant string in the sorted strings, wrt its length.
Priority Queue will be used to achieve the desired solution here.
2. Given a matrix of size m x n. Here m and n are very large, assume like 1 lakh.
You are given a series of submatrix inside this matrix. Find the sum of all elements inside
each submatrix.
Submatrix positions are given interms of its: top_left_cell and bottom_right_cell.
For eg:
input array: 5 x 6
1, 2, 3, 4, 5, 6
7, 8, 9, 10, 11, 12
13, 14, 15, 16, 17, 18
19, 20, 21, 22, 23, 24
25, 26, 27, 28, 29, 30
submatrix positions:
(3, 4), (4, 5)
which is
16, 17
22, 23
o/p is: 78
Solution: Since there will be multiple submatrix will be given for your, its not optimum
to go element by element for each submatrix. Do some pre-processing, like build another
matrix same size as input matrix, which will contain sum of its sub matrix. This way we
can calculate the sum in O(1) time.
For the above example, the sum matrix is:
1×1 1×2 1×3 1×4 1×5 1×6
2×1 2×2 2×3 2×4 2×5 2×6
3×1 3×2 3×3 3×4 3×5 3×6
4×1 4×2 4×3 4×4 4×5 4×6
5×1 5×2 5×3 5×4 5×5 5×6
Now to find the sum of submatrix: (3, 4) and (4, 5)
sum = sum[maxRow, maxCol) – sum(minRow-1, maxCol) – sum(maxRow, minCol-1) +
sum(minRow-1, minCol-1)
3rd Round:
1. Design a newspaper subscribing system for a user.
What are all the systems to be considered as part of this design?
2. There is a stream of integers coming. At any particular point of time, you are required
to give the first non-repeated element from it.

499
Chapter 199. Set 198 (For SDE1)

For eg: 2, 3, 1, 2, 1, 3, 5
o/p: If I ask you at 2nd position(after 3), the answer is: 2
If I ask you at 5th position(after 1), the answer is: 3
If I ask you at 6th position(after 3), the answer is: “No such element”
If I ask you at 7th position(after 5), the answer is: 5
Solution:

Maintain a LinkedList, with the elements in insertion order


maintain hashMap with input integer as key and value as:
class IntValue {
int count;
LinkedList headNode;
}

Now when an element comes, check if the element is present in hashMap.


If(present in hashMap) {
if(element count == 1)
delete the element from linkedList,
by replacing its data with its next element's data;
} else {
insert the element into hasmap with count as 1
and insert the element into linked list at then end.
}

Manager Round:
1. Google crawler question.
Given a set of N documents.
Given k strings: {str_1, str_2, …, str_k)
Now return the document numbers, which contains all the k strings.
2. Given an N-ary tree. Mirror the tree.
Give a suitable tree Node structure for this and write code for the same to mirror it.
eg:

i/p:
1
/ / | \ \
2 3 4 5 6
/ / |
7 8 9

o/p:
1
/ / | \ \

500
Chapter 199. Set 198 (For SDE1)

6 5 4 3 2
/ | \
9 8 7

I haven’t done well in last two rounds. So I got rejected. But it was a nice experience
altogether.
Thanks to geeksforgeeks for hell lot of questions. It takes at least a life time to prepare all
the questions present in geeks for geeks, if we go by one question per day. Thanks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-198-for-sde1/

501
Chapter 200

Set 198 (On-Campus for


Internship)

Amazon Interview Experience | Set 198 (On-Campus for Internship) - GeeksforGeeks


Hello friends, Amazon recently visited our campus hiring for SDE. They are usually the first
or second company to visit our campus, which gives little time for preparation. so better
prepare yourself in summer vacations (read g4g).
I had great fun preparing for the Amazon, and really enjoyed myself through the interview
process. The process spanned across two days. The interviewers were really nice and I really
felt really comfortable throughout the interview process.
Let me share my experience with you.
First round (1 hour 30 mins) (Apti + coding):
This was the online round, conducted on hackerank.
20 questions were asked from C/C++/Java outputs, OS, DS, Algorithms, etc.
and 2 coding questions were asked.
Q1) Given a linked list, check whether it is palindrome or not.
https://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/
Q2) Given a matrix of NxM, consisting of alphanumeric characters, print the matrix spirally.
https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
After this round around 30 students were selected from 250 students.
F2F 1:(1 hour 30 mins) (Technical):
This round started with some basic questions like ‘tell me about yourself’ and some questions
on my projects.
after that coding questions were asked:
Q1) Given a matrix of NxM.
Now consider a submatrix in it having top-left coordinates as (x1,y1) and bottom right
coordinates as (x2,y2).
Now many queries are performed in which (x1,y1) & (x2,y2) are entered.

502
Chapter 200. Set 198 (On-Campus for Internship)

We have to find the sum of elements in this sub-matrix in O(1) time complexity for each
query.
Eg:
1234
5678
9102
3415
(0,0)-(1,2) : 24
(1,1)-(2,2) : 14
Q2) We are given an alien language, in which we dont know the arrangement of the letters.
Now we are given some words of that alien language in dictionary order.
using those words we need to find the order the the letters of the alien language.
https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
Q3) We are given the preoder traversal of a BST, we need to create the BST using the
given traversal.
But we can’t use inorder traversal(i.e. sort the elements and use the array.)
and also we need to create the BST in single traversal of the preorder list.
Q4) We need to reverse a Linked List using single pointer. (in other words : recurrsively)
He asked me to write the code for reversal.
After this round some students were selected for second round of the interview process.
Luckily i was among them.
F2F 2:(1 hour) (Technical):
This round also consisted of coding questions:
Q1) Given a tree, print the tree in Zig-Zag manner.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
Q2) Given a sorted array, we need to find that element whose value is equal to that of its
index value.
He asked me to do it in log(N) time complexity.
Q3) Given a tree, now the given tree is special as in this tree all node has only 1 pointer
which points to its parent.
Now, in this tree we are given any 2 nodes, and we need to find their lowest common
ancestor(LCA).
Hint: This question is similar to intersection of 2 linked lists.
In the end he asked me if i had any questions to ask.
Thanks to geeksforgeeks �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-198-on-campus-for-internship/

503
Chapter 201

Set 199 (On-Campus for


Internship)

Amazon Interview Experience | Set 199 (On-Campus for Internship) - GeeksforGeeks


Recently, Amazon visited our campus. Here is my Interview Experience:
Online Round: (Duration – 90 minutes)
20 MCQs and 2 coding questions. MCQs were on Algorithms, Time Complexity, Quantita-
tive Aptitude, Probability, Operating Systems, Graphs, Data Structures, Recursion outputs
etc.
Coding Questions:
1. In one of Amazon fulfilment centres, there are a no. of empty boxes kept in increasing
order in a row. Kiva robots are designed to put a product in a box. The product size is
given. Design a program to find the best fit box for given product size. First line contains
no. of empty boxes and next line contains size of boxes with space. The next line contains
size of given product. The output shows the best fit box size and -1 otherwise.

For example, Input: 6


2 7 9 11 13 16
12
Output: 13

2. Given a binary tree, find the longest path in the tree. If there are two longest paths print
the lexicographically first path.
EXAMPLE:

504
Chapter 201. Set 199 (On-Campus for Internship)

OUTPUT: D E B A F G
ROUND 2: (DS CODING ROUND)
1. Given a BST and 2 nodes in the BST, find the length of the path between the two given
nodes.
Example:
Input: the below tree and node 3 & 7
Output: 5

505
Chapter 201. Set 199 (On-Campus for Internship)

ROUND 3: (F2F)
1. Given an array where the elements are in absolute difference 1, write an algorithm to
search for an element in the array and return the position of the element. (return the first
occurrence).

Example:
Input: 8 7 6 7 6 5 4 3 2 3 4 3 search element: 3
Output: 7

2. Given a linked list, check if it is a palindrome or not.

Example:
Input: madam Output: true

3. It was a scenario question based on facebook. I have to find all the mutual friends of my
friends and my friends of friends of friends. This list returned should be in a sorted order.
To perform the above action u are given a getfriend() function which will return the list of
friends for that id.
Hint: use hashing
ROUND 4: (F2F)
1. It is a graph question. A 2D graph with x and y coordinates. Given millions of points in

506
Chapter 201. Set 199 (On-Campus for Internship)

a graph, find the k nearest point to the origin.


Hint: use heap ( I used a priority queue )
2. Given a binary tree, a node in the tree and a distance k. Print all the nodes at a distance
k from the given node in the tree.
Example:

Input:
given node – F
K=2
Output: A E J K L

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-199-on-campus-for-internship/

507
Chapter 202

Set 200

Amazon Interview Experience | Set 200 - GeeksforGeeks


Aptitude Round: (1:30 hours)
19 MCQs
Easy MCQs on trees, semaphores, deadlocks and algorithms. Few output questions on
pointers.
2 Coding questions:

• Check if two strings are anagram.


• There are n employees in a company, each having some ratings. The employees are
given a hike in their salary based on their ratings, i.e employee with higher rating will
get the higher raise. An employee can only know the hike and rating of two of his
neighbors, one on the left and other on the right. Given an array of size n, specifying
the ratings of n employees, find the minimum hike that should be raised for each
employee, such that no employee feels unfair.
Example: 1 3 5 4 (ratings for 4 employees)
Output: 1+2+3+2 = 7
Example: 5 3 4 2 1 6
Output: 2+1+3+2+1+2 = 11.
The hikes are positive integers only. The ratings are greater than zero.
Size of input array: 1-1000000

Interview:
Round 1:

• Given a no, find next no greater than n and having same digits.I was supposed to
write a working code for this on paper.
• There is a robot that is initially at origin. A robot have three operations, he can either
turn left or turn right, or he can move one unit ahead in the direction he is facing.
Given a string containing L (turn left), R (turn right), G (move one unit ahead).Find
if the robot again reaches the point he has been before (find a loop).

508
Chapter 202. Set 200

Example: LGRGRGG
Initial co-ordinate is (0, 0), it turns left and moves one unit, updated coordinates
(-1,0).
Then turns right and moves one unit, updated coordinates (-1, 1).Then turns right
and moves two unit (two ‘G’s). Updated coordinates are (1, 1).

Round 2:

• Given an 2-D array, implement an hash map which when given (key, value), insert and
retrieve value in O(1). Also implement one more functionality that gives me all the
keys for corresponding value in O(n).
• Given a graph whose vertex can have only two value, either 0 or 1. Find no of distinct
clustered ones (island) in the graph. Write a working code for this on paper.

Black nodes – 1 marked vertices.


Ans = 2.

Round 3:

• Reverse a stack using only recursion.


• Create a data structure that maintains a record for all the courses and students enrolled
for that course. Each course has course id, and student is uniquely identified by its
enrolment no. The data structure should provide following operations:
– Insert of a new student for a particular course.
– Deletion of a student for a particular course.
– Given a (courseid, enrolment no), search if this pair exists or not.
– At any time you should be able to give the last enrolled student for a particular
course.
• Given a tree, print left most and right most node of each level.

509
Chapter 202. Set 200

Output: 1 2 3 4 5 8
• Given a table that has amount has its column and an integer n, write a query that
give nth largest amount value in the table.
• What are the differences between child processes and threads? Explain virtual memory,
paging concept, page replacement algorithms. Design a data structure for working set
algorithm.

Round 4:

• Questions on my internship and projects.


• Then the interviewer started asking questions on computer networks about framing
and all. After asking 3-4 questions on CN, he then switched back to DS.
• Given a binary tree, find whether it is Binary search tree or not, without using any
external dynamic memory for array. Write code for this.
• And then at last the aura got filled with all the never heard questions on OS and
Computer Organization.

Important tips:
Have a loud thinking, the interviewer helps you if you get struck.
Don’t do silly mistakes while writing code, take your time but have a neat, optimized code.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-200/

510
Chapter 203

Set 201 (On-Campus for SDE-1)

Amazon Interview Experience | Set 201 (On-Campus for SDE-1) - GeeksforGeeks


Aptitude Round: (1:30 hours)
20 MCQs
MCQs on processes, maths aptitude, and algorithms etc . Few output questions on pointers.
2 Coding questions: ( on hackerRank)

• Given 2 strings, check if any one of them has any anagram of the other string, as a
substring of it.
• Graph question : ( not mentioned directly as graph, but was implied). basically
Needed to find the shortest path between two given vertices in the graph.

Interview:
Round 1:

• BST to Doubly Linked List ( Geeks question){code it}


• for Doubly Linked List to BST conversion, give an algorithm and prove its complexity
using recurrence relations. => O(nlogn)
• On a number line from negative infinite to positive infinite, if you start from 0, you
can either jump back or front. but every jump length is 1 more than the previous
jump. Given a number on the number line, can we reach it using any combination
of jumps. If yes, print the minimum length path. Hint: Solved using Queue storing
all possibilities, something similar to BFS. and BFS search wud always give shortest
path.

Round 2:

• Given an array of Integers, find the Maximum length subarray with sum equal to
zero. Solved by constructing Prefix sum array for the given array. In prefix sum
array, any number repeating more than once, implies subarray between those indices

511
Chapter 203. Set 201 (On-Campus for SDE-1)

is 0, so store length of this subarray, check for other repeated values too. ( careful
coding required to eliminate bugs) Additionally had used a HashMap(java) to do this
solution time efficiently. {code it}
• Return largest BST from a BT ( geeks question) {code it}

Round 3:

• Tell me About your Internship project. ( It dealt with Performance bench-marking for
embedded Systems ( SoC) with respect to latency and bandwidth done at Samsung
R&D B’lore).
• Given a 2-D matrix of zeroes and ones, any row/column containing a single 1 is made
completely 1. ( available on geeks) I told him I know the space and time optimized so-
lution to it ( as provided by geeks). Asked me to code it… had some bugs, took some
time to debug a particular corner case.{code it}
• He Modified above question, providing conditions -> if there are no limitations on
the space used, and if accessing each cell has a cost attached to it, how would you do
the same problem in least cost.
• Given a tree with three pointers in every node, left, right and next, connect all the
nodes at the same level in a spiral fashion. eg root’s next points to right child which
in turn points to roots left child which in turn points to level 2’s 1st left child … and
so on… any node could have 0,1 or 2 children.( geeks)

Round 4:

• Given the function : int func( int n) { if(n==1) return 1; return n* func(n-1)*func(n-2)
+ func(n-1)*func(n-2) + func(n-1); } // What is its space complexity.
• Given a in-coming stream of numbers ( either 0, 1 or 2), Design a Finite state
machine which tells me if the number formed by the input stream so far, is divisible
by 3. eg stream state is “012” return true, coz 12 is divisible by 3.. for “0111” return
false… { Design the FSM }
• Proposition logic question with 5 statements given, determine their truth. ( Solved
using common sense, but wanted me to prove it mathematically )
• Given an int represented in Big Endian form, convert into into Little Endian, where
the number of bytes taken up by int is not provided. Ex: if int is of 4 bytes and input
integer n= A B C D , => o/p = D C B A => n2 … where the alphabets represent a
byte. return n2. Involved Bit manipulation. { Code it}
• The one thing you regret from the past 3 years in college.

Round 5:

• Introduce yourself.
• Given an n-ary tree, traverse it in level order, printing a particular element in each
level( that particular number is returned by function “func1(int level)”. Gave an O(N)
time and O(N) space complex solution, followed by an O(N) time and O(1) space
complex solution. {code it}
• Advantages/Disadvantages of a static variable inside a class in java.

512
Chapter 203. Set 201 (On-Campus for SDE-1)

• Performance implications of the static variable inside a function in C.

Selected as a full time employee.


Tips:

• Have a loud thinking, the interviewer helps you if you get struck. Ask ALOT of
questions. At least he will know what you are thinking or where you are going wrong
at.
• Write neat code,”take your time …..as much as you like”.
• Make sure the interviewer has approved the algorithm before you start coding. Discuss
full algorithm before you code. He may ask you to think in a more optimized manner.
• Study “geeksforgeeks.org” well, especially the tree sections, and dont mug up the code,
its no use, you will not remember when needed, instead, understand why every minute
detail of the code. This will take u further.
• Study basics of every computer related subject taught in class. No need to be experts,
but having an idea helps.
• Mostly it is about data structures and algorithms. Make sure you are comfortable
with them.
• Side note: Help others and just do good. Neither hard work nor luck pays. Its all
about your destiny. Dont get worked up about these things. Life has more purpose.
• “Karmaane vadhi karaste ma faleshu kadhachanam..” – Gita

above line means “Keep doing good deeds, dont expect rewards..”
“Nasrum Minallaahi Wa Fathun Qareeb” – The Holy Qura’an
Above line means, “When comes the help of Allah, Victory is near”
Best of luck �
Thank You geeksforgeeks teams.. Thanx a ton �
And thanx to my parents, and friends who helped me alot.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-201-on-campus-for-sde-1/

513
Chapter 204

Set 202

Amazon Interview Experience | Set 202 - GeeksforGeeks


I had an interview with Amazon recently below are the questions asked.
Qualification round
1) Rotate/Shift the elements of a square array clockwise by one at a time. (Not by 90
degrees, but by one element. Think of concentric circles)
Example:
12
34
Output:
31
42
2) Write a function that determines whether a two dimensional array contains duplicate
values within k indices of each other
The first line of input will be a number indicating how many rows are in the matrix. This
will be followed by lines of input one for each row of the matrix each row will contain the
same number of columns with each column separated by a space. Following the matrix will
be a single line of input containing a number indicating the k value.
Output should be ‘YES’ or ‘NO’
example:
4
1234
5678
9 10 11 12
13 14 15 16
3
Output: No

514
Chapter 204. Set 202

F2F Interview
5 rounds in total.
Each round was for 45 mins.
1st F2F
Tell me about yourself
Given three sorted arrays, how will you sort all the three arrays into one array, shortest
time expected
2nd F2F
Design architecture that should handle millions of hits at given time, the response time of
the system should be the least. – ( Hash Map for data storage is something i came up with
and that was accepted. Couldnt come up with a solution for the entire problem.)
3rd F2F:
About project experience and how i handled it. Amazon leadership skills were mostly
expected.
4th F2F:
Sum all the values of the nodes of a Binary tree that fall on the same column and print
them.
The solution is to treat root as the center and any node that moves away from it (left/ right
)one at a step is treated as under same column
5th F2F:
Print the values of a binary tree that occurs on the same level.
-Level order traversing.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-202/

515
Chapter 205

Set 203 (On-Campus for SDE-1)

Amazon Interview Experience | Set 203 (On-Campus for SDE-1) - GeeksforGeeks


Hi everyone. Following is my experience of the recent Amazon recruit drive:
Aptitude Round: (1:30 hours)
20 MCQs
MCQs on outputs, maths, algorithms, DBMS, OS.
2 Coding questions: ( on hackerRank)

• Given 2 strings, check if any one of them has any anagram of the other string, as a
substring of it.
• Graph question : ( not mentioned directly as graph, but was implied). basically
Needed to find the shortest path between two given vertices in the graph.

Tip: It is important that one should attempt both sections decently.


Interviews:
Round 1:

• On a number line from negative infinite to positive infinite, if you start from 0, you
can either jump back or front. but every jump length is 1 more than the previous
jump. Given a number on the number line, can we reach it using any combination of
jumps. If yes, print the minimum length path.
• https://www.geeksforgeeks.org/a-boolean-matrix-question/
• https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/

Round 2:

• You have n slabs with two dimensions. Stack them to get max height. No rotation
of dimensions required. First he started with 2 dimensions, then 3, 4 and then for n
dimensions.

516
Chapter 205. Set 203 (On-Campus for SDE-1)

• Given a binary tree, a target node in the binary tree, and an integer value k, delete
all the nodes that are at distance k from the given target node. No parent pointers
are available.

Round 3:

• https://www.geeksforgeeks.org/sort-array-according-order-defined-another-array/
• An array of 0s and 1s is given. A sequence is given as f(1)=1,f(2)=2, f(n)=f(n-1)^2 –
f(n-2)^2.
Print 0s and 1s alternatively according to the given sequence.

Round 4:

• Implement the power function in log n complexity.


• Intersection of two arrays
• Given a stream of As and Bs, print 1 when no of As is odd and no of Bs is even. I
just had to draw the DFA for it.
• An SQL query.

Round 5:

• Given an array and a window k, print the minimum in every window of k. After
suggesting a few data structures like dequeue, heap, bst, he told me to code it using
bst.
• A file system is given. All the subdirectories in the root directory, the subdirectories
within subdirectories and so on is given. The input is some file or subdirectory paths
for which we need permission. Find the minimum permissions required to get all the
permissions. No file for which permission is not asked should be given permission to.

Tip:

• The interviewers are really very helpful and they keep on giving hints if you are stuck.
Just let them continuously know your thought process. It is not necessary that you
speak continuously but let them know what you think in intervals.
• They might ask you to think of better complexities and different data structures
to solve the same problem. But its not that if you straight away land up in an
optimized solution its bad for you because I was asked sometimes to compromise on
the complexity but think of other data structures to solve it.
• While coding take your time. Make sure you cover the corner cases and if it is taking
long, let your interviewer know what you are doing currently. Test it before finally
approving it. If it fails, don’t worry, tell your interviewer about it and think of a fix
or an alternative

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-203-recruit-drive/

517
Chapter 206

Set 204 (On-Campus for


Internship)

Amazon Interview Experience | Set 204 (On-Campus for Internship) - GeeksforGeeks


Cut off: 75%. Around 140 students were short listed.
Round 1 (Written Test) 90 minutes
It comprised of aptitude, operating system, complexity, hashing ,graph, and complexity
related questions (20 questions).
There were two coding questions
1. Given a string find the first non repeating character in it
2. Given an array of integers delete minimum number of elements such that the minimum
of the arrays is at least twice of the maximum. (need to return the count).
Round 2
The round began with my brief introduction and then there was a question on arrays.
I was given an array with all elements greater than or equal to zero
I was asked to to return the maximum product of two numbers possible
It was quite easy as we can find the maximum and the second maximum and their product
will be the answer but the interviewer wants me two to reduce the number of comparisons.
Initially i did it in O(n) and with 2*n comparisons
and finally came to a solution with 3n/2 comparisons by considering the numbers in pairs.
The interviewer was satisfied with my solution and i was asked to write a production level
code for the same.
example Test case
5937
answer 9*7
Now she added one more constraint to it we are not allowed to change the structure of array
and we need to find the pair such that they are in increasing order
example

518
Chapter 206. Set 204 (On-Campus for Internship)

1978
answer 7 * 8
Initially I did it in O(n2) ie for each element i I found the maximum to its right and then
compare the maximum with the ith element then it can be the possible pair
and can contribute to the result
I came up with and (nlogn) solution using segment tree and sparse table
(Range maximum query) (Interviewer was impressed).
Finally I created a max stack from the right side and did it in O(n) with O(n) space but
still she wanted me to reduce the space to O(1)
It was already 1 hr and she gave me a hint that move from right side
and bingo i was able to answer her in just 5 minutes.
She was completely satisfied with my solution.
Then there was a small discussion on my projects.
Round 2
The round again began with my brief introduction and then he asked me about my favorite
subject.
He asked me to explain any data structure. I explained him Tries and segment tress. I even
told him about how tries can be used . I told him about auto complete features available,
forward dns and there working (He was impressed)
Now the he was asking questions from application point of view
He asked me about heaps and it uses and to comment upon it
I explained him heaps priority queues and complexity of it operations and about Fibonacci
heaps.
Application for merging k sorted arrays.
He asked me to illustrate some application of circular linked list and double linked list.
I told him double linked list can be used for LRU cache and using hashmap it can be done
in O(1) expected complexity per operation.
I was asked to code it.
For circular linked list I told him that it can be used for implementing a circular queue
efficiently since we need to maintain only one pointer ie. the rear for it.
Application BFS.
He then asked me to code and dry run a circular buffer and optimize it and compare it with
standard cyclic queue.
I used a counter variable for this purpose to use the buffer completely
and told him that the drawbacks can be when multiple processes try to access this shared
variable then there may be inconsistency hence traditional one was better.
Then he asked for critical section,locks ,semaphore and mutex.
All Practice Problems for Amazon !

519
Chapter 206. Set 204 (On-Campus for Internship)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-204-on-campus-for-internship/

520
Chapter 207

Set 205 (On-Campus for


Internship)

Amazon Interview Experience | Set 205 (On-Campus for Internship) - GeeksforGeeks


Cut off: 75%. Around 140 students were short listed.
Round 1: 90 minutes
It comprised of 20 MCQs on aptitude, operating system, DBMS, data structures and algo-
rithms on Hackerrank.
There were two coding questions
1. Given a string find the first non repeating character in it, O(n) was good enough.
2. Given an array of integers, find count of minimum number of elements to be removed
from the array such that the maximum element of the new array is at most twice of the
minimum. O(nlogn) solution was required.
39 shortlisted after this round
Round 2 (F2F) 75 minutes
1. Given a complete BST, find kth minimum element. Required time complexity O(logn)
and O(1) space complexity. The interviewer was really supporting and kept giving me hints
to reach the solution.
2. Given a 2D array of 0s and 1s. Find largest square submatrix with all 1s. Although I
made silly mistakes initially, I arrived at efficient solution later.
3. Find the LCA of two nodes in a binary tree.
Around 22 shortlisted after this round
Round 3 (Tech +HR) 45 minutes
It started with questions like
1. why do you want to join Amazon?
2. what are your areas of interest?
3. plans for higher studies?

521
Chapter 207. Set 205 (On-Campus for Internship)

He scanned my resume and then proceeded with a brief description of my project and its
relevance.
2 coding questions
1. Maximum sum subarray
2. Maximum product subarray
covering all corner cases and proper working code
It moved on to detailed discussion on OS: thrashing, threads, processes, mutex semaphores
etc. The interviewer was nice and made me comfortable throughout the process.
Lastly, he asked if I had anything to ask him. I asked about the role of interns and latest
projects going on in the company.
Tips:
Be expressive during your interview.
Have a good resume (Aggregate+Projects+Coding skills)
Stay calm and confident
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-205-on-campus-for-internship/

522
Chapter 208

Set 206 (On-Campus for SDE-1)

Amazon Interview Experience | Set 206 (On-Campus for SDE-1) - GeeksforGeeks


Hi Everyone recently Amazon visited our campus for SDE-1 and internship and I got an
offer for internship as well as SDE-1. Here’s my experience.

Written Exam(1hr:30mints):
There were 22 questions asked in which 20 were of MCQ’s and 2 coding questions. Most
of the MCQ’s came from OS, Algorithm, C-o/p and aptitude (directly from previous year
Computer science GATE).
First coding question: Determine the diameter of a tree (Taking input was a bit difficult as
we have to take input in array of unknown size,sort it and create BST).
Second coding question: Given a string of words seperated by comma,we have to print pair
of words who are anagrams line by line(case-insensitive). If you don’t find any such pair
then print -1.
Interview Rounds:
Round 1(1hr:15mints):
1. Started with Introduction then he jumped into project and discussed about 15 mints.
2. Given an array print elements according to frequency and if two elements have same
frequency then print it in decreasing order.
Gave solution using 2d matrix in O(n2). Then reduced the complexity by sing AVL
tree in O(nlogn).Later coded AVL tree solution on paper.
3. Given a binary tree, print boundary traversal
I gave solution by using three traversal(as given in gfg) then he asked me to do it in
single traversal. I discussed alot with him then finaly came up with solution by using queue
and stack data structure. Later he asked me code it and I coded correctly. He was impressed
with my code.

Round 2(1hr):
1. Started with project discussion of around 25 minutes.

523
Chapter 208. Set 206 (On-Campus for SDE-1)

2. Given an array of stock prices, find maximum loss in buying and selling stocks. I gave
him appoach first, then he asked me to code. Coded it.
3. Implement garbage collector in C without using free function.
4. What is virtual inheritance.
5. Explain how the file is stored in memory.
6. Explain UNIX I node Implementation.
7. Difference between process and threads.
8. How threads are executing parallely and how they share memory.
9. Asked algorithm to schedule kernal level threads(gang scheduling).

Round 3(1hr:30mints):
1. Started with Introduction
2. Detailed project discussion of around 45 minutes.
3. Given me the Resource allocation graph with set of processess and resources, ask me to
tell him the approach to execute all the process.
I told him to use topological sort suddenly he said very good and ask me to code. I
coded it.
4. Explain the need of synchronization with the help of example.
I explained him with use of producer-consumer and printer spooler problem(also written
code for both).
5. basics of synchronization i.e code for wait and signal operation and how the semaphore
maintains their suspended list.
At the end of this round interviewer was very impressed.
Round 4(1hr):
1. Given a integer number n, tell its binary representation is palindrome or not.
e.g 4=100 not palindrome
5=101 palindrome.
TC = O(n) and SC = O(1) was expected and I coded it.
2. He gave me a java code using lock on this keyword.Ask me is there any problem in
the code using lock keyword when multiple threads are running concurrently. I found the
problem then he ask me to resolve it and I resolved it.
3. What is virtual memory. Who implements it.
4. How virtual memory concept is implemented in system.
Tips:
1. Interviewer don’t expect you to give all correct answer though they want to see your
approach first and how you tackle a problem which you don’t know apriori.
2. Brush up OS fundamentals thoroughly and try to practice code on paper as much as you
can.
3. Along with basic data structures also have some idea of advance data structures like
BBST,Trie,Graphs etc.
4. Think loud in front of interviewer and try to engage him all the time.
5. Listen his words carefully, probalbly they will have some hints to answer.
I would like to thanks geeksforgeeks team for providing such a great platform. You guys are
doing awesome job.
All Practice Problems for Amazon !

524
Chapter 208. Set 206 (On-Campus for SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-206-on-campus-for-sde-1/

525
Chapter 209

Set 207 (On-Campus for


Internship)

Amazon Interview Experience | Set 207 (On-Campus for Internship) - GeeksforGeeks


Cut off: 75%. Around 140 students were short listed.
Round 1: 90 minutes
It comprised of 20 MCQs on aptitude, operating system, DBMS, data structures and algo-
rithms on Hackerrank.
There were two coding questions
1. Given a string find the first non repeating character in it, O(n) was good enough.
2. Given an array of integers, find count of minimum number of elements to be removed
from the array such that the maximum element of the new array is at most twice of the
minimum. O(nlogn) solution was required.
39 shortlisted after this round

Round 2 (F2F) 75 minutes


The only question that was asked was
Find the third largest element in the array
I first gave him a heap solution(kth largest element in the array )
He asked me to write the code for it.
Then he asked me to improve it. And then i gave him O(n) solution .
He said that i should cover all the edge cases .And left the room alone for 30 minutes. Then
he came back and he was satisfied with my solution .And immediately said that wait for
the 3rd round
Round 3 (F2F) 75 minutes
Here the main focus was on Data Structures

526
Chapter 209. Set 207 (On-Campus for Internship)

1. Mirror A Binary Tree.


2. Given Two BinaryTrees , check if they are mirror of each other. (Told me to code it)
3. Level Order Traversal in spiral form(Told me to code it)
4. Boundary Traversal in BinaryTree
5. Merge k sorted arrays.(All approaches).
6. Diameter of the BinaryTree
Then he asked some question on OOPS(friend function etc.)
Lastly, he asked if I had anything to ask him. I asked about the role of data structures and
algorithms in the company work . He said they are used greatly that’s why we judge all of
you on the basis of these only.
Tips:
Be expressive during your interview.
Strong Data Structures And Algorithms
Focus On More Than One Solution Of The Question
Stay calm and confident.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-207-on-campus-for-internship/

527
Chapter 210

Set 208 (On-Campus for


Internship)

Amazon Interview Experience | Set 208 (On-Campus for Internship) - GeeksforGeeks


Amazon visited our campus for hiring Software Developer interns for Summer 2016.
Cut-Off : 75%
140 students were shortlisted.
Round 1 (Coding + Aptitude):
First round mostly comprised of problems on OS, DS, Basic Aptitude, Algorithms etc.
2 coding questions
1. Given a string find the first non repeating character in it
2. Given an array of integers, find count of minimum number of elements to be removed
from the array such that the maximum element of the new array is at most twice of the
minimum.
39 shortlisted after this round
Round 2(F2F)
He asked about my favorite subjects and Data Structures that I have implemented. I named
few Data Structures including Segment Tree. Then he asked me about segment trees and
how to solve some simple problems based on segment trees, He asked only about approach
didn’t asked me to code. Then he asked me about
https://www.geeksforgeeks.org/connect-nodes-at-same-level/
I told him approach using level order traversal. Then he asked me to connect nodes on same
level but this time to their left sibling. After telling my approach he asked me to code and
said that he want code free of any errors. After I gave him my code he pointed out that
there are some errors in code. He asked me to find and correct them myself.
Then he asked another question:
https://www.geeksforgeeks.org/diameter-of-a-binary-tree/
After hearing my approach for this question he asked me to print leaves that correspond to
diameter.

528
Chapter 210. Set 208 (On-Campus for Internship)

Round 3(F2F)
Only one question was asked in this round. She asked me to implement a data structure
that can perform
1) Insert (O(1))
2) Delete (O(1))
3) Count(O(1))
4) Get Element(O(1))
on integer inputs. Here Get Element returns any element present in DS.
I told her my approaches using array, single linked list with hashing and using two singly
linked list and hashing. I couldn’t reach exact solution but she was satisfied with my
approach.
Solution to this problem was easy using doubly linked list and hashing.
After this round a total of 19 students were selected for internship.
TIPS:

• Think before you speak


• Be honest during interview
• Stay Calm
• Take hints from interviewers

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-208-on-campus-for-internship/

529
Chapter 211

Set 209 (On-Campus)

Amazon Interview Experience | Set 209 (On-Campus) - GeeksforGeeks


Round 1:-
MCQ – Memory management , angle between hands of clock at a certain time , Inheritance
etc
Coding :- There were 2 coding questions
1) Given 2 Strings , check if any anagram of one string is a substring of the other string
2) Given some friends on Facebook say A, B, C, D. and their friendship as AB and B C
We need to find out the minimum Hops from a query say:- for A to C the hops should be 2
A to B and B to C , (Floyd Warshall Algorithm)
I solved approximately 17 correct MCQ’s out of 20 and Both the Coding questions.
Round 2:-
This round was the longest . (1 hour 40 min) approx
first slight discussion on a project . I was discouraged to explain in detail and asked to give
high level discussion .
3 questions :-
1) if we throw light from the left of a tree , what nodes receive light .
2) extended first question and asked boundary traversal of a tree
3) asked to search an element in a sorted and rotated array
Round 3 :-
(45 min)
2 questions :-
1) Given an array of positive and negative integers we need to find the longest subarray
where sum =0
first gave o(n^3) then o(n^2) then finally o(n)time+o(n)space
2) given an array of size n-1 and given that there are numbers from 1-n with one missing ,
the missing number was to be found

530
Chapter 211. Set 209 (On-Campus)

Round 4:-
(1 hour 15 min)
4 questions :-
1) given a number line from -infinity to +infinity what are the mnimum number of hops
required to reach a number given the condition at step j I can take j steps forward and j
steps backward
2)what datastructure to use to implement best fit algorithm , I gave a skip lists solution
which i thought was a strong solution
3)Traverse a binary tree in zig zag order – very common question
4) gven some values [M] [T] [R/W]
M- memory address
T- time slice
R/W- Read/ write
the number of conflicts were needed to be found out !
I couldn’t make it after this round –
Why I got into such a predicament was because I was to excited and was asking too many
questions and trying to discuss CS concepts which were unrelated to the problem in hand .
Only 2 tips :-
1) Geeks for Geeks is a MUST, so is GeeksQuiz
2) Speak as little as possible the interviewers would not be interested in answering your
questions with the time constraint that they have , Short discussions are acceptable but I
was trying to ask too many questions and telling them about stuff I knew without them
asking .
Thank you Geeks for Geeks for making answering amazon questions easy !!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-209-on-campus/

531
Chapter 212

Set 210 (On-Campus)

Amazon Interview Experience | Set 210 (On-Campus) - GeeksforGeeks


I am sharing here my experience in Amazon On Campus Interview. Amazon visited our
campus for SDE-1 positions.
Round 1(Coding + Aptitude)
There were 20 MCQs based on aptitude and technical questions. The quality of questions
were good.
Two Coding questions were as follows:
1. Convert a given Tree to sum tree (from geeksforgeeks)
2. Given an unsorted array of positive and negative numbers, create an array of alternate
positive and negative numbers without changing the relative order of positive and negative
numbers respectively. Suppose the array is(zero is treated as positive)
array : 9 4 -2 -1 5 0 -5 -3 2
result: 9 -2 4 -1 5 -5 0 -3 2
24 candidates were shortlisted for the Interview round out of around 300 candidates.
Round 2 (F2F)
Asked questions like, Tell me about yourself, most challenging project, most risk taking step
in any project, any project in which you did something extra for your team even though it
was not in requirement.
1. Given a multilevel linked list with next and down pointer as shown in the image below:

532
Chapter 212. Set 210 (On-Campus)

Give the following output without using any extra space: 1->4->6->7->2->5->8->3
Solution: Make the next pointer of D to point to down pointer of A, followed by making
next pointer of 1 to point to down pointer of B. Similarly proceed until the two heads meet.
2. Connect nodes at same level using constant extra space (expected me to write a modular
, clean and production level code)
Round 3(F2F)
1. Given a string and a pattern, Replace all the continuous occurrence of pattern with a
single X in the string. With example it will be more clear
String: abababcdefababcdab
Pattern: ab
Result: XcdefXcdX
Initial 3 occurrence of ab is replaced by one X and then two occurrence of pattern is replaced
by one X and final one occurrence of pattern is replaced by one X
Coded it incorrectly in first attempt. The interviewer gave me another chance, coded it
perfectly.
2. Print the left and right side view of the tree in a same function. (wrote a clean code with
no mistakes)
Round 4(F2F)
Asked about my projects, about myself etc etc
1. Given a stream of Twitter data with hashtags generated in time construct a data structure
to give top K trending tweets at a time.
I initially suggested max heap based on frequency but was unable to find top K nodes in a
max heap.(*Trouble)
Later, i suggested to maintain a hash table with frequency count as the value and hashtag
as key and to implement a k-size Min-Heap to store the top K elements.(She was satisfied
but not happy with the time complexity)

533
Chapter 212. Set 210 (On-Campus)

2.(*Trouble) Because of my statement to find top k elements in a max-heap, i was asked to


code for finding Top K elements in a max heap with size N where (N>K). It seems to be
trivial but it isn’t. I tried my best and didnt gave up, the interviewer was happy with my
energy and my never-give up attitude :P.
Round 5(F2F)
Asked me about a project done as a team and what was my role in it. My most challenging
project etc
1. Suppose a chemical Formula is given C6H2(Cl3(OH2)3)3
Print: C-6 H-20 O-9 Cl-9 (Print the number of atoms of each element in a compound)
Solution: Gave a stack based approach where we need to push opening brackets and atoms
and multiply the frequency of each atom in stack with the value after closing bracket until
we find a opening bracket.
2. OOPs concept: Abstract class, Interface, Singleton class, code for constructor of singleton
class.
Tips: Always practice on paper. Never give up in interviews. Pick up hints from interviewer.
Be Energetic. Study from geeksforgeeks �

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-210-on-campus/

534
Chapter 213

Set 211 (On-Campus for


Internship)

Amazon Interview Experience | Set 211 (On-Campus for Internship) - GeeksforGeeks


Amazon visited our campus for hiring Software Developer interns for Summer 2016. All CS
and IT students were eligible.
Round 1 (Coding + Aptitude):
First round comprised of problems on OS, DS, Basic Aptitude, Algorithms, Time Complexity
etc. followed by 2 coding questions on HackerRank platform
1. Find the nth Magic Number where a Magic Number is either a power of 5 or the sum of
unique powers of 5. Eg. 5,25,30(25+5),125,130(125+5),…
2. Given a dictionary find if any possible division of the input string corresponds to strings
present in the dictionary. Eg. If “i” and “like” are present in the dictionary, we need to find
if the given input string(say “ilike”) can be divided such that its components are members
of the dictionary.
18 students were shortlisted after this round.
Round 2(F2F)
Problem 1 Given a matrix containing 1’s and 0’s in sorted order(all 1’s should be continuous
followed by all 0’s), we need to find the row which has the maximum number of 1’s.

Eg. Consider the matrix


1111000
1000000
1110000
1100000

Your program should return row=1(1 based indexing)


Expected complexity = O(r+c) where r is the number of rows and c is the number of
columns.

535
Chapter 213. Set 211 (On-Campus for Internship)

I started out with O(r*c), then optimized to O(rlogc) and finally O(r+c).
Problem 2
Given three points in space find if a triangle exists.
Problem 3
Given four points in space find if a square exists.
Problem 4 Given points in space, how will you determine whether the points given are in
clockwise order.
All the problems required full working code for the most optimized approach.
10 students were further shortlisted for the next round.
Round 3(F2F)
We initially discussed about my project including the future course that I would like to
further steer my project in.
Problem 1 Given a Binary Tree, find if it is a Binary Search Tree with constant space
complexity.
Problem 2
Suppose there are n Petrol Stations in a circle. The difference in distance between two
stations P1 and P2 is L1 and so on and so forth.
Now, given the fact that for every unit of petrol consumed you can only walk 1 unit distance
and you can move further only for positive difference between the reserve petrol and the
distance that is to be traversed. . Find out if there is a vertex starting from which you can
come back to the same point traversing the circle once.
Expected Complexity O(n) I started with O(n^2) and gradually optimized it to O(n)
(Hint: Build a reserve array such that R[i] = P[i] – L[i])
Full working code was required in this case as well.
After this round, 6 students were selected for internship.
TIPS:

1. Stay calm
2. Remain super confident throughout. That is the key.
3. Have faith in yourself
4. Your implementation skills must be real good.

All thanks to Geeksforgeeks for helping me with my preparation and for being an excellent
repository of past Interview Sets.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-211-on-campus/

536
Chapter 214

Set 212 (On-Campus)

Amazon Interview Experience | Set 212 (On-Campus) - GeeksforGeeks


Online Coding Round
Time 1 hour 30 minutes.
1) Given an array of numbers, Rearrange the numbers to make the even and odd numbers
alternate. If any one type is in excess, let it come in the end.
2) Given a binary tree, change the value of the node by the sum of the values of its children.
I completed both the programs, first one passed 7 test cases, second one passed all test cases.
I was shortlisted for the interviews
1st Round F2F (Technical)
Asked what was my favorite project among the ones i have mentioned in my resume. Then
he asked to explain Project, and then he asked few questions regarding it.
He asked 2 questions. One was regarding linked lists. I forgot what those questions were.
2nd Round F2F (Technical)
stack using 2 queues. I implemented and showed, he was happy.
Given a matrix. Each cell is either marked with a * or nothing. One cannot go into the
cells that are marked by a *. Given 2 points a and b in the matrix, Find out if point b is
reachable from point a.
I gave a solution solution, but i had missed marking the cells visited. He pointed out that
it will be an infinite recursion. So i said i will mark it visited. He then told me to code it.
I did. He was satisfied with it.
Robot problem. Dynamic programming. I somehow solved it, he then asked for the code. I
wrote it. He tried to understand himself, but he wasn’t able to. So i made him understand,
he was happy and satisfied with it.
3rd Round F2F (Technical)

537
Chapter 214. Set 212 (On-Campus)

Questions on OOPs concept. Asked what a singleton class is. I answered, then he asked
how can it be implemented in C++. I was weak in the C++ language, so he gave hints. I
tried but he was not satisfied with my answer.
Then he asked to a question regarding trees. Given a binary tree, you have to connect all
the nodes in each level through extra pointers.
I gave an approach using queue. He then asked how to do with constant space. I tried, but
i had forgotten the algorithm. He tried giving hints, but i wasn’t able to solve.
4th Round F2F (HR + Technical)
He started off by asking how was the other interviews. Then he asked the typical “Tell me
about yourself”.
He asked me little about my favorite project. I selected the same one which i explained in
the first interview.
Next he asked, Given just a page of a Dictionary. It can be from anywhere, middle, end
or start. The dictionary is for a language that one doesn’t know. You have to find out the
order of the alphabets, which one comes before and which one comes after. I started with
an approach using generic tree. He asked me why can’t graph be used. I thought a little
and agreed, and started using graph. I explained him the inconsistencies that can occur.
Later after few minutes of discussion, he told me, suppose he gives me a graph with letters
in place of nodes, and says to find out the order of the alphabets. How would i go about
doing it. I mentioned topological sort, but i said i don’t remember the algorithm properly.
He gave a little hint, that reminded me, and i solved it.
He gave a scenario. Suppose you type “www.amazon.com” and hit Enter. What goes on
in the background after that. I gave a detailed explanation with Network layers, routing,
CDN, Content Caching. I missed out NAT, so he asked me what it was and how it will be
used.
Then he gave me a list of list. It had integers. Like the one shown in picture below (in
Attachment).

538
Chapter 214. Set 212 (On-Campus)

He told me to print 1, 2, 3, 4… I did it using loops, But he wanted to optimize it, and said
that i can modify the list if i wished. So i thought a little and got the idea. He asked me to
write the code. I wrote, he saw and said there was a bug, but he had missed something, i
explained him, so he was satisfied with the code.
Only 7 people were there till the last round. The interviews were over by 10:40pm. They
took 3 hours to come to the final list. They said that we all did very well. At 1:30 night
they announced 3 names. I was not selected. All in all it was a good experience, but i was
a little sad after the results came out.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-212-on-campus/

539
Chapter 215

Set 213 (Off-Campus for SDE1)

Amazon Interview Experience | Set 213 (Off-Campus for SDE1) - GeeksforGeeks


Hello I have applied for Amazon after completing my 1 yr at job and got a call for a full
day interview.
Interview happens as in following rounds :
Round 1( Technical):
1.)I was straight away asked to write code for detecting loop in a linkedlist without any formal
introduction and all https://www.geeksforgeeks.org/write-a-c-function-to-detect-loop-in-a-linked-list/
.
After telling my approach he asked me to give a proof of it to which I got shattered
but then he gave me a hint and later discussing it we got to the proof but it wasn’t a
full-valid proof. But later on it I found http://math.stackexchange.com/questions/412876/
proof-of-the-2-pointer-method-for-finding-a-linked-list-loop
After it he asked me to detect starting point of the loop. Again which is geeksforgeeks. I
wrote the full code on a paper and understand him my approach which is very similar to
geeksforgeeks one. https://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/
2.)He gave me another question from g4g which I haven’t read before
Sort one matrix based on another matrix. I gave him one brute force approach, then he asked
me to optimise it and then we discussed a bit an finally I came up with O(nlogn) approach.
However this is https://www.geeksforgeeks.org/sort-array-according-order-defined-another-array/
I was a bit hesitant after 1st round as I’ve mumbled upon the proof of detecting loop in
linkedlist until he gave me some hint. However, I was called after 2-3 long hours of waiting
for my 2nd round of interview.
Round 2(Technical):
He was a very senior guy and a very cool and calm personality. He entered the room and
said sorry to me for such a long wait and then started with formal introduction as to What
you do in your present company and why do you want to leave it at such an early stage.
1.)He asked me to check whether a given tree hold children sum property or not. Another g4g
question https://www.geeksforgeeks.org/check-for-children-sum-property-in-a-binary-tree/.
As soon as I heard the problem, I tld him my approach and coded it on a paper. He then

540
Chapter 215. Set 213 (Off-Campus for SDE1)

to calrify if I haven’t crammed it asked me to explain him the recursion and dry run it on
different examples. I did that explaining him completely the edge cases and every aspect of
that recursion. He was impressed �
Then he started telling about his experience of startups and that of Amazon
2.) He asked me another question :
Given a stock market price for each day in an array. Give the ans as to when you will buy
stocks and when you will sell so as to make the maximum profit.
I think for a while and gave him my approach which he was quite impressed.
After that HR asked me to leave and said that you’ll be informed about the result and
further rounds.I got a call and was asked to come for Hiring manager Round
Round 3 (Hiring Manager):
He is the manager of the team for whose team interviews are going. So he started of with
the formal discussion as to what are my technical interests and what did I learn in my
previous jobs. Then he starts discussing my CV and asked e t pick any 2 projects at which
I’m confident enough.
As I wrote technical paper on the work I did in my last job, so he started discussing over
that and asked me different ways of solving that problem and hw could I optimize it further.
Then he asked me some of the behavioral questions as of why are you leaving when such a
good work is there. I told him the concern about salary. It went fine and I thought that I
impressed him.
Later on HR told me to wait for another 4 hrs for Sr Manager round.
Round 4 (Sr Manager):
He is a very senior person in the Amazon. probably their head of some main division. He
started off with very behavioural questions as to why leaving so early and why Amazon. It
was very hard t convince him as his expressions were not changing at that time. He fired
me a series of such questions as to what is the most difficult task I have performed till yet
technically. He was hoping for answers specific to work related. What are your weakness
and strengths and what are you doing to improve yourself.
Then he jumped to my CV and asked me for each and every single detail written in my CV(
so please make your CV as small and as specific to your strong pints as you can). He asked
my role in different projects I have done and in the technical paper I have written along with
others. he even asked my college projects(even the 2nd sem project which I forgot to take
off from my CV) to the depth and asked for the specific details( He knew about everything
regarding my projects ).
Then after this discussion I thought it would get over, but he has some other plans. He
asked me to give a solution to some coding problems:
1. Check how many Parenthesis are balanced in an array of parenthesis.This was easy but
then he asked me to scale it such that your array can’t reside it on one memory. To this I
said do parallel processing, he gave me freedom of number of clusters on which I can store
and compute and then it took some time to me to come up with scaled algorithm. That
was quite interesting and energetic enough. All my tiredness went off.
2. In a string detect the smallest window length with highest number of distinct characters.
For eg.
A = “aabcbcdbca”, then ans would be 4 as of “dbca”

541
Chapter 215. Set 213 (Off-Campus for SDE1)

Finally I gave him some solution which was incomplete, he asked me to relook at my solution
and I found the mistake but didn’t asked me to code it.
I would like to thanks G4G to be such organized forum with the help of which, we can get
what are the current trends in interviews and also what they expect.
Don’t copy the solution from g4g but get the approach as that will help you to solve newer
problems ;). In other words train your model rightly, Don’t overfit it, else your accuracy
will be compromised �
Thanks.
All Practice Problems for Amazon !
Smallest distinct window

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-213-off-campus-for-sde1/

542
Chapter 216

Set 214 (On-Campus)

Amazon Interview Experience | 214 (On-Campus) - GeeksforGeeks


Amazon visited our campus for recruitment. Here is my experience.
First there was an online round on hackerrank and consisted of 20 mcqs and two coding
questions. Here are those two questions:
Ques 1: Given a singly linked list, write a function to put all the even numbers at the front
and odd numbers at the end of ll while maintaining the order of numbers. In place solution
was expected.
Ques 2: Given a sequence of moves for a robot, check if the sequence is circular or not. A
sequence of moves is circular if first and last positions of robot are same. A move can be
either R(Rotate right), L(Rotate left), G(Go one unit).
Round 1: There was some discussion on my intership project. Then i was asked the following
coding questions:
Ques 1: Given an array, find a pair of elements which gives us the maximum sum.
Ques 2: Given an array of strings in sorted order, print all the same strings only once on
the screen.
Ques 3: Given a binary search tree, find the kth smallest element int it.
Round 2:
Ques 1: Given an array, find the maximum length of subarray such that the average of that
subarray is the maximum of all subarrays.
Ques 2: Given the data value field of a node, print all the nodes at distance k from that
node in a binary tree.
Round 3:
Ques 1: Write a function which takes input as bank balance and returns a string equivalent
of that integer/float.
Ques 2: What happens after we type some web address in a browser and hit enter.
Round 4:
Ques 1: Given an integer and a mapping of Roman numerals [I:1, V:5, X:10,L:50] write

543
Chapter 216. Set 214 (On-Campus)

a function to convert any integer between 0 to 100 to Roman numerals. All the rules for
conversion have to be followed.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-214-on-campus/

544
Chapter 217

Set 215 (On-Campus for


Internship)

Amazon Interview Experience | 215 (On-Campus for Internship) - GeeksforGeeks


Online Round(1:30 hrs)
20 MCQs based on OS, C, C++, 3 questions on aptitude & 1 question on DBMS.
Q1. Write a program to separate even nodes from odd nodes and odd nodes must come
after even nodes(in place).

Input: 17->15->8->9->2->4->6
Output: 8->2->4->6->17->15->9

Q2. Find if the Robot moves in Circular fashion.


https://www.geeksforgeeks.org/check-if-a-given-sequence-of-moves-for-a-robot-is-circular-or-not/
After this round 20 students were shortlisted.
Then there were 2 PI rounds
Round 1:
Q1. Print a matrix spirally.
Q2. How to deserialize and serialize a binary tree.
After this round 8 students were selected.
Round 2:
Q1. Given a sorted stream of 0’s and 1’s, find the first occurrence of 1.Write a full working
code.
I firstly did it in O(n). Then he asked me to reduce the complexity.I reduced the complexity
to O(log n) by applying binary search.
Then he asked about my project mentioned in my CV. It went on for 20 minutes.
Then he asked me another question.

545
Chapter 217. Set 215 (On-Campus for Internship)

Q2. What happens when you click a web address and how are web pages retrived.
Q3. He asked me about memory management in C and C++ and how new allocates memory
to objects and he asked me to overload new operator.
Q4. If you are given some functions and whenever you call that function,the timestamp is
stored along with function name.

eg: f1 1:20
f2 2:30
f1 3:10

Suggest an appropriate data structure and write a code to make following queries within
two given time stamps t1 &t2:
query 1: Return number of all the functions called between t1 & t2.
query 2: Return number of times a particular function is called between t1&t2.
Then he asked me various OS and networking Questions.
Q5. Given an array of integers,find a subarray having least average.
Q6. Suggest some data structures to maintain relationship between various hierarchies in
an organization.
Thanks to geeksforgeeks for helping me out.
Read Geeksquiz for MCQs & g4g for interview questions.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-215-on-campus-for-internship/

546
Chapter 218

Set 216 (On-Campus for


Internship)

Amazon Interview Experience | 216 (On-Campus for Internship) - GeeksforGeeks


Amazon came to out campus a week back and this was the procedure followed.
Round 1 : On line coding (1 hr 30 min)
This round has 20 aptitude+coding +OS mcq questions
2 coding questions
1-Given a linked list retain the first i elements and delete the next j elements.
2-Given an array of number give a permutation of array which when converted to a number
is the greatest. eg Input-{2,985,9,3} output {9,985,3,2} as 998523 is the greatest number
that can be made.
12 students were selected for the next round.
Round 2 (Face to Face) (1 hour)
Introduce about yourself, asked my interests and then jumped to questions
First asked me dbms questions . ACID properties, transactions.
Then OOP questions , to explain the concepts of OOP.
Technical question-
Given an array which has id of songs write a song shuffle song. I first gave an hash table
approach he asked me to optimize it which i reached eventually.
Given a binary tree , connect all the nodes at the same level with a next pointer.
Given a sorted,pivoted array search for an element
At the end 4 students were selected.
All thanks to geeksforgeeks for helping me with my preparation.
All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-experience-216-on-campus-for-internship/

547
Chapter 219

Set 217 (On-Campus)

Amazon Interview Experience | 217 (On-Campus) - GeeksforGeeks


Hi everyone …Following is my experience for the recent recruitment drive of Amazon in our
college.
*** First Round ***
:- Aptitude Round: (1:30 hours)
20 MCQs
MCQs on Outputs, Math, Algorithms, DBMS, OS.
:- 2 Coding questions: (onHackerRank)
1) Given two string Str1 and Str2, Find whether any anagram of Str2 is a sub-string of
string Str1 (Case Insensitive) then return True otherwise False.
For Ex:if Str1 = Amazon and Str2 = zmao, Output: True
2) Given n non-negative integers representing an elevation map where the width of each bar
is 1, compute how much water it is able to trap after raining
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.

**** Second Round (F2F) (60 min)****


1) Check whether the given binary tree is BST or not
2) Find the lowest common ancestor of given two nodes pointer
3) Find Height of Binary Tree represented by Parent array
Input: parent [] = {1 5 5 2 2 -1 3} Output: 4
I did it in O(n2) and then interviewer ask to optimize it then I optimize the code but still
it is O(n2) but the interviewer was satisfied with the solution.
4) Find the next greater element in array
5) Find orphan node and cycle in linked list. I gave him the logic and Interviewer was
satisfied with approach.

548
Chapter 219. Set 217 (On-Campus)

TIP: Interviewer should understand your code properly. So write code neat & clean.
***** Third Round (F2F) (70 min approx.)****
1) Again the interviewer ask the same question: Find the next greater element in array. I
told him that I did it previous round then interviewer tell me that it is good u told me
about this.
I think I got some loyalty point from this �
2) Given the mathematical expression. Check for balanced parentheses in an expression
with constraint of precedence like
[2*{3+4}] = True;
{2*[2+4]} = False;
I give him approach and written full code for this.
3) How to detect cycle in graph ( I just told my approach using DFS)
**** Fourth Round (F2F) (120 minute)*****
1) Consider a row of n coins of values v1 . . . vn, where n is even. We play a game against
an opponent by alternating turns. In each turn, a player selectseither the first or last coin
from the row, removes it from the row permanently, and receives the value of the coin.
Determine that the user move first or second so that he will get the maximum possible
amount of money
I gave him the recursive approach for this then he ask for optimize code for this then I make
DP for this.
2) Consider a 2-D map with a horizontal river passing through its center. There are n cities
on the southern bank with x-coordinates a(1) … a(n) and n citieson the northern bank with
x-coordinates b(1) … b(n). You want to connect as many north-south pairs of cities as
possible with bridges such that no two bridgescross. When connecting cities, you can only
connect city i on the northern bank to city i on the southern bank.
I have no idea about this question I think 10 minute and told the interviewer that I’m
unable to solve this. But the interviewer asked for my approachthen I gave him brute force
solution for this and Interviewer asked for the code. Then he told me to optimize the code
then I gave recursive approach for butstill complexity is exponential and Interview asked
me optimize this and again I think for half an hour &arrive at solution that in DP with
extra space. Buthe still wants better solution and gave me five minute more. Then in the
five minute one best solution strike in my mind and told to interviewer and he ishappy with
effort then he ask to code.
TIP: What I learned from this round is that Push yourself to the edge. Give something
different or better than geeks
***** Fifth Round *****
1) Some project discussion in brief and some question on project like what is your role, what
difficulties you faced, and future scope.
2) Find minimum height of tree (I gave him two approach using 1) simple 2) using level
order)
3) Some simple Bit-masking problem

549
Chapter 219. Set 217 (On-Campus)

4) Given an input file with four billion non-negative integer. Provide an algorithm to
generate an integer which is not contained in the file. Assume you have 1 GB of memory
available for this task.
Firstly I have no idea then interview is giving me hint and I give my approach using bit
vector by mapping all integer from this bit-vector.
***** Sixth Round ****
1) He give me an API function that increment the counter when the client access this. And
told that two client simultaneously accessing this API function. Then they get ambiguous
value of counter. Why this is happening?
I give him Peterson solution and semaphore solution for the critical section problem.
2) Some more question on OS (thread, Mutexlock, and deadlock)
3) One more DP Ques: Remove minimum elements from either side such that 2*min becomes
more than max.
I gave him geeks solution but he ask that Have u seen this problem before? I said yes then
he ask to code the recursive approach for this I write it
Correctly. And He was satisfied.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-217-on-campus/

550
Chapter 220

Set 218 (On-Campus)

Amazon Interview Experience | 218 (On-Campus) - GeeksforGeeks


Hii, Everyone this is my interview experience with amazon.
***First Round (1:30 hr)-
It consist of two sections
:- Mcq (20 questions)
:- Two coding questions
1) Given two string Str1 and Str2, Find whether any anagram of Str2 is a sub-string of
string Str1 (Case Insensitive) then return True otherwise False.
Test case :if Str1 = Amazon and Str2 = omaz, Output: True
2) Given n non-negative integers representing buildings where the width of each bar is 1,
compute how much water it is able to trap after raining
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
I solved 19 mcq and both coding questions.
***Second Round (F2F):(1:30hr)
1) Find LCA in BST.
2) Find LCA in Binary Tree.
3) Given a binary tree where each node contains three pointers left,right,succ, where succ
pointer is pointing to any of its successor node , the question is if any of succ pointer is
pointing to its predecessor node then make that pointer NULL.
4) Given an array that represents the runs scored by a batsman and we have given the total
score ,now we have to find out in how many ways can batsman score the run.
Ex – arr = {2,3,1} total run = 4
2+1+1 = 4, 3+1 = 4, 2+2 = 4, 1+3 = 4, 2+1+1 = 4 and many more.

551
Chapter 220. Set 218 (On-Campus)

First I have given the recursive solution than interview asked me dp solution, I told him DP
approach he was satisfied.
5) Find Loop in a linked list and remove it.
6) You have 100 songs to play in a shuffling mode how will you play.
Interview want full working code for each question for last question he wanted only approach.
***Third Round (F2F):(1 hr)
1) Given a source string and a destination string and a dictionary consisting of various words
write a program to find minimum length path to travel from source to destination. Rules
for traversing:
1. You can only change one character at a time
2. Any resulting word has to be a valid word from dictionary
Example: Given source word CAT and destination word DOG , one of the valid sequence
would be
CAT -> COT -> DOT -> DOG
Another valid sequence can be
CAT -> COT – > COG -> DOG
One character can change at one time and every resulting word has be a valid word from
dictionary
I told him a approach using graph.
2) What is hashing.
3) What is modular hashing.
4) How collisions can be handled.
5) Is semphore guarantee deadlock prevention.
*** Fourth Round (F2F) : (2 hr)
1) A kind of celebrity problem you have n person where one of them is celebrity
condition are all non-celeb person knows celebrity and celebrity can know few other persons
and all non- celeb persons can know few of them among each other so you have to find
celebrity.
2) Given a binary tree and two nodes print the path between the two nodes of binary tree.
3) Find Height of Binary Tree represented by Parent array
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-218-on-campus/

552
Chapter 221

Set 219 (On-Campus)

Amazon Interview Experience | 219 (On-Campus) - GeeksforGeeks


Amazon came to our college. Here is my interview experience. There were total 5 rounds.
First Round (1.5 hr)-
It consist of two sections
-> Mcq (20 questions)
-> Two coding questions
1) Given two string Str1 and Str2, Find whether any anagram of Str2 is a sub-string of
string Str1 (Case Insensitive) then return True otherwise False.
Test case :if Str1 = Amazon and Str2 = omaz, Output: True
2) Given n non-negative integers representing buildings where the width of each bar is 1,
compute how much water it is able to trap after raining
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
Round 2(2 hr)
1.Introduce yourself.
2.Short discussion of project on machine learning as interviewer is working on machine
learning stuff.
3.A tree is stored in an array such that value stored at index I is parent of node I. Firstly
gave an nlog(n) approach as it came to mind first. He said to code it(coded it), then he
insisted to optimize the solution with worst case time complexity O(n), then we discuss the
DP solution he agreed on the logic and asked to code it (coded it).
3.Find lowest common ancestor in a binary search tree of nodes A and B. He asked if I have
seen this problem already I replied in affirmative, so he asked me to code it quickly, I coded
it. But he asked what if node A or B or both are not present, I said this code wont work
but we can first check it both nodes A and B present then we can use this code, he was
convinced n moved to next code.
5.Find max distance between any two nodes of a binary tree with at most a single bent. We
discussed a lot over this question then he asked to code my approach which we discussed,

553
Chapter 221. Set 219 (On-Campus)

while coding I found it was the wrong one, I told him that this approach wont work. At last
he said to leave this problem n moved to next.(only questions I couldn’t solve)
6.find loop in LL.
7.find frequency of words in a paragraph I suggested at first a hash than trie n he was
satisfied with the answer.
8.Again a short discussion on the project.
Round 3(Design questions) (1.5 hr)
1.) Suggest auto correct if a word is misspelt.
i)only one character is replaced by wrong character like cht then suggestion can be cat.
ii)the word written is prefix of other word.
Used trie.
2.) A service is requested by fixed number of customers (limited 5-10 ). If the service fails
at time n. Find frequency of requests made by each customer 10 minutes prior to failure of
service. I suggested a DS made up of queue and map.
3.)given a set of classes and their dependencies, return if this given set can be
BUILD(compiled) with or with out error.
class A:B C
class B:D
class C:E F
class D
class E:A
class F:G
class G:A
return error as classes A,C,E depends on each other.
I said questions same as find loop in a graph he agreed n asked to code.)coded it)
round 4(subject round)(2hrs)
1.)The answer sheets of previous interviews are passed on to next interview as my 3rd
interviewer did not had my answer sheet of 2nd interview he asked me about the questions
asked to me in the last interview.
2.)consider a service running on a server for a customer c1,but customer c1 times out after
s sec for what so ever be the reason so customer again fires the same request ,so server is
running duplicate query hence it gets overloaded, resolve this glitch. Some how I managed
to give a solution which he said is very similar to the solution he himself implemented to
resolve this glitch.
3.)given a tree find sum of all the numbers formed by appending the data of nodes from
root to leaf node. In a single traversal of the tree.
Eg:

1
/ \
2 3
Return 12+13=25

554
Chapter 221. Set 219 (On-Campus)

I solved it using a reference variable to store final solution and an variable passed as value
to store up to current node*10,thus add data of current node to this variable to get number
formed till this node if current node is a leaf then add it to variable passed as reference.
4.)Any idea about scheduling algorithms and there types.
5.)Given a matrix of 0’s and 1’s,find the maximum size of the square formed by 0’s.
1111
1000
1001
0000
Return 2.
coded it by flipping all zeros to ones and ones to zeros than ques similar as given on GFG.
6.)what is mutex?
7.)given words of a lexicographical order of an alien language find order of characters in the
language.
I said I have seen this problem it is of topological sorting and he proceeded to next question.
8.)multiple producers single consumer problem.
9.) Find all possible interpretations of an array of digits. I proposed a solution I was asked to
code it I coded it but he pointed out an error for test case containing zeros like 10,20,2010,so
I handled the case of zero.
Round 5(45 min)
1.)I was asked to tell about my projects which was not the one I discussed in first round
(either they had an discussion about it prior to my interview or coincidence).
2.)I had one project on web crawler so I was asked what changes will you make to this
project to scale it.
3.)another project was an android game similar to duck shooting(video game) was asked to
tell the difference between the 2.
4.)I was asked to tell how to copy last 10 lines from a file, he kept on asking for other
methods (I answered around 10 different ways).
5.)add and subtract two numbers without using + or – operator.i was asked to code it.i
used xor and binary and to solve it, then he asked to prove this method works.
7.)convert 777 to binary.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-219-on-campus/

555
Chapter 222

Set 220 (On-Campus)

Amazon Interview Experience | 220 (On-Campus) - GeeksforGeeks


Amazon visits our campus for recruitment. Here I am sharing my experience of the whole
process.
Round 1:
First there was an online round on hackerrank and consisted of 20 mcqs and two coding
questions.
mcqs were mainly from c/c++ input/output DS, OS .Here are those two coding questions:

Ques1: An array containing heights of building was given. Its a rainy season. Calculate the
amount of water collected between all the buildings.
Input: 1 5 3 7 4 2
Output: 2
Ques2: Two strings are given check if anagram of one string is contained in other string.

Round 2(F2F 1):


Three coding questions were asked, all from geeks.
Ques1: In a party of N people, only one person is known to everyone. Such a person may be
present in the party, if yes, (s)he doesn’t know anyone in the party. We can only ask
questions like “does A know B? “. Find the celebrity.
https://www.geeksforgeeks.org/the-celebrity-problem/
Twist: this time celebrity may or may not know some persons in the party. Suggested him
O(n^2) approach. Using stack we can minimize comparisons.
Ques2: Given an unsorted array that contains even number of occurrences for all numbers
except two numbers. Find the two numbers which have odd occurrences in O(n) time

556
Chapter 222. Set 220 (On-Campus)

complexity and O(1) extra space. Told him that I know its approach already. He asked me
for the approach.
https://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/
Ques3: An array of size n-1 is given contains numbers from 0 to n. Find the two missing
numbers in O(n) time and O(1) space. Suggested him method given in :
https://www.geeksforgeeks.org/find-the-smallest-positive-number-missing-from-an-unsorted-array/

Round 3(F2F 2):


He starts with my introduction and some questions on classification as in my machine
learning project I have made a classifier.
Ques 1: Find next Greater element for each element of the given array.
https://www.geeksforgeeks.org/next-greater-element/
Ques 2: Find if a binary tree is BST or not. Suggested method 3 given in this post.
https://www.geeksforgeeks.org/a-program-to-check-if-a-binary-tree-is-bst-or-not/
Ques 3: Given a matrix calculate minimum cost path to reach from top-left to bottom-right.
Suggested him the dp approach then he asked me if this will work with negative edges or
not. I said yes it would work.
He then twisted the question a bit…now one can move in either of the four direction
left,top,right and bottom and can contain negative edges. Suggested him recursive ap-
proach having exponential time complexity. Asked me in which case it won’t work. After
sometime told him if it contains negative cycle. I think it can easily be done with graphs.
Ques 4: coins are lined up (eg. 100 200 50 2) Two players playing this game can pick a coin
from either of the left or right end. Player with maximum sum will win. Both players are
optimally playing the game. You have to tell that whatturn(1 or 2) should be chosen in
order to win. Like in above example if you play first then can select coin 2(you want to get
that 200 coin to win).

Round 4(F2F 3):


He started will “tell me about yourself” and then he asked me about “Virtualization” one
of my project. A long discussion on the same. Questions like what happens if he wants to
have a trace of his previos work and other project related questions.
Ques 1: Sort a 2GB file line by line. Avoid use of extra space (or use minimum space).
Suggested him solution with trie but he said it would take space if there are no common
prefixes. Then i gave him a solution with hashing(store hash value per line and sort it) but
he was not satisfied with time complexity) then finally suggested counting sort. As we can
have only 256 different characters at max in any line. Time complexity was O(n*m) n no
of lines and m no of characters per line. Satisfied =D.
Ques 2: He gave me a small code to debug. Below code is having four bugs.

557
Chapter 222. Set 220 (On-Campus)

Unsigned inti;
For(i=100,i<=0,–i)
Printf(“%d\n”,i);
Ques 3: What happens when you hit your college url. Describe all steps. Then he asked
some questions on networks like http, tcp, port, switches etc.
Ques 4: Print all permutations of a string. Asked me for the approach and code it.
Round 5(F2F 4):
Long discussion on my summer internship project. Project was on “Machine Translation”
(translation of one language document into other language). Mine was converting English
to Hindi. Asked me for the approach and discussion on the same.
Then he gave me this problem.
There are number of clients requesting pages of a service. Find number of pages requested
by clients in each 5 minutes. Gave a solution with queue using linked list and map.
Then a long discussion on my minor project which was on machine learning. The interviewer
was having deep knowledge on machine learning So he asked me a lot on the same. Then
he asked me if I have studied it as a subject. I said no. He said “that is what I wanted to
know”. He was impressed with my projects.

Hope this experience would help you to prepare for the company. GFG helped me a lot, a
great site with almost all stuff to prepare for the interview. Best of luck J keep coding J
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-220-on-campus/

558
Chapter 223

Set 221

Amazon Interview Experience | Set 221 - GeeksforGeeks


I gave my round 1 amazon. There were two coding questions.
1) Given an integer n in the input, find its next sparse binary numberA sparse binary number
is a number whose binary representation does not contain any consecutive 1s.
For eg.
72 is a sparse binary number, because its binary representation (01001000) does not contain
any consecutive 1s.
17 is a sparse binary number, because its binary representation (00010001) does not contain
any consecutive 1s.
Similarly,
12 is a non sparse binary number, because its binary representation (00001100) contains
consecutive 1s.
43 is a non sparse binary number, because its binary representation (00101011) contains
consecutive 1s.
Now, given an integer n in the input, find its next sparse binary number. n itself can be
sparse or non sparse.
where n >= 0 and n < 2^31 Input 12 Output 16 Explanation 12 is 00001100 and next
sparse no. to it is 16 (00010000). 2) You are given heights of n candles. First day you lit
one candle s Scond day you need to lit two candles Third day you need to lit three candles
.......... ........ till possible. After lighting candles the height of candles deduced by 1 each
day.You can also extinguish any candle you want but only at the end of day. So you need to
tell the maximum number number of days , you can carry on lighting the candles. Example
: there are three candles of heights {2 , 2 ,2 } Answer : 3 1.You light first candle on day
one. heights -> {1,2,2}
2.You light second and third and extinguish first one . heights ->{1, 1,1}
3.You light all the candles. heights -{0,0,0}
Hope it helps aspirants.

559
Chapter 223. Set 221

Online mcq, there were around 20 and 13-14 were from geeksquiz.com
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-221/

560
Chapter 224

Set 222

Amazon Interview Experience | Set 222 - GeeksforGeeks


Aptitude Round: (1:30 hours)
20 MCQs
MCQs on OS, maths aptitutude, and algorithms etc . Few output questions on pointers.
Do have a look at old GATE papers and you may get some seen questions �
2 Coding questions: ( on hackerRank)

• Given an array having positive and negative numbers. Rearrange the array in such a
way that positive and negative numbers are then alternate
Eg – Input : { -3, 1, 5 , 7, -4, -7, -6} Ouptut : {-3, 1, -4, 5, -7, 7, -6} (Question
demand;ed that order of the elements should not change)
A similar question is given in geeksforgeeks with O(1) space but that uses quick sort
concept which is not stable and hence order gets changed in many test cases.
I used simple approach of dividing array in two parts of positive and negative numbers
and then merging them one by one which worked.
• Convert a tree into it’s sum tree
https://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/

Interview:
Round 1:

• Talked something about my projects and introduction.

• A modification of binary search. Eg – 5,5,8,8,9,11,11,13 .. If we give input 8 then it


should return index 1 i.e. index of previous element to the first occurence of the
given input number. Even though if the number is not found then also it should work
like for input = 12 the answer should be 7.

• Create links in an N-ary tree(N not fixed) into a tree where children of every node are
having next pointer connected to it’s siblings in a spiral fashion.

561
Chapter 224. Set 222

Also on level 1 right most node’s next pointer should point to level 2’s right most node
and in spiral way taking upwards root’s next should point to left most child.
I used two stacks to do the problem. The interviewer asked me to code it, I couldn’t
complete but she was convinced with my approach.

Round 2:

• It had easy questions, maybe they wanted to check coding skills for known problems.
And also asked about projects.

• Given two strings then check if they are anagrams or not. (Character set is not just
26 alphabets it can special symbols like $ % ! )
Also if strings have spaces then also they are anagrams like “adf ds” & “addfs” are
also anagrams. I implemented it in Java using HashMap.

• Given two sorted linked lists, merge them into one linked list (Both iterative and
recursive code)

Round 3:

• Tell me about your favorite subjects. I told Data structures & Algorithms , Number
Theory & Cryptography. He asked me about different attacks possible on a website
page. And asked me about what is man in the middle attack. Maybe he just wanted
to check my knowledge on my areas.

• There is a society which has 8 parking slots and there are 7 cars. Each car is supposed
to be parked in some fixed position and one slot is needed to be left.
Example – Let { A ,” “, D, E, B, F, G, C} be the perfect arrangement. But society
people never follow the rule and park in any position. Your work is to design a strategy
which arranges the cars in perfect arrangement at the end of the day having minimum
number of swaps. I was able to solve only this one question in this round. I used to
strategy that :
1. I’ll first find the empty slot and will check if there is some car should be placed in
that place properly and will swap the car.
2. In case the empty slot is at correct position then I’ll find an improperly placed car
and place it at empty slot and then will continue with step 1 iteratively till I get the
perfect arrangement.

Round 4:
This was the round with main person who had come with Amazon team. He was
taking interview since morning and had seen me with my friends discussing about interviews
conducted by him. It was 7:30 in evening when my interview was about to start so while
going to room in lift he asked me that if I know any of his questions. I honestly told that
yeah I know about a few. He asked me about them and their solutions. One was similar to
question 2 of round 1. Another was arranging a list of lists. He said that he will ask new
questions now �

562
Chapter 224. Set 222

• Again a modification of binary search : Ex : {c,f,k,v} Now given an input for element
we have to print the element next to it in array (even if it is not present)

Input Output
a c
c f
j k
v c

• Then he asked me something about my challenging projects. Some project where I


had to do submission in a fixed deadline. Also asked if I take part in online coding
competitions.

Then he asked simple question of finding maximum sum subarray (Kadane’s algorithm). I
did it very quickly so he asked another question to find next greater permutation. I gave
the algorithm and coded it.
Final question he asked that like in github when we save a code it makes commit points. So
if some code has been saved multiple times and has many branches divided and then getting
merged. We have to find the least common parent of two given commit points.
It is similar to a linked list which is getting divided and then getting merged again number
of times.

AA - B - C (divided in two) - D (merged into one)- -- F - G (divided) --- H - I - J


| --------------------- E |------------------K - L
As :
A - B - C - D - F - G --- H - I - J
\ / \
E K - L

I have a table given for parents of a node in chronological order and we have direct access
to parents too.
Ex – In this case
Node – J I H L K G F D E C B A
Parent – I H G K G F D,E C C B A NULL
Given if I/P is (H, L) the output must be G. It seems similar to LCA concept of trees but
it is a slight modification of it. I told about concept of stack that I’ll search for given nodes
and will then store in two stacks and will pop till I get same value from stack. This popping
I’ll do according to information of table of node- parent.
I was not able to complete it but was able to show my approach and I handled the corner
cases. He was satisfied with it.

• I suggest that always listen carefully to interviewer, they’ll definitely help if you have
any doubt. Tell them your approach at least if you are not able to code it. Practice
writing code on paper. Be very careful while you tell about projects. They may get

563
Chapter 224. Set 222

very interested in your projects and it will be very helpful for you. For Amazon Arrays,
Linked Lists and Trees are concepts which are very generally asked. Data structures
& algorithms should be proficiently practiced. Thanks a lot GeeksforGeeks � �

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-222/

564
Chapter 225

Set 223 (On-Campus)

Amazon Interview Experience | Set 223 (On-Campus) - GeeksforGeeks


Firtst Round: 20 mcqs from quants, os, data structures. they were easy.
2 programming questions to be solved in hackkerrank.
First: some people are standing in a queue and only even people are selected. Again out
of these only even people are selected.This happens until we are left with one.
Find out the position of that person in the original queue.
second: We have to find the longest possible interval that can be formed by combining
certain overlapping or constituent events from the given intervals.
people who solved one question were selected to the next round.

Second round:
1. find the area of largest possible rectangle from the given histogram.
2. print the boundary leaves of a binary tree.
some 20 odd people were selected.
Third Round: Technical Interview.The interviewer is my college pass out. He asked me
about my projects very briefly. Then he asked two questions.
1. Given a number give the count of all possible words that can be formed out of it taking
the digits continuously. time complexity O(n).
2. print the level order traversal of binary tree
Fourth Round: Technical interview. three questions were asked
1.find the maximum element in a sorted rotated array.O(logn)
2.print all the pairs of numbers that sum up to K in a given BST. O(n)
3. sort all the one’s and zero’s to opposite sides.O(n)
Fourth round: basic questions on os,dbms, networks.

565
Chapter 225. Set 223 (On-Campus)

Since I had some projects he asked me questions on cloud, and based on my answers the
topic got drifted towards distributed computing, etc.
Next round was HR interview.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-223-on-campus/

566
Chapter 226

Set 224

Amazon Interview Experience | Set 224 - GeeksforGeeks


Here’s my interview experience:
Round 1: Technical
1) A bot has to go from point A to point B. Every time the bot moves, it can take either 1
or 2 or 3 steps. Find the total number of ways in which this can be done.
Input parameters – distance between A and B
Required output – number of ways
Had to write error free code with all edge cases covered. First gave a recursive solution and
finally came up with a dynamic programming solution
2) Implement least recently used cache. This question is there in geeks for geeks. Again had
to write error free code.
3) don’t remember the question. But I just had to come up with an algorithm. Code was
not required.
Round 2: Hiring Manager
1) An array contains ones and zeros. Come up with an algorithm such that all ones come
on the right side and all zeros on left side. You can go through the array only once – no
code required.
2) Code for Singleton design pattern
3) Many behavioral questions like why amazon, why are you leaving your current company,
a situation where you had to go against your manager etc.

Round 3: Technical round


1) Given a list of words, come up with an algorithm such that all anagrams are separated
and placed in there respective buckets. So basically if 2 strings are anagrams of each other,
then both should come in the same bucket.
I used sorting and hashing to solve this problem. Code was not required.
2) Given a string of binary digits (for example 010111101000), partition the string in such
a way that each segment is a power of 5. If it is possible to partition the string such that at

567
Chapter 226. Set 224

the end there are no digits remaining then return the total number of segments, -1 otherwise.
Need to start with 5^1 and go up to the max power of 5 that is less than the string.
Had to write proper code for this problem covering all edge cases.
3) Given n people and n+1 parking slots. Each person has a car and a parking slot allocated.
One night they all go to a party and get drunk. They end up parking their cars randomly.
What’s the best way to go back to the initial configuration (one where every car is in the
right allocated slot). (N+1)th parking slot can be used to swap the cars.
Only algorithm was needed for this problem.
Come up with a sorting algorithm with nlog(n) complexity.
Hint: Use Java’s comparator class to solve the problem.

Round 4: Bar raiser


General behavioral questions like what have u contributed to your current project, one thing
that you don’t like about your project or would like to change etc.
Difference between queues and stacks?
Implement a queue using array such there is no waste of space even after a few enqueue and
dequeue operations.
Hint: Think of circular array.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-224/

568
Chapter 227

Set 225 (For 1 Year


Experienced)

Amazon Interview Experience |Set 225 (For 1 Year Experienced) - GeeksforGeeks


I recently had interviews with Amazon.com, Bangalore.
Here’s my interview experience
Written round:
1) Insert a number at its correct position in a sorted circular linked list.

For eg:
a) Insert 25 in 10->20->30->40->50->10-----
o/p : 10->20->25->30->40->50->10----
b) Insert 60 in 10->20->30->40->50->10-----
   o/p : 10->20->25->30->40->50->60->10-----

2) Convert a Binary Search Tree into a Binary tree where value of


each node in the tree is equal to sum of all nodes greater than it.
3) Clone a Binary Tree with random pointer.
Face to Face Round 1 (Technical ~ 1 hour)
1) Given an array indicating stock prices on each day for a n days. At any given day,you
could:
a) Buy only one stock.
b) Sell any number of stock(s) from what you have bought.
c) Do nothing.
Find the maximum possible profit that you could achieve by doing transactions given the
price array for n days.
2) Given a m*n matrix with LEDs, having each cell representing the state of the LED as
either ON(1)or OFF(0). Given a cell position, state of all the adjacent (in all 8 direction)

569
Chapter 227. Set 225 (For 1 Year Experienced)

cells sharing the same state as the given cell toggles and the effect cascades. Represent the
final state of the matrix.
3) Given a deck of n cards, in each iteration the top card is removed and pushed to the end
and the second card is removed from the deck. For eg: In 1st iteration, 1st card will added
to the end and 2nd card will be removed, again 3rd card will be added to the end and 4th
card will be removed and so on. Find the last card which will be remained.
Face to Face Round 2 (Technical ~ 1:30 hours)
1) Given a boolean matrix with every row sorted, find the row with maximum number of
1s.
2) Given a paragraph and two words A and B, find the minimum distance between a occur-
rence of A and B.
3) Given two valid three letter dictionary words, find the minimum number of steps required
to transform first word to second word. Following are the transformation rules –
a) You can, in a single step, change a single letter in the word.
b) Each transition should result in a valid word. Assume you have been provided a helper
function boolean isValid (String word) which tells you if a word is valid or not.
c) This must be done with minimum transitions.
Example: Transform CAT to TOY. One of the several possible transformations is CAT ->
CAR -> TAR -> TOR -> TOY
4) Sort a linked list which is in alternating ascending and descending orders.
For eg :

10->60->30->40->50->20 to 10->20->30->40->50->60

5) Find the next greater element for each element of an unsorted array.
Some Computer Science Fundamentals now :
1) Explain what happens in the background when you enter “ls” command on unix shell.
2) Difference between process and threads.
3) What is semaphore and mutex. What is Readers-Writers problem? Explain solution with
code.
4) Difference between TCP and UDP.
Few more questions which I don’t remember now.
Face to Face Round 3 Fa(Hiring Manager ~ 1 hour)
1) Tell me about yourself.
2) Why do you want to change your current company? Why Amazon?
3) Tell me about your current Projects. What is your role? Tell me architecture of this
project.
4) Scanned through my resume and asked about everything mentioned in it.
5) Design question : Design an autocomplete library for a keyboard in a mobile device which
does following tasks:
a) Autosuggest words while typing from the inbuilt dictionary.
b) Suggest words based on your previous inputs:
For eg: If you frequently type “Thank you”, so if you type “Thank” then your library should
suggest “you” as first result.

570
Chapter 227. Set 225 (For 1 Year Experienced)

I was asked to tell which data structure would I use and write classes and ethods for this
library.
Face to Face Round 4 (Bar raiser ~ 1:30 hours)
This round was taken by two guys from different teams and both of them were bar raisers
of their respective teams. I was asked to use the whiteboard in this round.
1) Both of them gave a brief description about themselves.
2) Tell me about yourself.
3) Why do you want to change your current company? Why Amazon?
4) Tell me about your current Projects. What is your role? Draw the architecture of this
project.
5) Then one of the interviewer gave a C code snippet and asked me what this piece of code
does?
What the problems that you see in this code?
6) Connect all the siblings node in a binary tree.
Follow up questions:
a) Now connect all the non-siblings nodes as well (basically connect all nodes at the same
level). ( cousins )
b) Now write a recursive solution of the same.
I took a long time in coming up with the recursive solution for this question, but eventually
solved it.
For each question I was asked write production level code.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-225-for-1-year-experienced/

571
Chapter 228

Set 226 (On-Campus for SDE-1)

Amazon Interview Experience |Set 226 (On-Campus for SDE-1) - GeeksforGeeks


Amazon interview experience for SDE-1
1st round (1.5 hrs)
1. given a dictionary of words – {“sam”, “samsung”, “sung”…. }. check if a given string eg.
“sungsamsungsam” can be made from the words in the dictionary.
2. magic number is a number formed by adding one or more powers of 5 .find Kth magic
number. 5, 25, 25+5=30, 125, 125+5=130, 125+25=150, 125+25+5=155,….
20 mcqs having c++, networking, dbms and apti Qs.
1st interview–
0. introduce yourself
1. check if binary tree is BST or not.
2. go from 0,0 to m,n in a 2d matrix. find the maximum possible sum of your path. you
can only move down or right.
3. given an array of integers. form pairs such that each pair’s sum is divisible by k. return
1 if this can be done, else 0.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-226-on-campus/

572
Chapter 229

Set 227 (On-Campus for


Internship and Full-Time)

Amazon Interview Experience | Set 227 (On-Campus for Internship and Full-Time) - Geeks-
forGeeks
This year our college kicked off placement season with the Amazon. We got the job descrip-
tion(JD) before the placement process. We got good news that Amazon have increased total
CTC. With this good news it also added tension and pressure.
Day 1: Coding and aptitude round
Coding round was at 5pm so from morning I had revised very basic things like sorting
techniques, B Tree, AVL tree, finding the power set and some DP questions.
Online coding exam was of two hours and was on HackeRank. There were 20 multiple
choice questions and two programs. Multiple choice questions were GATE type questions
mainly from OS, data-structure , algorithm, database and C. My plan was to attempt these
questions as early as possible and starts programming but questions were lengthy and it
took 30 mins. After 30 mins there were 3 to 4 questions which I skipped and started
programming.
Program 1: Anagram
Two words are said to be anagram when one word can be converted into another
word by shuffling/rearranging characters. Given a set of words find the number of anagram
for each word in given set of words.
Program 2: Find diameter of binary search tree in O(n) complexity.
Given the set of integer values, insert these values in the binary search tree and find
diameter of the tree.
Both the program were easy. I solved program 2 correctly in O(n) and second program in
O(n^2). Result was on next day so all of us were in tension. I could sleep only 3 hours :p.
Day2: Interview process
Interview Round 1:
Question 1: First question in first round of interview was how to insert node in binary search

573
Chapter 229. Set 227 (On-Campus for Internship and Full-Time)

tree using recursion and without recursion. He asked me to write the code of both.
Question 2: Given a binary tree how to find the least common ancestor of two nodes in the
tree.
Question 3: Given a binary search tree find the least common ancestor of the two nodes in
tree. He asked me to write the code of this program as well.
Question 4: He asked about projects it has taken almost 10-15 mins.
Time: 45 mins.
Interview Round 2:
Question 1: He asked me to tell about my self. During introduction I mentioned about my
previous company’s project. He asked next question about that project. I had worked on
that project almost 2 years so I could explain him that project in detail. He asked to write
the code for the Wait And Signal method of the counting semaphore.
Question 2: Given an array with -ve as well as +ve elements find max continues sum.
This question was easy.
Question 3: Given a singly circular link list containing both +ve as well as -ve numbers
find max continues sum. I explained him O(n^2) algorithm but he was asking O(n). I was
not getting answer of this question. I worked on this for 4 to 5 mins but I was not getting
perfect answer so he gave hint by drawing all elements on the circle. As soon as I saw circle
I got answer, I told to break the ring from most -ve number and then use normal algorithm
which was in 1st question. He was not sure about this algorithm he tried to break this by
using 4 to 5 example but he could not. He was happy after this answer because might be
he had another solution in his mind.
Question 4: Given prices of stocks per day find maximum profit you can earn by buying
and selling shares. You can make only one transaction.
This question is easy and from geeksforgeeks.
Question 5: Given prices of stocks per day find maximum profit u can earn by buying and
selling shares. You can make multiple transactions. He asked me to write the code of this
program.
Time: 1 hour 10 mins.
Interview Round 3:
Question 1: He saw my resume and asked me which project I find most difficult. I told
same office project. He asked me which part of that project I find most difficult. I told
part related to the scheduling. He asked me basic questions related the scheduling and
synchronisation.
Question 2: What is copy constructor in CPP
Question 3: Explain the LRU cache technique and how to implement it. I gave various
approaches like array, queue , stack, Link list. finally He agreed on Link List with hashing
approach. All other approaches were O(n^2) solution but Link List with hashing approach
is O(n). He was happy with that answer.
Link-List with Hashing approach:
Size of LinkList will be size of cache. Data in list represent page number of cache. Before
running algorithm we will build Hash Table. Key of HashTable will be page Number and

574
Chapter 229. Set 227 (On-Campus for Internship and Full-Time)

value will be address of the node in link list which contains key. One pointer to Link List
represent the most recently used page(Front of Link List) and one pointer will point to
least recently used page(End of Link List). When new page come then we will get node
containing page number directly from hash table in O(1). After getting that node move
that node to the front of link list which represent most recently used page. If the new page
not present in the Hash Table then update the value in page pointed by least recently used
pointed and move that page to front. and also update key in the hash table.
Here we are building hash only one time and not modifying its values after that.
Time: 50 mins
Interview Round 4:
Question 1: He asked about projects. I explained him my project in details which took
around 10-12 mins. During explanation he was asking like why u have used this approach
why not other and like that.
Question 2: Given n Runways and m Planes. How you will efficiently design this scheduling
problem so that there should not be collision. I explained this by giving view of CPU
scheduling problem and semaphore.
Use priority based Scheduling where priority can be departure time and emergency. Each
plane use runways as below:

Plane Pi:
Wait(S)
Take off(M.E.)
Signal(S)
S=n

Question 3: This was easy question. Given matrix which is sorted, row wise as well as
column wise like below:

01 04 07 09
11 23 45 46
51 56 59 63
70 73 75 79

and key. Find the position of key in given matrix efficiently. I explained the solution which
is in O(log m)+O(log n). He asked me write the code this problem.
Question 4: He asked very basic questions of database. After that he asked me what is
eventual consistency. I didn’t knew answer of this so I told that I don’t know, He again
asked that do u know about NoSQL I said no.
Time: 45 mins
Thanks to my parents, teachers, friends and GeeksForGeeks.
All Practice Problems for Amazon !

575
Chapter 229. Set 227 (On-Campus for Internship and Full-Time)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-227-on-campus-for-internship-and-full-time/

576
Chapter 230

Set 228 (On-Campus for


Internship)

Amazon Interview Experience | Set 228 (On-Campus for Internship) - GeeksforGeeks


Amazon came to our campus a week back and procedure was as follows:
Round-1-
20 easy MCQ
2 coding questions:
(a)- https://www.geeksforgeeks.org/find-next-greater-number-set-digits/ –>even brute
force solution is working.
(b)-Evaluation of post fix expression.-similar to this one http://geeksquiz.com/
stack-set-4-evaluation-postfix-expression.
Note – Only fight for solving atleast one coding question.If you have not done any coding
question then it doesn’t matter how many MCQ you have done you can not qualify for
next round. I had started with coding question and did 1 question and only 10 MCQ and
qualified for next round.
21 candidates were shortlisted.
Round 2(Face to Face)(30 min):
Introduce yourself -(Just a formality)
Asked about test and discussed coding question.(Must solve all coding questions before
appearing in interview).
Then 2nd question –
1- print a binary tree diagonally.I told him the algo within 2 min then he asked me to write
complete code (specially mentioned not pseudo code). It might contain some syntax error
but it was not much of a concern. They only see whether are you able to implement the
algo properly.
Then he told me there was an error in the code and that it doesn’t go correctly to next line.
I told him it’s correct lets run manually and check. The code was correct.

577
Chapter 230. Set 228 (On-Campus for Internship)

2-https://www.geeksforgeeks.org/find-if-there-is-a-sub-array-with-0-sum/
I knew its solution and answered the best solution immediately. He asked me if I had done
the question previously. I told not exactly same but I like competitive coding so I have done
similar question. Then he extended this question and asked to print all sub-array with some
some zero.(write proper code).
Then he discussed corner cases I told some then he gave some hint and after that I got the
idea so, answered all corner cases.
Some questions asked from my friends->
1-https://www.geeksforgeeks.org/write-a-c-program-that-given-a-set-a-of-n-numbers-and-another-number-x-determ
2-https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/(expect inorder and
reverse inorder solution)
3-https://www.geeksforgeeks.org/maximum-width-of-a-binary-tree/
4-https://www.geeksforgeeks.org/next-greater-element/
5-https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
Note- Same questions were asked by the same interviewer to many candidates so it is advis-
able to share questions with friends as they select you for next round only if you have done
both of the questions.
9 people were shortlisted in this round.
Round 3(nearly 2 hours)-
1-Given a stream of number how you will maintain top 10 element. Whenever asked, the
answer should be top 10 element till now. (answered in 2 min using min-heap).
2-https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
very tough question. In 1 hour with the hint of interviewer I was able to answer this.
3- Some basic C questions – What is difference b/w Malloc, Calloc. Scenario when to use
which one.

578
Chapter 230. Set 228 (On-Campus for Internship)

4- Data structure to use for undo and redo in text editor.


I took a lot of time but finally told its answer i.e. stack.
5- Lowest common ancestor of binary tree.(Proper code)
After this round 7 candidates were selected.
All thanks to geeksforgeeks for helping me with my preparation.
All Practice Problems for Amazon !
Top k numbers in a stream

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-228-on-campus-for-internship/

579
Chapter 231

Set 229 (On-Campus for SDE)

Amazon Interview Experience | Set 229 (On-Campus for SDE) - GeeksforGeeks


First Round: 20 MCQs, 2 Coding questions. Platform – HackerRank.
Coding Questions:
1. A magic number is one that can be represented as a sum of powers of 5. For example 30
= 5^2 + 5^1. Given n, return the nth magic number.
2. Given a set of words as dictionary, find out whether a given string can be formed using
any permutation of the words from the dictionary. The words given in the dictionary cannot
be altered, more specifically anagrams of the given words cannot be used to form the given
string,
Technical Interview 1:
1. Given an array which is sorted row wise as well as column wise, how would you find a
given element?
2. Given an n-ary tree, print the spiral traversal of the tree.
3. Given an array, and a number K, find the largest of all consecutive windows of the size
K. For example, for the array [2 , 9, 3, 4, 1, 6] and K = 3,
Output: 9, 9, 4, 6.
4. Given an array, you can only ROTATE the array as many times you want. Return the
maximum of summation of (i*A[i]).
Technical Interview 2:
1. Implement a circular queue using an array of a fixed size. Handle all boundary cases.
This question was followed by some Operating system questions based on it.
2. Given an array, divide it into two subsets such that the difference between the sum of
subsets is minimized. Also, return the subsets.
3. Discussions on the same dictionary problem asked in the online coding round.

580
Chapter 231. Set 229 (On-Campus for SDE)

Technical Interview 3:
1. Given a threaded binary tree with all the threads pointing randomly anywhere, fix all
the threads without using any extra space.
2. Questions on operating system, DBMS, automata theory etc.
Technical Interview 4:
1. Given a binary matrix (A matrix consisting of only 0’s and 1’s), where 1 represents land
and 0 represents water, Find the number of islands.
2. Given a paragraph and a sentence, find the smallest sub-string in the paragraph which
contains all the words in the sentence, return the smallest starting index of the occurrence
of such sub-string if there exist more than one sub-strings of the same smallest length.
Project based questions were also asked in between all the interviews.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-229-on-campus-for-sde/

581
Chapter 232

Set 230 (On-Campus For SDE)

Amazon Interview Experience | Set 230 (On-Campus For SDE) - GeeksforGeeks


Recently Amazon visited our campus and take three rounds for final selection.
First Round: 20 MCQs, 2 Coding questions. Platform – HackerRank.
Coding Questions:
1.Print all possible words from phone digits
Find possible words phone digits
2.A question involving optimization using modified binary search(I do not remember the
entire question).
A total of 10 students were selected after this round.The aptitude were simple but coding
questions were time-consuming.
Second Round(technical):
The interviewer asked me three questions one after another.
First question:
1.print all permutations of a given string.
https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
The interviewer asked me the approach only.
2.print a matrix in spiral order.
https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
The interviewer asked me directly to code.
3.print the left and right view of a binary tree.
https://www.geeksforgeeks.org/print-left-view-binary-tree/
https://www.geeksforgeeks.org/print-right-view-binary-tree-2/
The interviewer asked me the approach but did not tell me to code.

582
Chapter 232. Set 230 (On-Campus For SDE)

It was an easy round and 5 students were selected for Third round.

Third Round(Technical):
1.Write a program to remove the whitespaces from a given string.
First i told him in o(n) time complexity and o(n) space complexity approach but he wanted
o(n) time complexity with constant space complexity. I was unable to do it so he asked me
second question.
https://www.geeksforgeeks.org/remove-spaces-from-a-given-string/
2.Write a program to find the element which is common in all the rows in a two-dimensional
array. I told him using binary search but he wanted more optimized approach but i was
unable to do so.
I did not get selected but Overall it was a good interview experience.
I want to thank geeksforgeeks for such a good and amazing solutions to the back-breaking
problems which helped me in the interview .
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-230-on-campus-for-sde/

583
Chapter 233

Set 231 (On-Campus)

Amazon Interview Experience | Set 231 (On-Campus) - GeeksforGeeks


We had Amazon campus interview in our college offering an internship (performance based
job conversion).

First round(online coding round) :


20 MCQs.
2 coding questions.

1. Given three huge numbers, each represented using a linked list (where each node of
a linked list represents a digit), calculate the sum of the numbers and return back
the number in the form of a linked list. For example, 9->2->3, 4->6 and 2->5->1
representing numbers 923, 46 and 251 respectively. The result should be 1->2->2->0.
This can be solved using stacks.
2. Given a graph, detect if it has a cycle. We can perform a dfs here.

Second round(Technical Interview):


I was asked to explain my work at an internship that I did. I explained for about 10 minutes.
I was then given a binary search tree and asked to form a mirror of it i.e. every parent nodes
left and right child should be swapped. I wrote a simple recursive code for it.

void BST(Node root) {


if (root==null)
return;
Node temp = root.left;
root.left = root.right;
root.right = temp;
BST(root.left);
BST(root.right);
}

584
Chapter 233. Set 231 (On-Campus)

Given a somewhat sorted array where the numbers are in ascending order first and then
follow a descending order, find the index at which the order changes and return the number
at that index. For example, i/p: 1234532, o/p: 5. I wrote down a modified binary search
for it (had to take care of some corner cases). The interviewer was satisfied and I was sent
to the next round.

Third round(Technical Interview):


I was asked to talk about one of the projects. I spoke about an artificial intelligence project
that I did. He asked me some questions based on it. About 15 minutes.
I was asked the same question as the first one in the online round except here I had to add
only two numbers. I told him that but he asked me nonetheless to write the code down and
explain it. I gave him the recursive solution as well as the easier stack-based solution as a
replacement of recursion.
Given positive numbers a1,a2…an, you can sum up the elements in the following way:
1*a(i%n)+2*a((i+1)%n)…+n*a((i+n)%n) where i ranges from 0 to n-1. Find the value
of i at which this sum would be the maximum. For example, 5,6,7 the various sums can be
1*5+2*6+3*7, 1*6+2*7+3*5, and 1*7+2*5+3*6. The answer is 38.
We can solve this in O(n). We initially calculate the sum for i being 0. We make the
following observation.
i=0, sum0 = 1*a1+2*a2+3*a3…n*an.
i=1, sum1 = n*a1+1*a2+2*a3…(n-1)an
sum1 = sum0 – (a1+a2+…an) + n*a1
Generalizing the equation: sumi = sumi-1 – (a1+a2+…an) + n*ai , where i ranges from 1
to n-1. The maximum of the sum0 to sumn-1 is the result.
Next question, you need to create an application which listens to requests continuously. The
application has a common file that it can access. For every request, some information from
the file has to be retrieved and returned back. Would you spawn a new process for each
request or a new thread. And why? I said thread since the main processing to be done is on
a shared resource and by creating threads you do not need make a copy of the file as such
resources can be shared between threads.
What are the scheduling algorithms that you know in operating systems? What data struc-
ture would you use for each of the algorithms. I mentioned the following:
First come First Serve : Queue.
Priority based scheduling : Priority Queue.
Shortest job First: Priority Queue ( this scheduling algorithm boils down to priority based
scheduling)
Round Robin : Circular Queue. Interviewer told me circular linked list suits the purpose
better. I added that circular double linked list would be an even better answer because of
more efficient deletion of an ith node. He told me you can do this operation efficiently in a
single linked list itself. I thought for a while and agreed with him while also showing him
how I would go about doing this operation in a single linked list.
Given a computer with 1Gb ram and a 2Gb ram, the latter one would perform faster. Ex-
plain why would having more amount of ram would – in normal circumstances- fare better
than lesser ram powered computer. Answer : paging. I also told him how in certain com-
putations like external sorting, it would also be more efficient if you have more RAM.
Given a matrix of 1’s and 0’s, where 1 represents an island and 0 water, find the number
of islands formed. The interviewer was expecting me to come up with a dfs solution similar

585
Chapter 233. Set 231 (On-Campus)

to this one. https://www.geeksforgeeks.org/find-number-of-islands/ (Unlike the problem


given in link, the 1’s can be connected only horzontally or vertically). But I had a quick
union find(disjoint set problem) solution in mind. Solution : http://ideone.com/AzvU8m

Fourth round(Technical Interview):


I was asked about my internship work, again. I described the same one as I did in the first
round. He asked me some questions based on it. We spent about 20 minutes on it.
Print the top view of a binary tree in order, from left to right. I took some time to figure
it out. As I was arriving at the solution I kept explaining it out loud. I had previously
done a problem on printing right view of a binary tree which had a similar approach. https:
//www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
Given a number n, print all the squares of numbers such that the square is less than equal
to n. For example, if n is 30, o/p: 1 4 9 16 25. Do this without using *,^ or division
operations.
If we observe the sequence we get from the output, to arrive at the next number in the
sequence, we add the next odd number. So, 0+1=1, 1+3=4, 4+5=9, 9+7=16 and so on.
I have covered almost all of the questions asked to me. I had to wait for more than a week
for the results. I got selected �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-231-on-campus/

586
Chapter 234

Set 232 (SDE-1 for 1 Year


Experienced)

Amazon Interview Experience | Set 232 (SDE-1 for 1 Year Experienced) - GeeksforGeeks
Interview 1:
Before the interview began we were asked to solve 6 questions

1. Write a function to swap a number in place without temporary variables.


2. Find out if number is power of 2.
3. Find the least common ancestor of 2 nodes in a BST.
4. Write a method to replace all spaces in a string with ‘%20’.
5. Check if binary tree is balanced.
6. Implement an algorithm to find the nth to last element of a singly linked list.
7. Assume you have a method isSubstring which checks if one word is a substring of
another. Given two string write code to check is s2 is a rotation of s1 using only one
call to isSubstring (i.e. “waterbottle” is a rotation of “erbottlewat”)

In the first interview i was asked how i solved Q4) replace all spaces with ‘%20’ and Q6)
nth node from the end of a linked list.
and then we discussed in details about a project I did with my previous employer.
and then He asked a few questions ->
Q1) Dynamic Programming | Set 21 (Variations of LIS) – GeeksforGeeks -> 1. Building
Bridges: Consider a 2-D map with a horizontal river passing through its center. There are
n cities on the southern bank with x-coordinates a(1) … a(n) and n cities on the northern
bank with x-coordinates b(1) … b(n). You want to connect as many north-south pairs of
cities as possible with bridges such that no two bridges cross. When connecting cities, you
can only connect city i on the northern bank to city i on the southern bank.
Q2) Write a C program to print all permutations of a given string – GeeksforGeeks -> Print
all permutations of a string

587
Chapter 234. Set 232 (SDE-1 for 1 Year Experienced)

Q3) Given the arrival and departure time of various trains in a station. Calculate the
minimum number of platforms required such that no train has to wait for another train to
vacate the platform.
The question basically means calculate the maximum number of trains that would be present
in the platform at any given time.
Answer
sort the arrival time and sort the departure time, keep a count initialized to 0. compare the
first element of the arrival time with the first of departure, increase the value of count if the
value at current Index at arrival is less than the value index at departure and increment the
arrival index, and vice versa. Keep the maximum count that you see.

Round 2
Q1) given the x,y,z coordinates of a billion stars (basically the entire array can’t fit in the
RAM) calculate the k closest.
Answer -> use a max heap that contains the k minimum distances.
Time-> n(log k)
then the question was changed to -> now that we have several computers which can combine
to fit the entire set of stars, how will you then solve it?
Answer-> use selection algo (similar to step 1 of quick sort) to find the k closest stars in
each of the computers. Time -> O(n) and then use the k in the those m computers to find
the minimum k. One way is to sort all them individually. and then create a min heap to
calculate k minimum.
O(k^2 log k)
Q2) Symmetric Tree (Mirror Image of itself) – GeeksforGeeks -> How to check if the tree
is the mirror of itself
Then the question was extended to a n-ary tree.
Answer -> Please read the above link before reading this answer– We create a the n ary
tree like this->

struct node{
int data;
vector < struct node* > child;
}

then we have the number of children of each node as nodeName->child.size();


we use it to compare the first child of the node with the last child, 2nd with 2nd last
and so on and follow the steps which were written in https://www.geeksforgeeks.org/
symmetric-tree-tree-which-is-mirror-image-of-itself/

Round 3
Q1) Write a C code to evaluate an expression tree.
Answer-> It has to be done in a post order traversal method, since the value of the left
subtree is independent of the right subtree.
Q2) Articulation Points (or Cut Vertices) in a Graph – GeeksforGeeks -> Check for Artic-
ulation points

588
Chapter 234. Set 232 (SDE-1 for 1 Year Experienced)

Q3) Given a stream of number, like 1,3,5,4,6,9 print 1,3-6,9


Answer-> create a hash map that contains the value of the ending index of the previous
sequence.

For example
when we get 1,3,5 the hash map is
1 0
3 1
5 2

key is the number and the value is the index where it occurs.
when we get 4, we have to check for the index of 3 and 5. (One above and one below)
the value at 3 is 1 and 4’s index is 3, so they can’t be paired.
We then check for 5. 5’s index is 2 and 4’s is 3, since they are together, they can be paired.

1 0
3 1
5 2-3
4 2-3

and then we check for 3 again, 3’s index is 1 and 4’s index is 2-3, so they can match

1 0
3 1-3
5 1-3
4 1-3

We go on. I don’t think I answered the questions the way it was asked, but he seemed ok
with the answer I gave.
Next he modified more to include distributed systems in it. And asked me if there were
several systems which received the input in round robin manner, how would I implement
the above algorithms. I had no idea about this.
After round 3, I was called by Amazon and told that my first two rounds were positive but
round 3 wasn’t. Round 3 was the hiring manager round, and he wasn’t happy that I had
little idea about RAID ( Standard RAID levels – Wikipedia, the free encyclopedia )
So I had another hiring manager round.
Round 4
https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/
Find a pair with a given sum in a bst
more questions on what happened in Round 3 and why I want to leave my current firm.
Round 5 (Bar Raiser)
Questions like
1) tell me a time when you had a different opinion than the rest of the team.

589
Chapter 234. Set 232 (SDE-1 for 1 Year Experienced)

2) tell me a time when you were thinking that the problem is something else, but it turned
out to be something else
3) tell me a time when your opinion were discarded.
4) tell me a time when you had to work on a very short notice.
Coding questions-
1) given that we can form packs of 6,9 and 20 pens. Given a number x, calculate if we can
form combinations of packs to form those many pens. Eg 24 pens can be formed by having
2 packs of 9 pens and 1 of 6 and 23 pens can’t be formed.
Answer
Dynamic Programming with the recursive function
DP[i]=DP[i-6]||DP[i-9]||DP[i-20];
2) Design an escalator system. Which classes would you make, etc.
After Round 5, they didn’t find me a cultural fit so they conducted a Round 6.
Round 6
Questions like- tell me something about yourself,
a time when you helped someone
A time when you shared a different opinion from your manager.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-232-sde-1-for-1-year-experienced/

590
Chapter 235

Set 233 (1 Year Experienced for


SDE-1)

Amazon Interview Experience | Set 233 (1 Year Experienced for SDE-1) - GeeksforGeeks
I recently had interviews with Amazon.com, Bangalore.
Here’s my interview experienceCoding round (1 hour):
1. Find minimum number of coins that make a given value
Given a value V, if we want to make change for V cents, and we have infinite supply of each
of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make the
change?
2. Suppose you have given two strings S1 and S2. Find out if S1 is substring of S2. If S1 is
present in S2 return starting index of S1 in S2 and if not present return -1.
3. https://www.geeksforgeeks.org/find-two-rectangles-overlap/
Face to Face Round 1 (Technical ~ 1 hour)
1. https://www.geeksforgeeks.org/reverse-alternate-k-nodes-in-a-singly-linked-list/
2. https://www.geeksforgeeks.org/length-of-the-longest-valid-substring/
Face to Face Round 2 (Technical ~ 1 hour)
1. https://www.geeksforgeeks.org/design-a-data-structure-that-supports-insert-delete-search-and-getrandom-in-con
2. https://www.geeksforgeeks.org/bottom-view-binary-tree/
3. https://www.geeksforgeeks.org/dynamic-programming-set-18-partition-problem/

Telephonic Round 3 (Hiring Manager ~ 45 minutes)


1. Tell me about yourself.
2. Why do you want to change your current company? Why Amazon?
3. https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/

Telephonic Round 4 (Bar raiser ~ 1.30 hour)


1. He gave a brief description about him.
2. Tell me about yourself.
3. Why do you want to change your current company? Why Amazon?

591
Chapter 235. Set 233 (1 Year Experienced for SDE-1)

4. How Have You Gone Above and Beyond in Your Work?


5.Tell me about your current Projects. What is your role?
6. Some basic OS concepts
7. Then he gave a C code snippet and asked me what this piece of code does? What the
problems that you see in this code? Fix the bug in the code.
8. Write your own function to take string as input from user.

For each question I was asked to write production level code. I had to wait for 2 days for
the results. I got selected. Thank you geeksforgeeks !!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-233-1-year-experienced-for-sde-1/

592
Chapter 236

Set 234 (For SDE-II)

Amazon Interview Experience | Set 234 (For SDE-II) - GeeksforGeeks


Round 1:
a) Twitter design considering following functionalities:
– Post tweet
– Get the top tweets from the followers
b) Parking Lot design
Round 2:
a) Common elements from n sorted arrays
b) Given list of dictionary words. Find minimum number of trials to reach from source word
to destination word where word traversal is allowed through 1 letter difference.

Eg: List of words - {ABC, ACD, BBC, BCC, BCD,


BDC, ABD, BDE, AGF}
ABC -> BBC -> BCC (3 steps)
ABC -> ABD -> ACD -> BCD -> BCC (5 steps)

Round 3:
a) pow(a,n) function – recursive, iterative
b) Given list of cities, find the number of tour combinations (not permutations)
c) BookMyShow design
Round 4:
a) Questions on Projects
b) next hight number with same digits
Round 5:
a) Given stream of numbers, at any point of time, need to print first non-repeating digit
b) News paper & Magazine subscription design.
All Practice Problems for Amazon !

593
Chapter 236. Set 234 (For SDE-II)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-234-for-sde-ii/

594
Chapter 237

Set 234

Amazon Interview Experience | Set 234 - GeeksforGeeks


location: Hyderabad QCity.
Hiring for : Chennai Kindle team.
Position : Software Development Engineer.
Time: 10 AM started with written test.
1. https://www.geeksforgeeks.org/boggle-find-possible-words-board-characters/
2. http://algorithms.tutorialhorizon.com/find-the-deepest-node-in-a-binary-tree/ Just
deepest nde
————————————————————————————————————————
—-
Time: 11 AM:
Followed by explanation about my approach in solving the written test questions.
————————————————————————————————————————
—-
After lunch 2 PM.
1. Add Two numbers present in two files and write it another file. numbers are too large
not fit in integer bounds.
2. Design a DS for efficiently allocating/freeing Memory. Memory Management DS.
3. Design Hotel reservation system.
————————————————————————————————————————
—–
Time 4 PM.
Hiring Manager round
Behavioural Questions like 1. Big Mistake I have done 2) Learning 3) Why I am switching
1. Infix to post fix conversion ( I have not done earlier this question but tried )
Thought I am gone but later HR called me for next round . I think he liked/convinced my
approach.

595
Chapter 237. Set 234

———————————————————————————————————-
Senior Manager round
Time 5-30 PM.
1. 1 byte stream which contains single byte character and double byte character
single byte can by identified by checking MSB as 0. and double byte MSB as 1.
you are at end of a character. find the previous character ( is single byte or double byte)
solved the above problem by taking Manager help
————————————————————————————————————————
———–
HR told me that HR from Chennai will contact me.
I waited 2 days and sent mail to HR about the hiring status. He replied saying that “Working
on updated. Will get back to you”.
1 week and 1 day over no idea about the hiring status.
————————————————————————————————————————
———————–
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-234/

596
Chapter 238

Set 235 (For SDE-II)

Amazon Interview Experience | Set 235 (For SDE-II) - GeeksforGeeks


GeeksOfGeeks has helped me a lot, so, thought of making a little contribution from my side.
Amazon Interview for Position SDE II
Round 1:
The interviewer explained about his role and team. He asked questions below,

1. Tell me about yourself and a little bit about your project


2. Design a software to make a reservation at a chain of restaurants. All restaurants are
in same Timezone. (He just wanted the class diagram)

Round 2:
Again, the next interviewer explained briefly about himself and asked about me and my role
in the current project. He asked more details about current projects

1. Given an array of stock values of a company. Find out the time when a user would have
bought the stock and sold the sock. Basically find the maximum positive difference of
any two given elements in an array?
2. Told me to write this program.

Round 3:
Interviewer introduced himself and asked about my details and my current projects.

1. You have a BST and you need to assign an appropriate value to neighbor of all nodes
(Explained in below example)

Node Structure
node {

597
Chapter 238. Set 235 (For SDE-II)

node leftChild,
node rightChild,
T data,
node neighbor
}
A
/ \
B C
/ \ \
D E F
Based on above tree,
Node: Neighbor
A: NULL
B: C
D: E
E: F
Told me write a program (It’s suppose to be recursive method)
Round 4:

1. Given a price rules of parking and start time and end time of parking. Calculate the
price (Below is the table of price rule) Come up with data structure you can store
these price rules PriceRule

Price Rules:
On Weekday On Weekend
Hours Price Hours Price
0–2 $5 0–2 $8
2–6 $10 2–6 $13
6 – 12 $15 6 – 12 $18
12 – 24 $20 12 – 24 $25
The interviewer asked me to come up with an architecture for a system which shows the
parking spaces available near customers’ location in a mobile app.
Round 5:
This round has been just behavioral questions,

598
Chapter 238. Set 235 (For SDE-II)

1. What would you do when the manager disagrees with your decision even though you
have a valid point?
2. What are the challenges you have faced in your career? How did you resolve it?
3. Explain the instance where you have contributed towards making the improvement in
your project or team.
4. What would you do when your peer disagrees with your decision? How would you
resolve the conflicts?

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-235-for-sde-ii/

599
Chapter 239

Set 236 (Rounds 2 and 3)

Amazon Interview Experience | Set 236 (Rounds 2 and 3) - GeeksforGeeks


Round 2: Paper written coding
1) Given an unsorted array with a group of characters taken from the user. Find the first
occurrence of non repeating character and print the character(s).
2) Write a program to find whether the two given two strings are ANAGRAMS or not. (
built-in function should not be used )
3) Find the number if words in a given paragraph and find the required word needed by the
user and replace that word with an other word given by the user.
ROUND 3: TECHNICAL HR AND HR
*) Tell about your self
1) Given an string. Find the number of times a given character from the user is repeated in
the array.
2)Given two arrays in sorted manner, you need to multiply one two numbers i.e., one from
each such that the pair is like the first number is taken from first array should be the largest
number and the second number is taken from second array should be the smallest number.
The desired product and the values in the array should be taken from the user first and
accordingly produce the result.
3) what will you do if your facebook page doesn’t get logged in? Derive the maximum
number of test cases that you will perform to check the login page of facebook.
4) what will you do if you set the alarm clock to ring at a particular time and it doesn’t
ring? Derive the test cases and try to debug the issue
5)what will you do to check whether the facebook page UI is working perfectly on all sorts
of screen sizes and browsers. Derive the test cases
6) What will you do if you have an issue in sending a mail after clicking the SEND button.
Derive the test cases.

600
Chapter 239. Set 236 (Rounds 2 and 3)

7) what are the test cases to check whether your whatsapp is running properly or not ?
8) write a program to sort the numbers using singly linked list.
9) what will you do to check the response time of a webpage and also the derive the test
cases if the webpage doesn’t load completely.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-236-round-2-and-3/

601
Chapter 240

Set 237 (For Application


Engineer)

Amazon Interview Experience | Set 237 (For Application Engineer) - GeeksforGeeks


1) Written Test on Unix Shell Scripting
1. write a script/command to find files older than 7days and zip them and move to specific
folder.
2. Asked write some examples on CUT
3. sked to write some examples on awk

2) Written test on core java


1. Binary search
2. Hash map program
3. Psudo code for binary search algorithm
Thanks and Regards
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-237-for-application-engineer/

602
Chapter 241

Set 238 (For SDE)

Amazon Interview Experience | Set 238 (For SDE) - GeeksforGeeks


First round was HackerRank test:
Your job is to write a method that will take a stream of integer values, and put them into a
tree while counting the number of times each value is seen. The first value from the given
list should occupy the root node. Then you need to traverse the tree breadth-first to generate
a string representation of the tree. Values are to be inserted into the tree in the order that
they are given.
Second Round was an Event at a hotel where 5 intervewers each took about 45 min for a
session of Q &A:

1. Find the missing number in the increasing sequence. i.e. :


input: 1 2 3 5 6 7 output: 4. Tell the complexity.

2. Tell YES or NO if two binary trees have the same numbers (could be of different
structures, non-unique elements)
3. Find the nth from frequent character in string (any character)
4. TPM guy: Design an elevator system (one lift, maybe more)

5. (a) Design a Messenger like Facebook or Whatsapp


(b) Given 1M U.S. phone numbers (10 digit), choose a data structure/method for
the most efficient search. Tell the complexity.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-238/

603
Chapter 242

Set 239

Amazon Interview Experience | Set 239 - GeeksforGeeks


I recently attended an interview with Amazon at WTC, Bangalore
Round 1 – Written (write code for any 2 out of 3)
1. Given an array of elements which is first increasing and then decreasing, find the maximum
element in the array.
Points where based on how we handle the corner cases like what if we have only two elements
in the array.
2. Given a string of parentheses, find if the expression is balanced or not ?
3. Given a binary tree, find the level which has maximum number of nodes, consider root
as level zero
People were asked to write 2 or 3 lines about the approach they follow, the space and time
complexity, data structures used to solve the problem
I attended 1 and 3 – scored 7/10, on my further analysis I had failed to handle the corner
cases in question.3
Round 2 – Face to Face discussion
1. Write program to escape URL string, say you are given a URL string, you have to replace
“(space)” -> “%22”
“(double quotes)” -> “%d”
say http://www.google.com/hello world” -> http://www.google.com/hello%22world%5d
what is the space and time complexity, can we accomplish the solution with only one traversal
of the string ?
2. Given a million of points(x,y) in a two-dimensional plane and a utility function to compute
the distance from Origin, how will you return the smallest k distances from the Origin.
Answer : Use Comparator and sort the array, return first K elements from the sorted list
Follow up: why do we need to keep all elements in the sorted list, how can we maintain only
k elements in the sorted list ? Time, space complexity of the solution. time complexity of
the problem.

604
Chapter 242. Set 239

Round 3 – Face to Face discussion


3. Implement hash map of your own
Follow up:
1. How to handle a collision situation
2. How can we reduce the time complexity of rehashing process ??
Gave my best in this round but couldn’t clear it.
Amazon people were friendly all during the process.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-239/

605
Chapter 243

Set 240 (1.5 Year Experienced


for SDE-1)

Amazon Interview Experience | Set 240 (1.5 Year Experienced for SDE-1) - GeeksforGeeks
I recently had interviews with Amazon. Here’s my interview experience
Coding round on Hacker rank (1 hour):
1. Find minimum number of coins that make a given value
Given a value V, if we want to make change for V cents, and we have infinite supply of each
of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make the
change?
2. Suppose you have given two strings S1 and S2. Find out if S1 is substring of S2. If S1 is
present in S2 return starting index of S1 in S2 and if not present return -1.
3. https://www.geeksforgeeks.org/find-two-rectangles-overlap/
Face to Face Round 1 (Technical ~ 1 hour)

1. LCA in a BST. Lowest Common Ancestor in a Binary Search Tree …


2. Swap two nodes in a singly linked list.Swap nodes in a linked list without swapping data

3. Building bridges problem Dynamic Programming | Set 21 (Variations of LIS … algo-
rithm – Building bridges problem – how to apply longest …
4. Implement a data structure with push() , pop() , find minimum element in O(1). De-
sign and Implement Special Stack Data Structure | Added … ( For each
question they asked me to write the code and also tell all test cases.)
Face to Face Round 2 (Technical ~ 45 mins)

1. Find the number of islands.Find the number of islands – GeeksforGeeks

606
Chapter 243. Set 240 (1.5 Year Experienced for SDE-1)

2. Calculate how many paths exist from top left to bottom right corner of matrix with cost
= k. Number of paths with exactly k coins – GeeksforGeeks (For each question
they asked me to write the code and also tell all test cases.)
Face to Face Round 3 with Hiring Manager (Technical ~ 1hour)

1. Tell me about yourself.


2. Given 4 digits , find the sum of all the 4-digit numbers that can be formed using these 4
digits.SOLUTION: Find the sum of all four digit numbers that can …
3. Merge two balanced BST’s.Merge two BSTs with limited extra space – Geeks-
forGeeks (For each question , code and a dry run was expected)
4. Tell me a situation when your manager disagreed with you.
Telephonic Round 4 (Technical ~45 mins) ( held after some 3-4 days )
This interview will is taken by some senior guy who doesn’t belong to the team you are
hired for.
1. He gave his brief introduction and then asked mine.
2. Why do you want to leave the current company
3. Why Amazon?
4. The most challenging project/thing ever done. Why it was challenging . How would
u do the same project/thing again. i need to tell some improvements in previous ap-
proach/design/code.
5. Tell me a situation when your manager disagreed with you / or had a different opinion
6. Tell me a situation when there was a time constraint for project delivery and how you
handled it.
7. Find an element in a rotated sorted array.Search an element in a sorted and rotated array
… (The collabedit link was shared to me through the mail but it didn’t work during the
interview . So the interviewer asked me to just explain the logic)
Some suggestions:
1. Practice Trees , Linked lists , DP , Arrays , Strings , Stacks , Queue , Hashing , Heaps ,
Backtracking and basic Graph questions from gfg. The questions are asked as it is.
2. Don’t just look at the solutions , write the whole code on paper while practising.
3. In the interview , start from the less optimized solutions and then move to more optimised
solutions.
4. Practice the latest 20-25 sets from the Amazon Interview sets in gfg
5. Ask questions / take hints from the interviewers.They are co-operative.
6. Prepare behavioural questions like why leaving , why amazon , situation against manager
etc. Have answers to these questions ready .Practice speaking them to yourself before the
interview, otherwise you might get nervous.

607
Chapter 243. Set 240 (1.5 Year Experienced for SDE-1)

A big thanks to gfg for making everything easy.


All the best folks! Prepare well.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-240-1-5-year-experienced-for-sde-1/

608
Chapter 244

Set 241 (1.5 years experience)

Amazon Interview Experience | Set 241 (1.5 years experience) - GeeksforGeeks


Round-1 (World Trade Centre, Bangalore) – Technical
1. Given an array that is first increasing then decreasing, find an element in it.
Example: arr[] = { 2,6,8,9,15,20,18,16,12,7,1}; x = 12, Find x.
2. Print left view of a binary tree.
3. Given an array that contains only 1, 2 and 3. Sort the array. He asked me to write code
for two methods – counting method and Dutch National Flag algorithm.
4. There is a irregular, haphazard, shapeless cake that needs to be divided equally among
n people. Say you are one among them. How do you achieve consensus?
Round -2 (Q-city, Hyderabad) – Bar raiser
1. About projects, your contribution, your roles and responsibility, challenges faced etc.
2. Why amazon?
3. Given a pattern containing only Is and Ds. I for increasing and D for decreasing. Devise
an algorithm to print the MINIMUM number following that pattern. Digits from 1-9 and
digits can’t repeat.

Example:
1. Input: D Output: 21
2. Input: I Output: 12
3. Input: DD Output: 321
4. Input: II Output: 123
5. Input: DIDI Output: 21435
6. Input: IIDDD Output: 126543
7. Input: DDIDDIID Output: 321654798

Round – 3 (Q-city, Hyderabad) – Technical


1. Given pre-order traversal of a BST. Construct the BST.

609
Chapter 244. Set 241 (1.5 years experience)

2. Given a m*n matrix. m and n can be huge. We need to query the matrix for sum of
submatrices. Input will be the top-left and bottom-right co-ordinates. We need to return
the sum of submatrix in O(1) time.
Solution: Do column wise sum of the matrix and store it. Again, do the row wise sum and
store it.
Round – 4 (Q-city, Hyderabad) – Managerial
1. About projects, your contribution, your roles and responsibility, challenges faced etc.
2. Given m sorted arrays, merge it into one array.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-241-1-5-years-experience/

610
Chapter 245

Set 242 (1 Year Experience)

Amazon Interview Experience | Set 242 (1 Year Experience) - GeeksforGeeks


Telephonic round: (1 hour)
It is started with interviewer introduction followed by my introduction. Need to write the
code in shared docs. They shared CollabEdit link before interview.

1) http://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/
2) http://www.geeksforgeeks.org/given-an-array-of-numbers-arrange-the-numbers-to-form-
the-biggest-number/
After one week, they called me to Hyderabad office for on-site interview. They have arranged
everything.
Every round started with interviewer introduction followed by my introduction.
End of every round, interviewer asked “Do you have any questions”?

Round-1: (1 hour, 2 interviewers)


1) Questions related to my exp, projects and my role, architecture of my projects
2) can we construct a tree with single traversal? NO
which traversal is must needed ? INORDER. Why?
Then he asked https://www.geeksforgeeks.org/construct-a-special-tree-from-given-preorder-traversal/
2) http://www.geeksforgeeks.org/next-greater-element/

Round-2: (1 hour 45 min, 1 interviewer)


1) Multiplication of two numbers without using multiplication operator.

611
Chapter 245. Set 242 (1 Year Experience)

2) He explained a situation like you have super market and items sold every day, blah blah…
finally the question becomes as follows
Given a file which contains one product id per line(millions of products) which are sold and
some product ids may repeat. We need to find how many items are unique in that file. (i.e
sold uniquely)
3) Cycle in a LL
4) How we can implement a queue with one pointer
5) Given a key , search the key in the LL, if exists swap the values of prev node and current
node. After I given solution then he asked me swap nodes NOT values.
6) Given a binary tree, construct a MIRROR of that tree.
So many behavioural questions around 10 -15 questions. some are
Give me an instance

• clashes with Teammate


• when you shared your team mate burden
• your PM doesn’t agree with your opinion
• if time is less for the project, how you will handle
• What you have done to increase team efficiency
• big mistake you have done in the team
• your are moved to new team but you dont have any exp with that technology. how
you will handle?
• you team mate is not working properly because of that you are working more time.
how you will handle the situation?
• you came with idea but team doen’t agree
• What are the areas/techonoloies which you want to improve?
• blah, blah, … so many

Round-3: (1 hour, 2 interviewers)


They said that first we will go with technical questions then related to exp and projects.
1) Given an array find the missing numbers. Array is not sorted and range of elements also
not known.
Ex: input: a[]={1,100} output: 2,3,…99
input a[]={100,1} output: 2,3,..99
Then they asked algorithm for

• if only one number missing and range 1 to n


• if array sorted and one number missing

2) Given a two nodes in a binary tree, check those are cousins or not. Cousins means both
have to present in same level but doesn’t have a common parent.

612
Chapter 245. Set 242 (1 Year Experience)

They wants within a single traversal of a tree we need to find. (2 traversal of a tree also not
allowed. I have done in two traversal � )
They given hints and finally we solved it.
3) Related to heaps

• how you will insert a value, what is the time complexity


• how you will delete a value, what is the time complexity
• how you will construct a heap with a given array, what is the time complexity

Round-4: (1 hour, 1 interviwer)


He is senor most guy. I felt a little bit uncomfortable.
1) Asked about current projects and my role and related to exp.
2) He explained a scenario as follows:
Amazon has so many products which are selling outside. Given a millions of products and
he can tell how to construct a URL with product id to get the product details page which
contains info about product, ratings and commnets, blah blah.
Ex: if product id is 123456 then the URL becomes www.amazon.com/product/123456
Then questions are as follows

• Retrieve the rating for each product(ex:123456) which is present in that page (ex:
www.amazon.com/product/123456
• After finding ratings for every product(millions of products). Give an algorithm to
find top 10 rated products. Asked me to write production level code NOT pseudo
code.
• Then he extended if product ratings are same (it may occur for some product) then
we need to consider the product which has more number of comments
• Time complexity for above cases

3) Why you want to leave current job?

Suggestions:
1) Need to cover (order is high to low priority): Trees, Heaps, sorting and searching,
LL, Stacks, Queues, strings, DP, Greedy, Divide and conquer, hash map and collisions,
recursion and back tracking, bit manipulation, basic graph algorithms, OOD, scalability
and memory units, any missing topics.
2) You sholud know the time complexity for STL data structures.
Ex: For hashing, we will say we can find a value in O(1) but if we are using C++ STL, map
was implemented with Balanced BST so it will take O(logn).
3) You MUST prepare some beheaviroual questions, atlest standard quesitons like Why
Amazon? Why do you want to live?

613
Chapter 245. Set 242 (1 Year Experience)

4) Practise on paper because you need to write on paper in all rounds of interview.

All Practice Problems for Amazon !


Largest Number formed from an Array

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-242-1-year-experience/

614
Chapter 246

Set 243 (2.5 Years Experience)

Amazon Interview Experience | Set 243 (2.5 Years Experience) - GeeksforGeeks


Coding round (1 hour):
1. http://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
2. http://www.geeksforgeeks.org/sum-of-two-linked-lists/

Face to Face Round 1 (Technical ~ 1 hour)


1. Introduce yourself and give me a brief about what projects are you doing currently?
2. What was the challenge you have faced in your current project?
3. Given a running stream of integers. I need to find the median of the running stream. I
gave solution using heaps. He was interested in the approach using tree, after a hint i was
able to solve it using tree. He was convinced by my approach
4. Design a data structure in which the operations like insert , delete and finding minimum
element should be done in O(1) time complexity. I told him that i have already done this
question so he was just interested in logic.

5. Given n non-negative integers representing an 2-D elevation map where the width of each
bar is 1, i need to compute how much water it is able to trap after raining.

Input: arr[] = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]


Output: 6
|
| || |
_|_||_||||||
Trap "1 unit" between first 1 and 2, "4 units" between
first 2 and 3 and "1 unit" between second last 1 and last 2

615
Chapter 246. Set 243 (2.5 Years Experience)

Face to Face Round 2 (Technical ~ 1 hour 10 min)


1. Introduce yourself and tell me the most challenging project you have done in your career.
Lots of discussion on project part and challenges i have faced.
2. Given an unsorted array which contains unique numbers from 0 to 999 and size of array
is 1000. At one of the index the element has been replaced by some other element. I need
to find the original element. Only logic was required.
3. An infix expression is given and i need to evaluate this expression. I told him that this is
standard question, so he just asked me the logic and ask me to convert the infix expression
to post fix expression.
4. An binary tree is given. He asked me to serialize and deserialize the given binary tree. I
gave him the approach using pre order traversal and store the elements in array and using
another array which will store whether a node element is leaf node or internal node. He was
convinced with the approach. Then he asked me to write the code for the same logic.
5. Discussion on what data structure i will use to implement recommendation engine. e.g.
if someone buy mobile from Amazon, it should recommend the ear phones, power bank etc.
It was a good discussion.

Face to Face Round 3 (Bar Raiser ~ 1 hour 30 min)


1. Trapping rain water question was asked again. I did not tell him that i had already done
this question in my first interview round. Eventually he came to know that i had done this
question already. So he asked me another question.
2. Given a 2-D plane and number of points are given on that 2-D plane which are represented
by its (x,y) co-ordinates. So i need to find the maximum number of points which can be lie
on a single line.
Answer : I gave the solution using hashing, i calculate the slope using any two points, now
one by one checks the slope with other points if slope matches i will increase the count for
that particular slope in hash map. Now i will traverse the hash map and find the maximum.
Time complexity O(n2 ).
Then discussion happens on what if slope comes out to be something that can even not be
stored in type “long double”, what to do then.
3. LRU cache implementation. I told him that i knew the answer already. So he asked me
a different question.
4. Given an array of integers. I need to modify the array so that each index of array contains
product of all elements except for the its own index element. Twist is that i need to do it
without using divison(/) operator. I was able to solve it with a little hint.
5. Given a post order traversal of a binary search tree. He asked me to write a clean code
to create a BST using the given post order traversal and return the root of the BST.
6. Given a stream of characters which can contain only alphabets [a-z]. I need to find the
whether there is a duplicate element present or not and accordingly return true or false. He
was interested in the worst case time complexity.

616
Chapter 246. Set 243 (2.5 Years Experience)

Telephonic Round 4 (Hiring Manager ~ 1 hour)


1. Introduce yourself and give me a brief career background of yours.
2. Why you have left your previous company?
3. Why you are leaving your current company so early?
4. Why Amazon?
5. What is the most challenging thing you have done in your entire career? Give me the
implementation details, what was the situation and how have you handled it?
6. Tell me a situation when you have suggested your manager a better idea of solving a
problem and he has to go back and used your idea and done the things again.
7. Tell me a situation when your manager has disagreed to your ideas and why?
8. Given a sorted and rotated array. I need to find the search the given element in this
array. Expected time complexity was O(log n).

TIPS
1. Practice to write the code using pen and paper.
2. Keep trying to solve the problem, they will definitely give you hints wherever you stuck
and you can capitalize on those hints to solve the problems.
3. Be honest with the interviewer.

Amazon people were friendly all during the process.


A Big thanks to geeksforgeeks for making everything easy.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-243-2-5-years-experience/

617
Chapter 247

Set 244 (For SDE-1)

Amazon Interview Experience | Set 244 (For SDE-1) - GeeksforGeeks


ROUND 1 (Telephonic, 70 mins):
1. Given an array, print the greatest element on right side, for elements having no greater
element print “-1”..
2. Given a binary tree, print its boundary traversal..
3. Given a m*n matrix, find the number of paths to reach m*n from 1*1..
After Round 1, I was asked for In House Interview SDC Hyderabad.
ROUND 2 F2F (60 mins):
1. Given a mountain array and some obstacles in array, check if there is a way to reach the
end cell from beginning cell..
2. Design a phone book, make search as efficient as possible.. Only approach was required
on how will we store multiple numbers, multiple websites, multiple email ids etc and how
will we search efficiently.. Many approaches were discussed: Linear Search, Binary Search
then TRIE.
ROUND 3 F2F(60 mins):
This round was easy, i think just to check my coding skills.
1. Given an array, find one pythagoras triplet..
2. Given a binary tree convert it to its mirror tree..
3. Given an n-ary tree convert it to its mirror image.
4. A 1-D puzzle. I could not answer it as only 7-8 mins were given to me, but at last
Interviewer asked my approach before leaving, she said yes I am on the right track but left
as Interview time was over.
ROUND 4 F2F (Hiring Manager, 60 mins) :
1. Asked full explanation what i am currently doing in my company.. Asked me to explain
on the whiteboard..

618
Chapter 247. Set 244 (For SDE-1)

2. Given a large file, that cannot be loaded into the memory, with 2 fields, ItemId and its
description. Entry contains the list of all items sold on amazon.in. Track the most sold item
item at any instant.
I could not answer this question efficiently, I tried to explain him with MinHeap, he then
said to go ahead and code. I did, but there were some flaws. But he was satisfied with the
approach i took to solve the problem.
3. Design a network packet class.. Class designing for Request, Response and Timeout
Packets..
4. Some behavioral questions, like tell me a time when you helped a collegue, a time when
you were helped, what should you improve in yourself etc..
ROUND 5 F2F (Sr. Manager, 75 mins):
1. Asked about my current project in full detail, many questions why do we make this
product, whats the use, who uses it, for what etc..
2. Design a contact list, full production level working code was required for all methods.
How will we store the contacts, what classes will we use, how will we search.
So we should display all the matched contacts whenever we press some characters..
Suppose when we open contact list and it have many contacts like (….Saransh Santa Sarcastic
Secular Sharma Start …… )
So if we type S , the screen displays all contacts with “S” then when we type “Sa”, screen
must display Saransh Santa Sarcastic.
Suggestions:
1. DO NOT mug up the code. Understand it.
2. If stuck, ask interviewer for hints, they are very co-operative.
3. Prepare Data Structures(especially Arrays, Trees, DP, Linked List, Stack, Queues,
Strings, Heaps, Hashing for Amazon).
4. You should be flawless at explaining what you are currently doing and your past projects,
future is a reflection of past.
At last Thank you GeeksforGeeks for helping me through this.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-244-for-sde-1-hyderabad/

619
Chapter 248

Set 245 (For 2.5 Years


Experienced)

Amazon Interview Experience | Set 245 (For 2.5 Years Experienced) - GeeksforGeeks
Round 1:
Q-1 Given an array os 0s and 1s, and another input m, I was supposed to tell the longest
continuous streak of 1s after flipping m 0s to 1s. E.g., Array is {1,1,0,0,1,1,1,0,1,1} m = 1
(which means I can flip ‘m’ one 0 to 1)
Answer: 6 (if we flip 0 at index 7, we get the longest continuous streak of 1s having length
6)
Q-2 Given N ropes of lengths L1, L2, L3, L4, …, LN. I had to join every rope to get a final
rope of length L1 + L2 + … + LN.
However, I can join only two ropes at a time and the cost of joining the two ropes is L1 +
L2. I was supposed to join ropes in such a way that the cost is minimum.
Round 2:
Q-3 Given a BST, I needed to serialize it and deserialize it. This essentially boiled down to
generating the “traversal” string and getting the BST back from the traversal.
Q-4 There are two linked lists. Both linked lists have a single-digit number in their nodes.
I needed to
treat this linked lists as a numbers and add them up and store the digits in a new linked
list.
E.g., head -> 5 -> 6 -> 7-> 9
head -> 2-> 1 -> 1
Resultant linked list: head-> 5 -> 8-> 9-> 0 (5679 + 211 = 5890)
Round 3: Hiring Manager round
Q-5 Project discussion in detail. Most challenging problem, how did you solve it, had any
disagreement with manager, how did you fix it etc.
Q-6 Given an array {2, 4, 6, 0, 1, 8, 1}, where each element represents the height of tower
located at its index. I was supposed to tell how much maximum water can accumulate in
this “valley” once it rains.

620
Chapter 248. Set 245 (For 2.5 Years Experienced)

Round 4:
Q-7 Given the encoding rule:
A -> 0
B -> 1
C -> 2

K -> 10

Z -> 25
I was supposed to get the number of original strings possible given an encoded input.
E.g., Given input 10, two possible original strings are possible BA and K, the answer is 2.
Q-8 Given two trees, find out if the second tree is a “subtree” of the first one.

E.g., Tree 1
A
/ \
B C
/ \ \
D E F
/
G

Tree 2:
B
/ \
D E
/
G

Answer: Yes (B is a subtree of A)


Tree 2:
B
/ \
D E

Answer: No (Tree 2 is not a subtree of Tree A)


Round 5: Engineering manager round
Q-8 Engineering Manager round, all behavioral, why do you want to leave the company, one
challenging problem, how did you overcome it, your biggest failure etc. etc.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-245-for-2-5-years/

621
Chapter 249

Set 246 (For SDE 2)

Amazon Interview Experience | Set 246 (For SDE 2) - GeeksforGeeks


I was recently interviewed by amazon for SDE 2 position. Here is my experience.
Round 1:
I was asked to solve 2 questions.
1. Spiral printing of 2D matrix.
2. Given an array of 0s and 1s . I was asked to return the index of a zero turning which will
produce a longest continuous 1s.
Ex 1 0 1 1 0 1 0 1 1 1 0 1. here turning the last 0 to 1 will form 5 ones. this is the longest
of all.
Round 2:
In this round I was asked to solve 4 question.
1. basic implementation of stack.
2. finding the middle element of a linked list
3. printing the vertical sum of a tree.
4. given an array of integers where the number go increasingly and at a point will start
decreasing something like the following.
2 3 4 5 6 7 8 6 4 3 2.
we need to find the turning point of this series. in this example it is 8.

Round 3:
Given 2 design problems
1. I was asked to design a s/w for game shop in shopping mall.
Description: The game shop will distribute preloaded cards. That card needs to be used to
play any game. if the card has balance the cardholder will be allowed to play the game.

622
Chapter 249. Set 246 (For SDE 2)

2. Design chessboard. I was asked to write all the classes.


Round 4: (hiring Manager)
Detailed discussion about project. Discussion about my current responsibilities in the cur-
rent company and details around that.
and lot of behavioral questions.
Round 5: (Bar Raiser)
Detailed discussion about the interesting problems I’ve faced in my past projects. The
interviewer went deeply inside the project and asked questions.
I was asked to solve a problem. Given a binary tree, I was asked to serialize that tree and
store it as a file format and retrieve it back to the form of a binary tree.
I was initially saying preorder and in-order delimited by a pipe symbol. But the interviewer
asked me to go with only one traversal. I finally gave a solution using only preorder, denoting
null nodes as *.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-246-for-sde-2/

623
Chapter 250

Set 247 (For SDE 1)

Amazon Interview Experience | Set 247 (For SDE 1) - GeeksforGeeks


Round 1:
Coding Round on paper
1 Ortp://www.geeleforgeeks.org/sum-of-two-linked-lists/
2 httP://www.geeksforgeeks.org/print a given matrix in-spiral-form/
Round 2:
1 Tell me about yourself??
2 http://www.geeleforgeeks.org/find-the-row-with-maximum-number-1s/
Round 3: Hiring Manager
Have you use what’s app, there are some hints come when we start type. How these hints
are coming.He asked me 1 to design my own code so that I can show the hint based on
number of count of particular word that I am using??
2 A At of disscussion on above question and he shows me how amazon maitain their product
recommedation feature.
Round 4:
1 Ortp://vovw.geeksforgeeks.org/reverse-a-list-imgroups-of-given-size/
2Ortp://www.geeleforgeeks.org/minimum-number-ITswaps-required-fortarranging-pairs-
adjacenTtmeach-other/
Round 5: Telephonic (Bar raiser)
1 A lot of disscussion on my projects.
2 Most challenging thing you have done in your both company??
3 Disagreement with your manager?
4 Is there any thing you develop which initiated by yourself??
5 Any time when you have to finished your work in short span of time?
6 Did you find any difficulty working with a team??
7 hrtp://www.careercup.com/question?id=6109164921159680
All Practice Problems for Amazon !

624
Chapter 250. Set 247 (For SDE 1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-247-for-sde-2/

625
Chapter 251

Set 248 (4.8 Yrs Experience for


SDE II)

Amazon Interview Experience | Set 248 (4.8 Yrs Experience for SDE II) - GeeksforGeeks

1. WRITTEN ROUND
(a) Given lengths(costs) of ropes, find the total minimum cost of creating a single
rope. (cost of two ropes = length1 + length2)
(b) Find all the diagonal sums of a binary tree

2. F2F
(a) Design Movie tickets booking system
i. Class diagram with all relevant classes & associations
ii. find out all use cases
iii. describe a typical flow of events
iv. show how each use case is handled using your class diagram (selection of
seats, payment etc)
v. how would system be designed such that you can show the user complete
cinema hall with all seats in their respective locations.
vi. write a service for a front end controller which will let users to select multiple
seats according to their preference. Already booked seats & available seats
should be marked differently.
vii. how will the cost of a booking be determined (I used decorator pattern for
it)

3. F2F
(a) About projects I had worked on; current task; few questions on the current task
(b) Challenges faced when an urgent action was required from my side during the
project life cycle. What were the problems, how I tackled it, how I implemented
its solution

626
Chapter 251. Set 248 (4.8 Yrs Experience for SDE II)

(c) Architecture (design) of the project I had worked for the longest period of time.
(d) Other tasks I had done: Batch jobs & REST web services. Questions around
them
(e) Design a system having multiple jobs, interacting with each other such that (use
a DAG for this problem):
i. a job can run for very long periods (1-2 days)
ii. a node can fail/crash on which certain job is running
iii. system should be scalable
iv. amount of data getting transferred is huge
v. data in the system is very sensitive and needs security
vi. job/s can fail

4. F2F
(a) About projects, current task
(b) Design a system for a Building having various Access Points & Users having
multiple levels of access
i. Class diagram with all entities, relationships
ii. how will you achieve scalability? (handle the system when the number of
users accessing it is very high at the same time)
iii. write all the necessary services required
iv. how will you handle the scenario when a person misplaces his card
v. how will the scenario for visitors entering the building be handled?

5. Telephonic
(a) Tell about all your projects you have worked in your career till now and your role
and contribution in each.
(b) Reasons for switching earlier from previous company to current, project with in
the company and now to Amazon
(c) Toughest situations handled, your role, your solution, how feasible was it
(d) Process of tackling highest priority issues, solutions, implementation, approvals
and end result.
(e) Flow of events in a typical development and release cycle.
(f) Coding question (first design & then code on collabedit). Problem Statement:
You are given n number of mutually exclusive jobs with their schedules (time of
running) that need to be run on m number of nodes. Find minimum value of m
such that all jobs can run in their respective times. Optimize your solution.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-248-4-8-yrs-experience-for-sde-ii/

627
Chapter 252

Set 249 (Telephonic Interview)

Amazon Interview Experience | Set 249 (Telephonic Interview) - GeeksforGeeks


Telephonic interview:
1. Given a string, display the words in reverse order
I/p: I work at xyz
O/p: xyz at work I
2. Given a linked list modify the linked list as below
I/p: a x b c y z
O/p: a b c x y z
3. What is virtual memory
4. If I am designing a media player and I want to store songs and play them in random
order
a) what data structure will you use to store songs?
b) how will select the next song to play in a way which prevents the same song being played
in consecutive turn
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-249-telephonic-interview/

628
Chapter 253

Set 250

Amazon Interview Experience | Set 250 - GeeksforGeeks


ROUND 1(Technical):
I initially had a telephonic interview where it started with my basic intro and some questions
about my current work. He then asked a couple of binary tree related questions:
1.1 Check if a given binary tree is BST or not.
1.2 In a BST, each node has an additional attribute ‘score’ along with the value. You need
to write two functions:
a. Update(value, newScore) -> update the score of the node with value ‘value’ to the
newScore
b. SubTreeScore(value) -> get the sum of scores of all nodes in the subtree with node having
the value ‘value’ as the root
Interviewer wanted O(logn) solution for Update and O(1) for SubtreeScore function. We
are allowed to change the structure of the node to add additional attributes
c. Discussion on the above solution for the case where nodes are deleted from the tree(How
to still have O(1) solution for SubTreeScore)
After this round, I immediately got a call for next round, which was an on-site interview
event
ROUND 2(Technical):
Around 30-40 candidates appeared for interviews on-site on that day and it all started with
a written coding test having 3 questions:
2.1 Level-order traversal for a binary tree
2.2 Don’t remember it exactly, something to do with pair-wise XOR operation for an array.
I could only give an O(n^2) solution for this.
2.3 Given a matrix, with each node having a value. You start from 0,0 and have to reach
n,m. From i,j you can either go to i+1,j or i,j+1. When you step on each block, the value
on that block gets added to your current score. What’s the minimum initial score you must
carry so that you can always reach n,m(through any possible path) having positive score at
the end.

629
Chapter 253. Set 250

Eg: Matrix -> 2 3 4


-5 -6 7
8 3 1

Ans -> 6 – for path 2,-5,-6,3,1 we need initial score of 6 so that when we land on 1, we have
a positive score of 1
After this everyone had a max of 3 interviews the same day, subject to qualification of each
round.
ROUND 3(Managerial):
Around 80% of the interview was about my current job and tiniest details about everything.
Design an automobile system -> two/three/four wheeler, petrol/diesel/gas, gear/non-gear
and classifications like this
How will you detect when a keyboard/mouse is attached to the computer? I said we will
have kind of listeners that listen to a port continuously and act accordingly. He insisted on
a solution without listeners. Had a good 5 mins discussion on this.
ROUND 4(Technical):
4.1 Linked list containing characters as values. Find if a linked list is palindrome.
4.2 Building Bridges Problem
4.3 Bottom View of binary tree
ROUND 5(Technical):
5.1 pow(a,b) needed to cover each and every case possible
5.2 LRU cache implementation
5.3 Given an array of numbers, form the largest number possible by concatenating all of
them. Needed to return a string.
After this, I was told that I can leave for the day, but next week will be called again for an
on-site-interview.
ROUND 6(Hiring Manager):
Again, 70-80 % of the time spent on my current work, minute details of each and everything
along with typical behavioural questions like hurdles faced, disagreement with manager,
conflicts and others..
Reverse a linked list again covering all possible scenarios
Some easy problem on binary tree (don’t remember exactly what)
After this I had to wait for almost a week for their call, where I was asked to appear for
another interview.
ROUND 7(Bar-Raiser):
Started with some behavioural questions like Why Amazon, why leave prev company along
with current job role details.
Longest Palindromic Substring in a string. The interviewer was satisfied with the first
solution that I suggested, asked me to code the same, and was convinced with the code too,
although I did make a small mistake which I realized later.
Initial intent was to ask two such questions, but I guess time restriction forced it to just
one.
Thanks a lot geeksforgeeks. The Amazon sets here did help a lot in the preparation.
All Practice Problems for Amazon !

630
Chapter 253. Set 250

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-250/

631
Chapter 254

Set 252 (For SDET)

Amazon Interview Experience | Set 252 (For SDET) - GeeksforGeeks


I got a call form amazon for the opening of SDET. It all started with telephonic interview
asking brief introduction and 2 questions.
1. rearrange a linked list in such way that all odd position nodes are together and all even
positions node are together, 1->2->3->4->5->6 , convert it ot 1->3->5->2->4->6
Face-to-Face 1st Round
1. Random play a song from a list of given songs in such a way that no songs is repeated
until all the songs are played
2. Distance between two nodes of a given binary tree
Face-to-Face 2nd Round
1. Find out whether a tree is subtree of given tree or not
2. For a given array find max of k sub-array, i.e if array is 1, 2, 3, 4, 5,6,7,8 ,9,10, then
function should return an array of size n-k+1 with each element be the max of k elements
output : 3 (max of 1, 2, 3), 4(max of 2,3,4), 5(max of 3, 4, 5) etc, array is not sorted �
Face-to-Face 3rd Round
1. Automating an api to getAllFriendListFromFacebook for a given email id.
Face-to-Face 4th Round 1. vertical sum of a binary tree, he was looking for in place
solution. just 1 traversal and without using hashmap as hashmap allocates more size than
the elements to store. interviewer gave hint to use doubly linked list to store the sum.
Face-to-Face 5th Round
1. Given a binary tree return a matrix where mat(i,j) is 1 when i is an ancestor of j. only
one traversal required and no extra space required, idea is to populate ancestor list as we
process nodes and update the matrix
Thanks & Regards
All Practice Problems for Amazon !

632
Chapter 254. Set 252 (For SDET)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-252-for-sdet/

633
Chapter 255

Set 253 (For SDE1I)

Amazon Interview Experience | Set 253 (For SDE1I) - GeeksforGeeks


Amazon Bangalore location. Part of weekend interview drive in March 2016.
Role: SDE1
3 rounds – all three very similar in pattern. Workout algorithm and write production ready
code.

1st round:
2 questions:
1. In a BST, replace value of each node with the sum of itself and everything greater than
itself.
2. There are two very large numbers, cant fit in any data type provided, so they are given
in a linked list (one digit per node). Sum the two numbers.

2nd Round:
2 questions:
1. Clone a linked list with random pointer.
2. In an integer array, find the window with maximum sum.

3rd Round (Bar raiser):


Mostly non-technical questions like challenges faced, and conflicts with colleagues etc.
Tech question: implement Linked hash map using Linked list and hash map.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-253-for-sde1i/

634
Chapter 256

Set 254 (Off-Campus for SDE1)

Amazon Interview Experience | Set 254 (Off-Campus for SDE1) - GeeksforGeeks


I got a call from amazon for opening in SDE – I. It started with a online screening round
and followed by one telephonic and then 3 face to face interview and again a telephonic
interview.
Online screening :
There were 20 multiple choice questions from Computer science fundamentals (OS, DS,
DBMS, Networks etc.) and basic input/output questions, some aptitude questions and 2
coding questions:-
1. Given an array find the minimum difference between any pair.
2. Write a function that returns true if a given undirected graph is tree and false otherwise.
http://geeksquiz.com/check-given-graph-tree
Telephonic Interview :
Interview started with brief introduction about me and my projects, then started with
coding questions.
1. Given two trees return yes if the order of leaves in tree are mirror image of each other.
2. Given an array of n numbers. another array with same elements but numbers are shuffled
and one element is removed. Find the missing element.(without using any extra space and
in O(n) ).
Then if both the array are sorted then how to find the missing element. (without extra
space and in O(log n)).
Then they called me for onsite interview and 3 face to face interview were conducted there.
Face-to-Face Interview 1 :
He started with a brief introduction and asked me my about my projects in detail.
then moved to coding questions:-
1. Arrange Linked List elements in zig-zag pattern such that
a < b > c < d > e ……
(without using extra space and Time complexity O(n)).
Don’t forget to handle edge cases.
https://www.geeksforgeeks.org/convert-array-into-zig-zag-fashion (This is array implemen-
tation of same question).

635
Chapter 256. Set 254 (Off-Campus for SDE1)

2. Given a binary tree. return sum of all Left Leaf nodes.


Left leaves meaning leaf node which is left child of his parent.
https://www.geeksforgeeks.org/find-sum-left-leaves-given-binary-tree/

Face-to-face Interview 2 :
1. Given two nodes of a binary tree,check they are cousins or not. (Both Iterative and
recursive solution).
https://www.geeksforgeeks.org/check-two-nodes-cousins-binary-tree
2. Given an array with N elements (numbers from 0 to N-1). Find all duplicate elements.
I gave a solution with hashing, he asked me to do without extra space.
Then I gave solution with sorting the array, he asked me to do with only single traversal
and without extra space.

Face-to-face Interview 3 :
Started with brief introduction and some questions from my projects and CS fundamentals
(OS,Networks).
1.Given an input string and a dictionary of words, find out if the input string can be
segmented into a space-separated sequence of dictionary words. https://www.geeksforgeeks.
org/dynamic-programming-set-32-word-break-problem

Telephonic Interview :
The interviewer asked me to introduce myself, and after that he asked some behavioural
question like-
Have you got offer from any other company ?
Why are you intersted in joining AMAZON ?
1. Design a Elevator. How you store the input from users inside the elevator, outside the
elevator. How the elevator will take decision whether to go up,down or stop.
2. There is an event in the auditorium and Given capacity of the auditorium (NxM).
every group of person booked ticket and all the tickets are booked, Now you have to assign
seat number to all of them such that minimum number of group split.
We can solve this using this https://www.geeksforgeeks.org/dynamic-programming-subset-sum-problem.
Thanks a lot geeksforgeeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-254-off-campus-sde1/

636
Chapter 257

Set 255 (On-Campus)

Amazon Interview Experience | Set 255 (On-Campus) - GeeksforGeeks


Amazon visited our campus. It started with a online coding round and followed by one
telephonic and then 3 face to face interview and again a telephonic interview. All interview
rounds started with brief introduction about me.
Round 1(Online Coding Round):
Asked 2 coding question and 20 mcq from Computer science fundamentals (OS, DS, DBMS,
Networks etc.)
1) Given n non-negative integers representing an elevation map where the width of each bar
is 1, compute how much water it is able to trap after raining.

Input: arr[] = {2, 0, 2}


Output: 2

https://www.geeksforgeeks.org/trapping-rain-water/
2) Check whether two strings are anagram of each other.
https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/
Round 2 (Telephonic round):
1) Tell me about yourself.
2) Vertical Sum in a given Binary Tree
https://www.geeksforgeeks.org/vertical-sum-in-a-given-binary-tree/
3) Project Discussion
Round 3 (f2f onsite):
1) Tell me about yourself.
2) Sort a linked list of 0s, 1s and 2s
https://www.geeksforgeeks.org/sort-a-linked-list-of-0s-1s-or-2s/

637
Chapter 257. Set 255 (On-Campus)

3) Find duplicates in O(n) time and O(1) extra space.


https://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/

Round 4 (f2f onsite):


1) Design a data structure that supports insert, delete, search and getRandom in constant
time
https://www.geeksforgeeks.org/design-a-data-structure-that-supports-insert-delete-search-and-getrandom-in-consta
2) Given a continuous input stream of integers, can you find the maximum N numbers at
any given instance?
https://www.quora.com/Programming-Puzzles-Given-a-continuous-input-stream-of-integers-can-you-find-the-maxi
3) lca of k nodes in given bst
4) K’th largest element in a stream
https://www.geeksforgeeks.org/kth-largest-element-in-a-stream/
5) Lowest Common Ancestor in a Binary Search Tree.
https://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/
Round 5 (f2f onsite):
1) Floor and Ceil from a BST
https://www.geeksforgeeks.org/floor-and-ceil-from-a-bst/
2) Find the two numbers with odd occurrences in an unsorted array
https://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/
3) Find the Number Occurring Odd Number of Times
https://www.geeksforgeeks.org/find-the-number-occurring-odd-number-of-times/
4) Project Discussion
Round 6 (Telephonic round):
1) Tell me about yourself.
2) Most proudest moment in last one year.
3) Most regretted moment in last one year.
4) Asked about what data structure and alogithms did i know then asked what is segment
tree.
5) Reverse the stack using recursion
https://www.geeksforgeeks.org/reverse-a-stack-using-recursion/
6) External merge sort
https://en.wikipedia.org/wiki/External_sorting
7) Project Discussion
Really want to thanks geeksforgeeks for providing great platform for learning.
All Practice Problems for Amazon !

638
Chapter 257. Set 255 (On-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-255-on-campus/

639
Chapter 258

Set 256 (Written Test for SDE1)

Amazon Interview Experience | Set 256 (Written Test for SDE1) - GeeksforGeeks
Recently i had an online test at hackerank platform for Amazon SDE1 position.
Following are the questions
1. Given an unsorted array, trim the array such that twice of minimum is greater than
maximum in the trimmed array. Elements should be removed either end of the array.
https://www.geeksforgeeks.org/remove-minimum-elements-either-side-2min-max/
2. Given a value V, if we want to make change for V cents, and we have infinite supply of
each of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make
the change?
https://www.geeksforgeeks.org/find-minimum-number-of-coins-that-make-a-change/
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-256-written-test-for-sde1/

640
Chapter 259

Set 257 (Off-Campus)

Amazon Interview Experience | Set 257 (Off-Campus) - GeeksforGeeks


I was recently interviewed by Amazon, Bangalore for SDE position. It was an off campus
drive in Delhi for TRMS team.
Written Test :
Q1) Find a peak element. https://www.geeksforgeeks.org/find-a-peak-in-a-given-array/
Q2) Top View of binary tree. https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
Q3) Maximum difference between node and its ancestor in Binary Tree. https://www.
geeksforgeeks.org/maximum-difference-between-node-and-its-ancestor-in-binary-tree/
Round 1 (F2F):
Q1) In a sorted array every number is present twice, only one number is present one time.
You have to find the number occurring once. Expected complexity : O(log N)
Ex : 101, 101, 200, 200, 301, 450, 450
Output : 301
Q2) Clone a binary tree with random pointers. https://www.geeksforgeeks.org/clone-binary-
tree-random-pointers/
In both the questions, they needed a proper working code covering every edge cases.
Round 2 (F2F):
Q1) Next greater element. https://www.geeksforgeeks.org/next-greater-element/
Q2) You have been given a grid with some doors, walls and some empty spaces.
1st part : You have to tell the least no of moves to go from random position in the grid to
the nearest door. You can move in four directions only, i.e, left, right, above, below.

641
Chapter 259. Set 257 (Off-Campus)

2nd part : Least distance of every empty cell to the nearest door. Lots of discussion was
done on both the parts of the problem.
I spend some time and finally came up with the working solution using Breadth first traver-
sal.
Q3) Find Excel column name from a given column number. https://www.geeksforgeeks.
org/find-excel-column-name-given-number/
This was the toughest round.
The interviewers had their flight to Bangalore and were getting late. So, next two rounds
were telephonic.
Round 3 (Telephonic) :
This round was taken by hiring manager.
Q1) Tell me about yourself. Your current company, your role and responsibilities. Reason
for leaving current company.
Q2) A 100 coin puzzle.
Q3) What happens after you write “a.out” and press enter. He wanted to know the func-
tionality performed by the OS after executable file is created of your code.
Q4) What happens when your code encounters NULL?
Q5) Garbage collector in Java. How is it different ?
Round 4 (Telephonic) :
Q1) Tell me about yourself. Your current company, your role and responsibilities.
Q2) Asked about the challenges faced in your current company. Any situation where you
were in disagreement with your manager. Any innovative or unique work performed in the
current company.
Q3) Connect nodes at the same level. https://www.geeksforgeeks.org/connect-nodes-at-same-level/
Proper working code was expected covering all edge cases. They shared the collabedit link.
Q4) What is Lock? Asked about semaphores, virtual memory, process scheduling.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-257-off-campus/

642
Chapter 260

Set 258 (For SDE1)

Amazon Interview Experience | Set 258 (For SDE1) - GeeksforGeeks


Round 1:
It was a writen round with three questions :
1. Find a row with maximum number of 1’s in a sorted 2D Boolean matrix.
2. Find next greater element for every element of an array to its right in O(n).
3. Convert a sorted array to binary search tree.
Round 2:
1. There is a linked list which is sorted based on their absolute values. Sort them based on
their actual values.
Eg., input : 1 -> -2 -> -3 -> 4 -> -5 output: -5 -> -3 -> -2 -> 1 ->4
2. Reverse a linked list.
3. Given a 1D array where each cell represents a toll gate ticket value. Find the minimum
number of tickets needed to surpass the whole array (means till u reach the end of array) .
If ticket value is 1 then u can pass that cell alone. If ticket value is 2 u can pass that cell
and the next cell.. that is how ticket values work.
Eg : Input : 3 1 5 4 1 1 1 Output :In this case if v buy ticket from a[0] and a[2] meaning
two tickets are enof to pass this array..
Round 3:
Only one question was asked :
1. Convert a BST to sorted doubly linked list without any extra space. (only ptrs to nodes
should be created ,no new node creation is allowed.)
Round 4:
Telephonic Round:
1. Tell me about yourself
2. Print the boundary of a tree.
3. There are billions of URL given. Come up with a efficient data structure that returns ip
address of these urls.
4. Trie data structure
I was asked to send the code snapshot within five mins after ending the call.

643
Chapter 260. Set 258 (For SDE1)

Round 5:
1. Tell me about yourself
2. Projects and Internship
3. Given a tree where each node has an additional ptr called “next” ptr. Initially this next
ptr of every node is null. Write code such that each node’s next ptr should point to its next
bfs node.
4. Trending tab related question: Given a large stream of strings, return the top 10 most
frequently occurring string . (Hash map + min heap of size 10 is the solution.)
Round 6:
1. Tell me about yourself
2. Why do u like Database Mgt System (I had DB in my areas of interest)
3. Design the backend of a social networking application (Eg : linked in)
4. All OS related qns
5. Network qns
6. Oops concepts with real time examples.
7. General technical questions.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-258-for-sde1/

644
Chapter 261

Set 258 (Off-Campus for SDE-1)

Amazon Interview Experience | Set 258 (Off-Campus for SDE-1) - GeeksforGeeks


I recently had interviews with Amazon at Hyderabad for SDE 1. I had around 1 year and
9 months of experience.
Telephonic Interview :
It started with a brief introduction of mine and my work. Then he asked me a coding
question
1) Given a linked list eg : 1->2->3->4->5->6, make the following changes
1->6->2->5->3->4
Easy but it was lengthy. Had to write production level code.
After 2-3 hours, I got an invitation for in house interview at Amazon campus:
Round 1 : Face 2 Face
It started with a discussion about my previous work and projects. After the discussion he
asked the following technical questions:
1) Given a pre-order traversal, construct a binary search tree.
https://www.geeksforgeeks.org/construct-bst-from-given-preorder-traversa/
Simple solution. Asked me to code it.
2) Given an alien dictionary, find the order of the alphabets in the dictionary.
Only the approach was required. I explained him the approach and he was satisfied. Here
is the link to the code anyway:
https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
3) Connect n ropes with minimum cost
https://www.geeksforgeeks.org/connect-n-ropes-minimum-cost/
I was asked to write production level code for the above problem.
Round 2 : Face to Face
Again the interview started with a discussion about my projects and then he asked a tech-
nical question.
1) Given m sorted arrays with n elements, merge these arrays into one sorted array of size
m*n

645
Chapter 261. Set 258 (Off-Campus for SDE-1)

I did hear about this question before but never really saw the optimized solution so I gave a
O(m*m*n) solution. He asked me to optimize it, but I wasn’t able to do so, hence he asked
me to code the O(m*m*n) solution. I took a lot of time to code it as I wanted to handle
all the edge cases. Finally I coded it. He didn’t find any issues but he asked me to make it
better. And then I suggested using heaps to get the minimum of all the m arrays.
Lot of questions on why heap and why not BST. Asked me to prove it mathematically.
But he was satisfied once I gave the solution using heaps.
https://www.geeksforgeeks.org/merge-k-sorted-arrays/
Round 3 Bar Raiser : Telephonic
Discussion on my previous projects and asked some behavioral questions like why are you
leaving your current company, conflicts with your manager etc
Technical questions:
1) Find the maximum element in an array which is first increasing and then decreasing
https://www.geeksforgeeks.org/find-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasin
2) Find the Pythagoras triplet in an array
Gave an O(n3) solution then made it O(n2logn). He asked me to optimise it even further.
Finally came up with O(n2) solution
https://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-unsorted-array/
3) Given a very large binary number which cannot be stored in a variable, determine the
remainder of the decimal equivalent of the binary number when divided by 3
I had no clue about this question. He gave me a hint, with which I was able to solve it. But
later, he asked me to find the remainder for any number k. Again he gave a hint and I was
able to solve it.
Basically when we append a digit to a binary number, the previous binary number gets
doubled, hence the remainder also gets doubled.

For example : 101 -> 5


1010 -> 2*5 + 0 = 10
1011 -> 2*5 + 1 = 11

If k = 3 then
5 = 1*3 + 2
2*5 = 2*3 + 2*2
Hence the remainder will be
(2*2 + 0)%3 = 1 for 1010

Similarly for 1011 the remainder


will be (2*2 + 1)%3 = 2

By keeping track of the remainder of the previous binary number, the current remainder
can be determined.
Round 4 Hiring Manager: Face to Face
Behavioral questions along with some questions about my previous projects.

646
Chapter 261. Set 258 (Off-Campus for SDE-1)

Then he gave me a technical question:


1) Given a number say ‘1234’, return the number in words i.e One thousand two hundred
and thirty four
Was able to cover all the scenarios. He was satisfied with my approach
Suggestions:
Think loud and be confident. It’s okay if you don’t know the answer at first. They mostly
see how you solve questions for which you don’t know the solution.
Thanks geeksforgeeks. You guys are doing an awesome job.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-258-off-campus-sde-1/

647
Chapter 262

Set 259 (1 Yr Experienced for


SDE1)

Amazon Interview Experience | Set 259 (1 Yr Experienced for SDE1) - GeeksforGeeks


Round 1: It was a written round with three question.
Q1) Find a peak element. https://www.geeksforgeeks.org/find-a-peak-in-a-given-array/
Q2) Top View of binary tree. https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
Q3) Maximum difference between node and its ancestor in Binary Tree. https://www.
geeksforgeeks.org/maximum-difference-between-node-and-its-ancestor-in-binary-tree/
Round 2 (F2F):
Q1) Given an array of distinct integers, find if there are two pairs (a, b) and (c, d) such
that a+b = c+d, and a, b, c and d are distinct elements. If there are multiple answers, then
print any of them. Expected complexity : O(n2

Ex : 3,4,7,1,2,9,8
Output : (3,8) and (4,7)

Q2) Lowest Common Ancestor in a Binary Tree https://www.geeksforgeeks.org/


lowest-common-ancestor-binary-tree-set-1/
In both the questions, they needed a proper working code covering every edge cases.
Round 3 (F2F):
Q1) If I am designing a media player and I want to store songs and play them in random
order
a) What data structure will you use to store songs?
b) How will you select the next song to play in a way which prevents the same song being
played in consecutive turn.
I spend some time and finally came up with the working solution.

648
Chapter 262. Set 259 (1 Yr Experienced for SDE1)

Q2) Clone a binary tree with random pointers. https://www.geeksforgeeks.org/


clone-binary-tree-random-pointers/
(Hint: Use HashMap)

Round 4 (Telephonic) :
Q1) Tell me about yourself. Your current company, your role and responsibilities. Reason
for leaving current company.
Q2) Maximum triangle path Sum : Starting from the top of a pyramid of numbers like
below, you can walk down going one step on the right or on the left, until you reach the
bottom row:

One of such walks is 55 -> 94 >- 30 -> 26. You can compute the total of the numbers you
have seen in such walk, in this case it’s 205.
Your problem is to find the maximum total among all possible paths from the top to the
bottom row of the triangle. In the little example above it’s 321.
Q3) Design your own Process Control Block(PCB).
Q4) Give me an example of a project that didn’t work out well?
Q5) What are some of the things that you and your supervisor have disagreed about?
Round 5 (Telephonic) :
Q1) Tell me about yourself. Your current company, your role and responsibilities.
Q2) Asked about the challenges faced in your current company. Did you ever have a boss
that you did not like or get along with?
Q3) Check for balanced parentheses in an expression. https://www.geeksforgeeks.org/
check-for-balanced-parentheses-in-an-expression/
I was asked to write code as well on collabedit site.
Q4) Move all zeroes to end of array. https://www.geeksforgeeks.org/move-zeroes-end-array/

All Practice Problems for Amazon !

649
Chapter 262. Set 259 (1 Yr Experienced for SDE1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-259-1-yr-experienced-for-sde1/

650
Chapter 263

Set 260 (For SDE2)

Amazon Interview Experience | Set 260 (For SDE2) - GeeksforGeeks


Online Coding Round:
1. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
2. https://www.geeksforgeeks.org/largest-rectangle-under-histogram/
1st Round:
1. https://www.geeksforgeeks.org/sum-of-two-linked-lists/. I gave recursion solution code.
Then asked for optimized one.
2nd Round:
1. Detail overview of current project. roles and responsibilities.
2. Implementation of Queue but with certain kind of constraints. Basically looking for
knowledge of design patterns.
3rd Round:
1. Again went through resume and asked every point.
2. https://www.geeksforgeeks.org/maximum-sum-path-across-two-arrays/
List all possible test cases.
3. Design a dashboard system. both HLD and LLD.
4th Round:
1. Design a system to upload images and tag them, ability to search images with two or
more tags particular tags.
2. Most challenging work
3. https://www.careercup.com/question?id=5638261762424832
5th Round (Bar Raiser):
1. Most challenging work
2. Why Amazon?
3. Why leaving current company?
4. http://geeksquiz.com/stack-set-4-evaluation-postfix-expression/
5. Design a online shipment tracking system.

651
Chapter 263. Set 260 (For SDE2)

Note: In all they asked for production ready code. Please take care of all edge case.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-260-for-sde2/

652
Chapter 264

Set 261 (For SDE1)

Amazon Interview Experience | Set 261 (For SDE1) - GeeksforGeeks


I had around 1 year and 9 months of experience.
Telephonic Interview :
It started with a brief introduction of mine and my work. Then he asked me a coding
question
1) Given a linked list eg : 1->2->3->4->5->6, make the following changes
1->6->2->5->3->4
Easy but it was lengthy. Had to write production level code.
After 2-3 hours, I got an invitation for in house interview at Amazon campus:
Round 1 : Face 2 Face
It started with a discussion about my previous work and projects. After the discussion he
asked the following technical questions:
1) Given a pre-order traversal, construct a binary search tree.
https://www.geeksforgeeks.org/construct-bst-from-given-preorder-traversa/
Simple solution. Asked me to code it.
2) Given an alien dictionary, find the order of the alphabets in the dictionary.
Only the approach was required. I explained him the approach and he was satisfied. Here
is the link to the code anyway:
https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
3) Connect n ropes with minimum cost
https://www.geeksforgeeks.org/connect-n-ropes-minimum-cost/
I was asked to write production level code for the above problem.
Round 2 : Face to Face
Again the interview started with a discussion about my projects and then he asked a tech-
nical question.
1) Given m sorted arrays with n elements, merge these arrays into one sorted array of size
m*n
I did hear about this question before but never really saw the optimized solution so I gave a

653
Chapter 264. Set 261 (For SDE1)

O(m*m*n) solution. He asked me to optimize it, but I wasn’t able to do so, hence he asked
me to code the O(m*m*n) solution. I took a lot of time to code it as I wanted to handle
all the edge cases. Finally I coded it. He didn’t find any issues but he asked me to make it
better. And then I suggested using heaps to get the minimum of all the m arrays.
Lot of questions on why heap and why not BST. Asked me to prove it mathematically.
But he was satisfied once I gave the solution using heaps.
https://www.geeksforgeeks.org/merge-k-sorted-arrays/
Round 3 Bar Raiser : Telephonic
Discussion on my previous projects and asked some behavioral questions like why are you
leaving your current company, conflicts with your manager etc
Technical questions:
1) Find the maximum element in an array which is first increasing and then decreasing
https://www.geeksforgeeks.org/find-the-maximum-element-in-an-array-which-is-first-increasing-and-then-decreasin
2) Find the Pythagoras triplet in an array
Gave an O(n3) solution then made it O(n2logn). He asked me to optimize it even further.
Finally came up with O(n2) solutionhttps://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-unsorted-array/
3) Given a very large binary number which cannot be stored in a variable, determine the
remainder of the decimal equivalent of the binary number when divided by 3
I had no clue about this question. He gave me a hint, with which I was able to solve it. But
later, he asked me to find the remainder for any number k. Again he gave a hint and I was
able to solve it.
Basically when we append a digit to a binary number, the previous binary number gets
doubled, hence the remainder also gets doubled.

For example : 101 -> 5


1010 -> 2*5 + 0 = 10
1011 -> 2*5 + 1 = 11

If k = 3 then
5 = 1*3 + 2
2*5 = 2*3 + 2*2
Hence the remainder will be
(2*2 + 0)%3 = 1 for 1010

Similarly for 1011 the remainder


will be (2*2 + 1)%3 = 2

By keeping track of the remainder of the previous binary number, the current remainder
can be determined.
Round 4 Hiring Manager: Face to Face
Behavioral questions along with some questions about my previous projects.
Then he gave me a technical question:
1) Given a number say ‘1234’, return the number in words i.e One thousand two hundred
and thirty four

654
Chapter 264. Set 261 (For SDE1)

Was able to cover all the scenarios. He was satisfied with my approach
Suggestions:
Think loud and be confident. It’s okay if you don’t know the answer at first. They mostly
see how you solve questions for which you don’t know the solution.
Thanks geeksforgeeks. You guys are doing an awesome job.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-261-sde1/

655
Chapter 265

Set 262 (For SDE1)

Amazon Interview Experience | Set 262 (For SDE1) - GeeksforGeeks


I am 1.5 year experienced guy, currently working in one good Product Based company in
Whitefield,Bangalore. I have spent 1.2 years in my present company and previously, I spent
6 months in TCS Pune.
Recently, I got a chance to be interviewed by Amazon at Bangalore, through a referral
(made friend from Facebook :p). I was preparing for Amazon from last 6-8 months from
GeeksforGeeks.org. I must say, GeeksforGeeks is making life of people. I got an offer from
Amazon by preparing from GeeksForGeeks.
Questions :
As I reached to 25th Floor of WTC, Brigade Gateway, we 25 people were asked to write
code for these 3 questions on paper (OnSite Written Round) :
1. Two numbers are represented by 2 linkedlists. Find the resultant linkedlist represented
as sum of these given linkedlists.
2. Given a number say 12345, find the immediate next number using the same digits, in
this case 12354.
3. 3 points of a triangle are given. Find if given forth point lies inside or outside of the
triangle.
F2F Round 1 :
1. Given a Hotel and checkin/Checkout time of visitors, find the maximum numbers of
rooms required. (different version of Trains/Platform question)
2. Given sequentially placed boxes, each representing a number( which may be positive or
negative), we need to select the numbers in order to have the maximum sum, having the
constraint that if we seelct a given box, we cannot select adjacent box to it, but can select
any other.
Solution : let the boxes positions be the indexes of array and their values as array values.
then if we select value at index 0, we cannot select value at index 1, but can select from
index 2,3„ and so on.so we can apply Dynamic programming here.

656
Chapter 265. Set 262 (For SDE1)

F2F round 2 (Hiring Manager Round):


HR called me and gave me some tips before this Interview(I must say Amazon Interview
people are really cool and make the candidate feel comfortable). He told me listen the
question carefully and answer perfectly as this interview matter a lot.
1. Asked about my experience and work in current company. (Discussion lasted for about
1 hour) as I explained in deep and he asked cross questions.
2. Given 2 numbers, add them without using any arithmetic operator.
Hint : Use Binary Operators (specifically ‘<<‘, ‘&’, ‘^’)
Gave answers to this question and he was really impressed.
(he was also very cool in nature)

F2F Round 3 :
1. Discussion on my projects and work in current company.
2. Given a general stack, design an advanced DS, such that getMin(),getMax() happens in
o(1). Many cross questions on this. about optimizations and all.
Then HR told me that all my interviews went well and they will call me for last round of
Interview. �

Last F2F round (Bar Raiser):


1. Given a file having many lines of text(words) and given a dictionary having an API func-
tion boolean isValid(String word), which will return true is a word passed to this function
is valid word in dic.,and will return false if given passed argument is not a valid word in dic.
Now read the file and check if each word as well as all possible words from its L to R and
R to L combinations, are valid words in dic. or not.
e.g. say first line in file is “My name is Gourav”, then in the word NAME, the possible valid
words are NAME, AM(L to R), ME(L to R), MAN(R to L), AN(R to L).
I implemented this simple questions in java code and used Hashmap to avoid processing of
already processed words.
2. Why Amazon ?
3. Extraordinary work done in company which was out of scope of your designation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-262-for-sde1/

657
Chapter 266

Set 262

Amazon Interview Experience | 262 - GeeksforGeeks


1. Given infinite sequence of number, how you will store it in a system. Find whether the
given sequence is palindrome or not.
Ans: He suggested to store all the number in a linked list and then find Palindrome or not
2. A) Find the path with given sum in a Binary tree from the root
B) Find the path with given sum in a Binary tree from any node in the tree.
3. Print all possible balanced parenthesis.
4. Implementation of publisher and subscriber design pattern.
5. Find the given sum in unsorted array.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-262/

658
Chapter 267

Set 263 (For SDET)

Amazon Interview Experience | Set 263 (For SDET) - GeeksforGeeks


It’s an on campus recruitment. The interview process started on October, 2015.
It had 25 MCQ questions from core subjects of CS including Operating systems, Database,
Networks, Data structures and algorithms, Fundamentals of programming. Apart from that
there was 2 programming questions too. Those who solved at least 1 programming problem
and few MCQ questions were selected for next round. But it’s better to solve both the
programming questions. I was asked the following questions:

1. https://www.geeksforgeeks.org/merge-two-sorted-arrays-o1-extra-space/
2. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/

It was a phone interview of duration 1 hour. It was conducted on collabedit.com. This round
consisted 2 data structures and algorithms related questions. I was asked the following
questions:

1. https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
2. https://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/

It was similar to that of round 2. I was asked the following questions:

1. https://www.geeksforgeeks.org/square-root-of-an-integer/
2. https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/

Overall it was an awesome experience. I enjoyed the interview process.


Thanks for geeksforgeeks!
All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-263-for-sdet/

659
Chapter 268

Set 264 (Experienced for SDE1)

Amazon Interview Experience | Set 264 (Experienced for SDE1) - GeeksforGeeks


I had around 1 year and 9 months of experience. And applied for SDE1
First Round (F2F):
1. What are data structures in which you are most uncomfortable.
2. What is your favorite sorting algorithm. Give a dry run.
3. Heap sort, dry run, Complexity of building heap, prove it.
4. https://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1 , extended for
n-array tree.
5. https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/ ( in single scan)
Second Round (F2F):
1. Tell me about yourself.
2. What is the most challenging project you have done, your contribution.
3. http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/
4. http://www.geeksforgeeks.org/find-the-longest-substring-with-k-unique-characters-in-a-
given-string/
Third Round (F2F):
1. Tell me about yourself.
2. Most challenging project, why it was challenging, your role in it.
3. Implement a LRU cache, extended for LRU with ttl at each block.
4. http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/
5. Full working code of Dijastra Algorithm and a dry run.
Fourth Round: Hiring Manager (Telephonic)
1 Tell me about yourself, company role and responsibility and many behavioral questions.

• Your current Group/Team structure.


• Promotion criteria in your group.
• Situation when you helped your colleague
• Situation when you needed help from a colleague.

660
Chapter 268. Set 264 (Experienced for SDE1)

• If one of team member is not working or working very slow, how will you handle the
situation.
• When you have trained any colleague.
• Technology suggested by you in your team.

2. Detailed discussion about previous projects.


3. If you have indefinite budget and indefinite time, what type of project would do ?
4. Design a notification system.
Fifth Round: Bar Raiser
1. Tell me about yourself.
2. Find smallest positive missing number from an array of positive numbers.
3. Disagreement with your immediate supervisor, how your relation got affected after that
disagreement.
4. Your one area which needs to be improved.
5. Your strongest strength.
6. A work in your project which made you proud.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-264-experienced-for-sde1/

661
Chapter 269

Set 265 (For Internship)

Amazon Interview Experience | Set 265 (For Internship) - GeeksforGeeks


Let me discuss each round in detail.
APTITUDE ROUND
There were 20 aptitude questions and 2 coding question
Aptitude question – each of 1 mark (-0.25 mark for each wrong answer)
Coding question – each of 10 mark
Since, Coding questions had more weight-age, so I started with coding questions. I
attempted only one coding question and there I could pass only 2 test cases (received 4
marks). And then I moved to aptitude part. There, I attempted 13 questions.
With God grace, I got my name in the extended list.

INTERVIEW ROUND
There were 4 interview round. Each round took by different people and 2 questions were
asked in each. I am going to tell you about each round in detail.

ROUND 1
First question was ‘Tell me about yourself?’. I told her about projects like what I learnt
from it, what difficulties I faced, my hobbies and what I am looking for in future.

After that, two more Questions that were asked:


1. Given an array consisted of both positive and negative integers. The task was to put
positive and negative elements alternatively and efficiently.
I told her 2 approach. The best approach was asked to code (in any language). I coded it.
2. Given arrival and departure times of Train. The task was to find out minimum number
of platform needed.
I did this question even earlier. I told her my approach and coded the same.

ROUND 2
Two Questions that were asked:
1. Given a complex weighted directed graph. Each weight represents the cost of transaction

662
Chapter 269. Set 265 (For Internship)

and each edge represents the transaction. The task was to minimize the graph and find out
the minimum cash flow.
I gave him one approach using hash map and coded the same.
2. Given an integer and decoding mechanism (like 1- A, 2-B……26-Z). The task was to find
out all the possible decoding of integer.
I applied dynamic programming approach and coded the same.

ROUND 3
He asked me to tell about my projects. I wrote three projects in my Resume. I discussed
them. Then he gave me some situation and asked how your project would solve this scenario.

After that, two more Questions that were asked:

1. Given an Amazon Store House where every products were stored like pens, balls
etc. Also the condition was that items can be sold in bundles like 2, 3, 5, 7 etc. The task
was that how I can sell those products if some order like 10 pens has come. It was asked to
solve it in an efficient manner.

I tried it using dynamic programming and solved it correctly. But interviewer replied
“No, you cannot apply dynamic programming here as you need to find the solution for all
the products and serve all the customer. Think of some other approach like using data
structure”.
Then I thought of another approach and that worked for me.
2. Given a BST and number K (which is one of those BST). The task was to find out the
closest value to K.
The solution was very easy. I did this with inorder traversal and picked the adjacent values
to K which has minimum difference with K. I coded the same.

ROUND 4
Here again, I was asked to tell about my projects. Some questions related to them were
also asked.

After that, only one question was asked:

1. Given a room, where N number of person are present and some comparison
among them (like A>B, B>C, B<D etch). The task was to find out the greatest among
them.
I solved it first using dynamic programming approach but its’ time complexity was O(n2).
So I was asked to find out another approach. I tried it with two other approaches. The last
one was asked to code. I used hash map for the input.
Interviewer seems to me that he was satisfied with the approaches and code I gave. May be,
he didn’t ask the second question because of this.

MY SUGGESTION
I would suggest the following things to follow:

• Be confident and keep on trying to solve the question however it is tough. Be-

663
Chapter 269. Set 265 (For Internship)

cause they’re looking for your analytical and problem solving ability rather than solved
problem.

• Keep on telling about the approaches that are coming in your mind at the in-
stant. Interviewer may help you to let you know where you’re wrong (as happened in my
case).

• Keep on explaining while you’re finding the time complexity of the problem.

• Be sure that your communication medium is English in interview.

• Practice the coding (coding not pseudo code) on paper and dry run. Otherwise,
you may not be able to write it there.
I’ve been selected in Amazon with God grace.
Rohit Kesarwani
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-265-internship/

664
Chapter 270

Set 265 (On-Campus


Internship)

Amazon Interview Experience | Set 265 (On-Campus Internship) - GeeksforGeeks


Amazon recently visited our campus for hiring interns for 6 month internship.
Round 1: Online Test
The round-1 was an online test of 90 minutes. It was hosted on HackerRank platform. There
were 20 MCQ questions and 2 coding questions. MCQ questions were of 1 mark each. There
was a negative marking of 0.25 for each wrong MCQ answer. The MCQ questions were from
data structures, DBMS, aptitude, etc.
The coding questions were:
Q1. https://www.geeksforgeeks.org/reverse-words-in-a-given-string/
Q2. https://www.geeksforgeeks.org/find-possible-words-phone-digits/
Note: It is very important to do atleast one coding question to clear this round. Even if
you get all your 20 MCQs correct but you don’t do any coding question then your chances
of getting selected are very low. I suggest everyone to do all the MCQs they can in initial
30 minutes and then devote last 60 minutes for coding questions.
I did 15 MCQs and 2 coding questions. I got selected for next round. Overall, 19 students
got selected for next round.
Round 2: Interview
The interviewer first asked me about one of my project that i mentioned in my CV. Then
he asked me two questions.
Q1. We are given a mapping: A is mapped to 1, B is mapped to 2, C is mapped to 3 … Z
is mapped to 26. We are given a number n, we have to tell how many distinct strings can
be formed from this number n using the given mapping. For example,
Input: 121
Output: 3

665
Chapter 270. Set 265 (On-Campus Internship)

Explanation: We can read the number n as 1, 2, and 1. The string formed will be ABA
(1=A, 2=B). We can also read the number n as 12 and 1. The string formed will be LA
(12=L, 1=A). We can also read the number n as 1 and 21. The string formed will be AU
(1=A, 21=U). So we can form maximum 3 distinct strings out of number 121 using the
given mapping.
I gave a recursive solution and the interviewer was satisfied with my solution. So he asked
me to code my solution on a paper. I coded the solution and then he checked my code.
Once he was satisfied, we moved on to the next problem.
Q2. https://www.geeksforgeeks.org/remove-bst-keys-outside-the-given-range/
After a while the shortlist was announced. 10 students got shortlisted for the next round. I
too got shortlisted for the next round.
Round 3: Final Interview
This was the final interview of the process. The inteviewer first asked me to introduce myself
and then he asked me about one of my project. He then asked me several questions, which
are as follows:
Q1. What is a binary tree? What are different types of traversals in a BT? What is the
difference between these traversals? Which of the traversal is based on BFS and which is
based on DFS?
I answered the questions appropriately. He was satisfied with my answers.
Q2. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
Once i gave him the solution, he asked me to code it on a paper. He checked my solution
manually with some test cases. Once he was satisfied, we moved on to the next question.
Q3. What is a max heap? What is a min heap? What are some real life applications of
heaps?
Q4. How to insert in a heap? What is the time complexity?
Q5. How to delete a min element from a min heap? What is the time complexity?
Q6. Given an array of n numbers, how can i build a min heap from the array. What is the
time complexity?
I answered him appropriately. I told him that we can solve the above problem in O(n) time
complexity. He then asked me to prove that the complexity is O(n). I proved it with an
example array. He was satisfied with my answer.
Q7. There is a constant flow of numbers coming in from some infinite list of numbers out of
which you need to maintain a data structure as to return the top 100 numbers at any given
point of time. Assume all the numbers are integer numbers only.
Sol: I gave him a solution using min-heap. We can create a min heap of 100 elements.
The first 100 elements is easy to handle. Let say we get the 101th element in the list. If
this number is less than the root of the binary heap then we need not do anything. If this
number is greater then the root of the binary heap then we need to replace the root element
with this element and call percolate-down procedure on the root of the binary heap.
My interviewer concluded my interview with this question.

666
Chapter 270. Set 265 (On-Campus Internship)

I suggest everyone to go through Amazon interview experiences of atleast 5 people from


geeksforgeeks.com before their Amazon selection process. Finally, i would say focus on data
structures, OS, DBMS and networks. In data structures, focus mainly on binary trees,
binary heaps and linked lists.
Operations on Binary Min Heap
Reverse each word in a given string
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-265-on-campus-internship/

667
Chapter 271

Set 266 (Off-Campus for SDE1)

Amazon Interview Experience | Set 266 (Off-Campus for SDE1) - GeeksforGeeks


Written Test (on Hackerrank)
20 MCQ’s and 2 Coding Questions to be solved in 90 minutes
1) NEXT PERMUTATION: Next Largest Number with same set of digits.
For Ex: I/P: 123, O/P: 132
2) DFS + DP Standard Question. I don’t remember the exact problem statement, but it
was pretty standard one and required a DFS+DP solution.
Round One (Telephonic)
1) Given an array of zeroes and ones. You are allowed to flip any one 0 so as to maximize
the continuous number of one’s.
A variation of this problem: https://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-
2) Given only a Node of a Binary Tree, Find the next in-order successor in O(1) space. Root
of tree is unknown.
As he told to assume anything except the position of root, To solve the problem I assumed
that the Treenodes also contain parent pointers to their respective parent.
Round Two (F2F)
1) Given a Binary Tree. Print its elements vertically. Solved it using Horizontal Distance
concept and hashmap.
https://www.geeksforgeeks.org/print-binary-tree-vertical-order-set-2/
2) Variation of above question, you are not allowed to use Hashmap. Discussed many
approaches. He applied a constraint of not using any Hashing, after a lot of discussion and
variations came up with the solution as a Doubly Linked List of List of Nodes. Since I was
not allowed to use hashing, the variation I did to solve was to maintain a global pointer to
the doubly linked list, moved it left in doubly linked list for the left child of current treenode
and move right for right child of current tree-node.

Round Three (F2F)


Introduction and Internship related discussion followed by these technical problems
1) Given a Stream of sorted integers. Size of input vector is unknown. Find a given integer.

668
Chapter 271. Set 266 (Off-Campus for SDE1)

Expected Complexity; Log(n)


Hint: Used Perfect Square’s as the start index and end index in binary search approach.
2) Variation in above problem, as we do not know the end point. Lets assume we have a
function which returns NULL if the threshold index (Size of input vector)
had crossed. Now improve above solution to handle the case.
Ex: Lets assume that the array size is
3) Subject Related Questions: TCP v/s UDP, Virtual memory, Cryptography etc
4) Design a Music Player which plays songs in random order without repeat. Came with
O(n) Time and O(1) space solution.
Round Four (F2F)
Introduction, Project related questions followed by:
1) Given k sorted Linked Lists. combine those into one sorted list.
Used custom Min heap approach to do the same.
2) Implement Custom Min Heap for above problem.
3) Print Nodes at distance “k” from a given node in a binary tree.
Round Five (Telephonic)
1) Introduction and Project discussion.
2) Convert given integer into Roman Number format but by using minimum number of
conditional statements. Came up with lot of approaches,
he was not satisfied with any approach and asked to remove as much conditional statements
as I can.
3) Given an array of zeroes and ones. find the maximum size of subarray with
equal number of zeroes and ones. Came up with O(n) time and O(n) space so-
lution, something similar to the one discussed here:https://www.geeksforgeeks.org/
largest-subarray-with-equal-number-of-0s-and-1s/
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-266-off-campus/

669
Chapter 272

Set 266 (SDE 2)

Amazon Interview Experience | Set 266 (SDE 2) - GeeksforGeeks


I recently had an interview at amazon for SDE2 role. I am here to share my experience :
Telephonic :
1. you are given a string and hashmap.
replace all characters that are present in hashmap with hash value and generate all possible
combinations.
2. Given a tree, print all cousins of node that is given as input.
Round 1
Interviewer was really nice guy, he was helpful and gave hints while solving
1. Implement LRU – time 45 min
as 15 min were left, so he asked one more ques and said we wont code for it.
2. given an unsorted array, get the median of array. – this has to be done in O(n)
We had discussion on this i tried all DS to look for solution, he gave me hint that i can sort,
so i came up with solution in which i used optimised quick sort and i was also asked to code
in last 3 min.
Round 2
1. He asked me to design Parking Lot.
2. He asked me to code zig-zag printing of binary tree.
we also had discussion on challenges of my past experiences.
Round 3
This was bar-raiser, i got to know after the round.
1. He asked me about my experience and background and asked some tricky questions on
leadership.
2. Asked me to design the flight system with src, destination and no of hops. (i coded 3.5
pages of solution :))
3. Why you want to join amazon ?
4. How will optimise the performance and check for leaks ?
Round 4
This guy was very smart, he pin points anything that i say and marks it.

670
Chapter 272. Set 266 (SDE 2)

discussion about my background.


1. Why did you shutdown your company ?
2. why amazon ?
3. Tell me about your failures ?
4. Tell me about your project with max technical difficulty ?
5. How will optimise any system ?
6. Design a Railway system – it was very lenghty stuff, i coded around 5 pages.
Round 5
1. You have a tree, find the minimum lenght from input node to leaf.
Happy to receive the offer and join here…:)
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-266-sde-2/

671
Chapter 273

Set 267 (8 Months Experienced)

Amazon Interview Experience | Set 267 (8 Months Experienced) - GeeksforGeeks


Recently, I got a chance to be interviewed by Amazon at Bangalore campus, through referral.
I had 8 months of experince in a product based company and 5 months of Internship.
1st Round Telephonic :
There were two guys, started with a formal introduction.
Question 1 : Given an array and a number say “Num1”. Find two numbers whose sum is
equal to given number “Num1”.
https://www.geeksforgeeks.org/write-a-c-program-that-given-a-set-a-of-n-numbers-and-another-number-x-determin
I told him first Brute Force solution then he asked the time complexity which i told him
O(n^2).
Then he asked me to optimize the solution and I gave a O(nlogn) solution using sorting.
And at last I told him O(n) solution using Hashing.
Question 2 : Given an array of stock prices . Determine the maximum profit one can get
by byuing an selling the stock(Similar to stack span problem).
https://www.geeksforgeeks.org/the-stock-span-problem/
I told him brute force solution of O(n^2) then he asked me if you could give an optimized
solution.
I told him O(n) solution using stack but code got stuck on some of the test cases and he
asked me to modify the code but i couldn’t as they were running out of time.
They provided me a link to Colabedit(kind of google shared document) where i had to
code.Production ready code was required.
After 2 days I got call from Amazon saying that feedback was positive and they asked me
to come for face to face interview at Amazon’s office.
F2F Round 1 :
Started with a brief introduction.
Q1 : Given a M*N matrix . you have to start from Index(0,0) and reach to Index(M-1,N-1)
with maximum sum , given the constraint that you can only move right or down i.e if you
are at index (i,j), you can only move to index(i,j+1) or to index(i+1,j)
I gave recursive solution for this and there were a lot of discussion on various test cases.
He asked me to optimize the code. I gave him Dynamic programming approach . He asked

672
Chapter 273. Set 267 (8 Months Experienced)

that have you done it before and i said no then he asked me to code it. I had no idea of the
code as i haven’t done it before. i struglled to write the correct code 2-3 times and at last i
wrote the correct code.
Then he said to me i am done with the interview, Do you have any question for me and i
asked two question.
Production ready code was required.
F2F Round2 :
Again Started with a brief introduction and some project discussion.
Q1 : A question similar to LCA(Least Common Ancesstor) of Tree and i gave the answer
immediately as i have understood the question and didn’t ask any further clarification.
Q2 : Given some resources in the form of linked list you have to canceled out all the resources
whose sum up to 0(Zero) and return the remaining list.
I gave the solution immediately but couldn’t handle some of the corner test cases then he
asked me to modify the code accordingly.
Then he asked me to write all the test cases for it and i did.
For eg; given the resources like this :
case 1 : 6 -6 8 4 -12 9 8 -8 It should return 9 as all others get canceled.
In the above example lists which gets canceled :
6 -6
8 4 -12
8 -8
o/p : 9
case 2 : 4 6 8 -9 10 -9
o/p : 4 6
case 3 : 4 6 -10 8 9 10 -19 10 -18 20 25
O/P : 20 25
F2F Round3 :
Started with a formal introduction and BTW he was the same guy who took my telephonic
interview.
Q1) He asked me subset sum problem i.e; Given an array find the maximum sum contiguous
subarray.
I gave O(n) solution for finding the maximum sum immediately after he asked the question
as i knew the solution.
Then he asked me to trace the code for some test cases and it passed.Then he asked me
to find the staring and end index of the subarray and I modified the code and initially got
wrong but after some modification I got the code right.
Q2) Sum of numbers represented by two linked list .
And i gave the answer immediately after he finished the question. But i gave the soln for
adding two linked list numbers starting from beginning but he told me add the numbers as
we do in normal addition.
And i gave that solution to by reversing the linked list and then adding the numbers and
finally reversed the resultent list.
After 2-3 days i got a call from Amazon that i have cleared the rounds and they asked me
to come for Hirring Manager Round.
One of the interviewer gave me feedback that he mugged the answer as i gave the answer
immediately after the interviewer asked the question as i came to know later which was

673
Chapter 273. Set 267 (8 Months Experienced)

major set back for me.


So one of the advice would be to all of you that Eventhough you know the answer pretend
that you don’t know. Ask some clearification question, As they also observe your problem
solving skills with coding.
Hiring Manager Round F2F :
Started with some basic questions and then asked why do you want to leave your current
comany and then he asked code Of Fibbonacci series.
I explained Fibbonacci series and then he asked me to code it .
I wrote the code and traced on some inputs.
Then he had a meeting as i reached late there so he asked me to improve the code as he
said there is some bug in the code and i did .
After that he asked me to write recursive code for it .
Then he asked the time complexity of the code and i said Exponential.
Then he asked me to prove it.
I said sir i could do it using Master Theorem or using Mathematical Induction. But right
now i remember none of them .
Then he told me that you can do it without Master Theorem or MI . Then in my mind it
striked as Recursion Tree Method but at that time i didn’t had no idea of recursion tree
methodas well. So i couldn’t tellhim.
My this round wasn’t positive as i knew right after my interview. i got eliminated after this
round.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-267-8-months-experienced/

674
Chapter 274

Set 268 (Experienced)

Amazon Interview Experience | Set 268 (Experienced) - GeeksforGeeks


I had worked at TCS,Chennai for 6 months and then was working at SAPLabs,Bangalore for
last one year. I was interviewed at Amazon,World Trade Center for the position of Software
Development Engineer.
Round 1:Written Round
a. Find a pair that sums to zero in a sorted array.
https://www.geeksforgeeks.org/write-a-c-program-that-given-a-set-a-of-n-numbers-and-another-number-x-determin
b. Buy and sell shares to maximize profit
https://www.geeksforgeeks.org/stock-buy-sell/
c. Replace all nodes in BST with its greater sum
https://www.geeksforgeeks.org/add-greater-values-every-node-given-bst/
Round 2:Face to Face
a. Find all anagrams of a given string.
The question is simple but there was a twist,the file size was 1TB.Interviewer asked me to
optimize the solution.I gave a HashMap solution where key was the length of strings in the
file and value was number of such strings.
Finally,I was able to solve the question with Trie data structure.
b. Given a Hotel and checkin/Checkout time of visitors, find the maximum numbers of
rooms required. (different version of Trains/Platform question)
Round 3:Face to Face
a. Find a row with maximum number of 1s in a
binary sorted matrix.I knew this questions before so I got another question
b. Rain Water Trapping problem

675
Chapter 274. Set 268 (Experienced)

https://www.geeksforgeeks.org/trapping-rain-water/
c. Given two strings print all possible permutations of two strings such that the order of
characters are maintained.
I gave a topological sort solution and then a recursive solution.
Round 4:Hiring Manager Round
a.A lot of behavioural questions like weakness,strengths,why leaving previous organization.
b.Detailed description of projects
c.Given an array,generate all valid ip address from the array.
A lot of discussion on this question and finally I gave a hashmap solution to this ques-
tion.Time complexity:O(n)
Round 5: Bar Raiser
a. A lot of behavioural questions,why amazon etc etc
b. Find the longest palindromic substring in a string.
I told him we can reverse the string and find the LCS for both strings.
Full working code was required at each round and time complexity was discussed in detail
for questions. Thanks a lot geeksforgeeks.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-268-experienced/

676
Chapter 275

Set 269 (1 year experienced for


SDE-1)

Amazon Interview Experience | Set 269 (1 year experienced for SDE-1) - GeeksforGeeks
Online Round: 2 Programming questions for 2 Hours

1. Convert set of strings in number as given on phone keypad. String will contain only
lower case characters. Print these strings with numbers in descending order of numbers,
if numbers are same then lexicographical order of strings.
Input: amazon, rat,pat
Output: 262966 amazon
728 pat
728 rat
2. In a M*N maze you can move in any direction(left,right,up,down). There are bomb
on some positions. Starting from (0,0) find the number of moves require to exit from
the maze. Exit point is (m-1,n-1). If its not possible then return -1. Similar to
Minesweeper Game.

1st Round(F2F) 1hr:


Ask everything about project working at current company.

1. https://www.careercup.com/question?id=7449675 in-place. Had to write proper code


for it.

2nd Round(F2F) 1hr:


Asked everything about project and lots of cross questions on the same. Interviewer gave
me lots of scenarios related to my project and ask to solve then.

677
Chapter 275. Set 269 (1 year experienced for SDE-1)

1. https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/ in place. He asked me


if i knew the question, I said yes. Then he told me to write code covering all corner
cases.

3rd Round(F2F) 1hr:

1. https://www.geeksforgeeks.org/find-a-pair-with-given-sum-in-bst/ . Asked all possi-


ble solutions and then asked to write code for it.
2. https://www.geeksforgeeks.org/merging-intervals/. Code for it.
3. http://stackoverflow.com/questions/14094914/count-the-number-of-occurrences-of-a-
number-in-a-sorted-array. O(nlogn). Asked to explain the solution then to write the
code.

4th Round(F2F) 2hr:

1. Correct a deformed BST. All kind of approaches and proper reasoning for each. Then
asked to write the code.
2. Array question. similar to https://www.geeksforgeeks.org/given-a-string-find-its-first-non-repeating-character/
.
3. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/.

All the interviewers were very helpful. In all rounds for every question they were looking
for what kind of approach you are going to use and proper reasoning for the same. Not just
coding , neat and efficient coding was required because for each question at the end you
have to code and they expect you not to miss edge cases.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-269-1-year-experienced-for-sde-1/

678
Chapter 276

Set 272 (On-Campus)

Amazon Interview Experience | Set 272 (On-Campus) - GeeksforGeeks


Round 1: (online in hackerrank)
20 MCQ questions based on outputs, OS, DBMS.
1. Print all possible words from phone digits
2. Given a matrix where elements are inserted as 1 to n in row 0, n+1 to 2n in row 1 and so
on till n^2 and you traverse the matrix in spiral manner, find the kth number you will visit

eg. n = 3
matrix: 1 2 3
4 5 6
7 8 9
k = 4, output: 6
k = 6, output: 8

Round 2: (F2F)
1. Given a boolean matrix find the row with maximum number of 1s
2. Given a pointer to a node of a tree, print the inorder successor. Assume that you have a
function getParent(node) which returns the parent of the node
3. Given a array find the configuration where we will get max sum of i*array[i]
eg: 8312 = 8*0 + 3*1 + 1*2 + 2*3 = 11
3128 = 3*0 + 1*1 + 2*2 + 8*3 = 29
1283 = 1*0 + 2*1 + 8*2 + 3*3 = 27
2831 = 2*0 + 8*1 + 3*2 + 1*1 = 15
max value here is 29 when array is rotated by 1
expected time complexity O(n)
hint: see what goes out and what comes in when the array is rotated. You dont need to
rotate the array

679
Chapter 276. Set 272 (On-Campus)

Some questions that my friends were asked:


1. Root to leaf path sum equal to a given number. Also print the path
2. Given a number n and a pattern that follows like:
(1 to 26): a,b,c,….z
(27 to 52): aa,ab,ac,…az
(52 to 78): ba,bb,bc,…bz
.
.
.
za,zb,zc,…zz
aaa,aab,aac,…aaz
aba,abb,abc,…
.
.
.
find the nth pattern
3. Given a linked list like 1->2->3->4->5->6->7->8
modify it to 1->8->2->7->3->6->4->5
Round 3:(F2F)
1. part 1: Design the snake and ladder game. consider cases like there may be another
ladder at the end of another ladder, or a snake at the end of another snake.
Mainly focus on the data structure you will use to design the game and all cases.
part 2: now that your game is designed, find the minimum number of dice throws/jumps
you will have to make to reach the end i.e. 100 starting from 0
you can control the value that comes up when you throw a dice.
2. Explain heap sort, hipify, percolate_down, time complexity
Round 4:(F2F)
1. OS related questions like what is paging, page faults
DBMS: transactions, ACID property, primary indexing, secondary indexing, multilevel in-
dexing
2. Given an array check if the array can be a preorder traversal of a BST
3. Design a data struct such that insert, delete, findMin(), find() can be done in O(1)
4. Diagonal view of a tree
similar to https://www.geeksforgeeks.org/diagonal-sum-binary-tree/
5. Diameter of a Binary Tree
Round 5:(Telephonic round):
1. About my summer internship
2. OS, DBMS questions
3. Given an array, just make the B-tree of order 3
4. Design STL map
5. Given a tree, connect all siblings. Asked me to give both iterative as well as recursive
approach

680
Chapter 276. Set 272 (On-Campus)

Thanks Geeksforgeeks.
Recruiter at amazon are very friendly. Interact with the interviewer if you get stuck. Try
to come up to different approach to solve the same problem. Their main focus remains on
how you see a problem and try to solve the problem. Don’t jump to code it as soon as you
are given the problem, first discuss it then go for coding if asked. Be confident and don’t
give up if you can’t get the perfect solution.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-272-on-campus/

681
Chapter 277

Set 273 (On-Campus)

Amazon Interview Experience | Set 273 (On-Campus) - GeeksforGeeks


I would like to share my Amazon Interview Experience (for Internship) with your audience.
1st Round (Online Coding Round):
It was 90 min test on Hackerrank. It had 20 MCQs and 2 coding questions. The MCQs
were from topics like time complexity, different sorting algorithms, dbms, os, 3-4 puzzles
and apti, output of the code, etc.
The MCQs had negative marking of 0.50.
Students of CSE, IT, ECE were allowed and there were around 160 candidates.
Coding Questions:
1. Find the first non-repeating character of the string.
2. There is a square matrix of order n which is filled from 1 to n^2 in row major. Find the
Kth element in spiral traversal of the matrix.
Example: Given n=3 and K=5.
Matrix:
123
456
789
Output: 9
I solved both the coding questions and attempted 16 MCQs and qualified for the next round.
It is very important to solve at least one coding question to qualify for the next round.
Second Round (Personal Interview-I):
Time: 40-50 minutes. 31 candidates were selected for this round.
It started with tell me about yourself. Then the interviewer asked me my JEE(mains) rank
and also what data structures I know. She asked me basic tree questions such as what is
tree, what is bst, how many types of traversals are there and to name them. Next, she gave
me this problem:

682
Chapter 277. Set 273 (On-Campus)

1. You are given an array of elements, find out if the array represents Pre-order traversal of
a BST.
I thought on it for few seconds and gave her n^2 logic. Before she asked me to optimize it,
I told her that I can try to optimize it.
Then after thinking about it for few minutes, I told her my O(n) logic.
After listening to my approach, she asked me to code it. I wrote the code without any
error at one go. She asked me the time complexity and space complexity of my code after
checking if its error free or not.
After this, the interviewer asked me theoretical questions on OS such as what is critical
section, mutex, semaphore, virtual memory, page fault, ways of preventing deadlock, etc.
Then she made a simple table and asked me to write SQL query for it which was very easy.
She asked me what is indexing in DBMS, difference between its types and if the query I
wrote is case sensitive or not.
Next the interviewer asked me if I know clone a linked list problem or not.
I said, yes. So the interviewer changed the question.
2. Given an array with both negative and positive numbers, find the maximum sum con-
tiguous sub-array.
I told the interviewer my approach (modification of Kadane’s algorithm). And she asked
me to write the code. I wrote the code without any errors.

Third Round (Personal Interview-II):


Time: 80-90 minutes. 8 candidates were shortlisted for this round.
First the interviewer went through my resume and asked me about my recent project. Then
he asked me if I am comfortable with trees. I said yes. He asked me:
1. https://www.geeksforgeeks.org/vertical-sum-in-a-given-binary-tree/
I told him the approach and he asked me to write the code. I wrote the code without any
error.
Then he asked me theoretical questions. Started with virtual memory concepts, next he
wrote a code and asked me if there was any error. Then he asked C/C++ questions based
on malloc/calloc, new operator, etc. A tricky question on exception handling. There were
many other theoretical questions which I don’t remember.
2. Then he gave me this problem:
There are n number of people required to do some tasks. Among these n persons, some x
number of person require a key to start their work. There are infinite keys which are thrown
one by one in front of people in every unit time. The time required by a person to pick up
the key is one unit time. Furthermore, the interviewer mentioned conditions such as some
particular person can only start after some other particular person finishes his task. The
time required by a person to finish his task is one unit. He asked me to find the minimum
time in which all people finish their task.
After thinking for few minutes, I told the interviewer my approach using topological sorting
in graph. Then he asked me to explain topological sorting in detail. Then he moved on to
another question.

683
Chapter 277. Set 273 (On-Campus)

3. You are in a forest and there are many paths. You need to get out of the forest. Which
path do you choose?
It was a problem of finding the minimum distance between source node and destination
node in a graph.
I told him my approach and then he asked me to explain dijkstra’s algorithm. Then the in-
terviewer asked me the difference between dijkstra’s algorithm and floyd-warshall algorithm.
Then he asked me about prim’s algorithm and kruskal’s algorithm.
Then he gave me another interesting problem.
4. For each node of a binary tree, you are given the node id and sum of the ids of its children.
Find the node id of the root.
After few minutes I came up with a wrong approach. As soon as I told the interviewer about
it, I understood I was wrong. Then he told me to focus on the sum of the ids. Then within
a minute I told him another approach. He asked me why this works, I explained him and
he was satisfied.
After that the interviewer asked me if I had any questions for him. At last, he again asked
me about one of my project in which I used Alexa.
Keeping calm will help you come up with a correct solution faster, ask questions to inter-
viewers if you have any doubt, they are very friendly. Practice questions from geeksforgeeks.
It helped me a lot. Thank you geeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-273-on-campus/

684
Chapter 278

Set 274 ( On-Campus)

Amazon Interview Experience | Set 274 ( On-Campus) - GeeksforGeeks


Round 1: (Online in Hackerrank)
20 MCQ questions based on outputs, DS, OS, DBMS.

1. Print all possible words from phone digits – https://www.geeksforgeeks.org/


find-possible-words-phone-digits/
2. Given a matrix where elements are inserted as 1 to n in row 0, n+1 to 2n in row 1
and so on till n^2 and you traverse the matrix in spiral manner, find the kth number
you will visit.
eg. n = 3
matrix: 1 2 3
456
7 8 9k = 4, output: 6
k = 6, output: 8

Round 2: (F2F)

1. . Sort an array of 0’s,1’s and 2’s. – https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/


2. Given a linked list like 10->8->3->4->5->6
modify it to
4->2->-1->4->5->6
The last number is subtracted from first number, 2nd last from 2nd number and so
on till middle of link list.
First gave him a brute force approach O(N^2) , then O(N) approach in which reverse
of 2nd half of list is done. He told to do this without reversing the list.
Then used a stack and gave him final solution.

Round 3 : (F2F)

685
Chapter 278. Set 274 ( On-Campus)

1. Given a number n and a pattern that follows like:


(1 to 26): a,b,c,….z
(27 to 52): aa,ab,ac,…az
(52 to 78): ba,bb,bc,…bz
.
.
.
za,zb,zc,…zz
aaa,aab,aac,…aaz
aba,abb,abc,…
.
.
.
find the nth pattern
2. Convert a Binary Tree to Doubly Link List in place- https://www.geeksforgeeks.org/
convert-given-binary-tree-doubly-linked-list-set-3/
3. Clone a graph and analyze the time and space complexity. First did it using two
traversals of BFS and using map. Then did it using one traversal of BFS and map.

Round 3:(F2F)

1. Count the number of inversions in an array- https://www.geeksforgeeks.org/


counting-inversions/
2. Tell a data structure which you will use to implement best fit algorithm. I told him
BST. Then he asked me to implement it.
https://www.geeksforgeeks.org/floor-and-ceil-from-a-bst/\
3. Longest Common Subsequence (Both recursive and dp approach)
4. Box stacking Problem – https://www.geeksforgeeks.org/dynamic-programming-set-21-box-stacking-problem/
5. One DBMS query select 2nd max salary from table,
6. OS questions from deadlock, synchronization, scheduling, diff between process and
thread.

Round 4:(Telephonic round)

1. About my summer internship


2. OS, DBMS , OOPS questions \
3. https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
4. What happens when you type URL in browser and hit enter? Explain in detail.
5. Given a number in form of array and number K you have to form largest number after
swapping elements K times.
You can swap only adjacent elements
e.g Array -> 4 5 7 8 2 3
K=2
Output -> 7 4 5 8 2 3
Only algo was needed.

Thanks GeeksforGeeks. Placed@Amazon

686
Chapter 278. Set 274 ( On-Campus)

Recruiter at amazon are very friendly. For each question working code was expected and
time and space complexity was asked.
Interact with the interviewer if you get stuck. Try to come up to different approach to solve
the same problem. Their main focus remains on how you see a problem and try to solve the
problem. Dont jump to code it as soon as you are given the problem, first discuss it then
go for coding if asked.
Be confident and do not give up if you cant get the perfect solution!!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-274-on-campus/

687
Chapter 279

Set 275 ( Off-Campus SDE-I


Experienced)

Amazon Interview Experience | Set 275 ( Off-Campus SDE-I Experienced) - GeeksforGeeks


I was interviewed in Delhi for SDE-I position in Kindle Frameworks Team at Amazon. I
was working as a Project Lead in Samsung, Noida and had a total experience of 1 year 10
months in the Software Industry.
Round 1 : Written

• Print Boundary Traversal of a Given Binary Tree – https://www.geeksforgeeks.org/boundary-


traversal-of-binary-tree/
• Add Two Numbers Represented by Linked Lists – https://www.geeksforgeeks.org/add-
two-numbers-represented-by-linked-lists/
• Print all Possible Permutations of a Given String by Placing Spaces (zero or one)
– https://www.geeksforgeeks.org/print-possible-strings-can-made-placing-spaces/

There were about 80 candidates and the time allotted for this round is 1 hour. I was able
to write all the 3 codes correctly in just 20 min and was the first candidate to move onto
the second round.
Round 2 : Problem Solving (F2F)

• Median of Two Sorted Arrays –https://www.geeksforgeeks.org/median-of-two-sorted-arrays/


• Equal Size – https://www.geeksforgeeks.org/median-of-two-sorted-arrays/
• Different Sizes – https://www.geeksforgeeks.org/median-of-two-sorted-arrays-of-
different-sizes/
• Maximum Size Square Sub-matrix with all 1s in a Given Boolean Matrix –
https://www.geeksforgeeks.org/maximum-size-sub-matrix-with-all-1s-in-a-binary-
matrix/

Round 3 : Design and Data Structures (F2F)

688
Chapter 279. Set 275 ( Off-Campus SDE-I Experienced)

• Behavioral Questions :
– Tell me about your Current Projects in Samsung.
– What are your responsibilites as a Project Lead ?
– Why do you want to join Amazon when you are doing so good in Samsung ?
– At last a 15 min discussion about the most difficult problem I ever faced and how
I tackled it with my coding skills and knowledge.

• Given a Sorted Dictionary of an Alien Language, Find Order of Characters


– https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
• What do mean by Dynamic Binding and Virtual Functions in C++ ? https://www.geeksforgeeks.org/virtual-
functions-and-runtime-polymorphism-in-c-set-1-introduction/
• Discussion about Mutexes, Semaphores, ISR (Interrupt Service Routines), Deadlocks.
https://www.geeksforgeeks.org/mutex-vs-semaphore/

The interviewer was highly impressed with my coding skills and shook hands with a sense
of approval.
Round 4 : Hiring Manager (F2F)
The Hiring Manager introduced himself and told me that I’ve been doing really great till
now. Then he grinned at me and said “ Lets hope you don’t mess it up in this round “ .
(1) Which Sorting Algorithm is the fastest and why would you prefer it over others ?
While telling the answer, I said in between “ If there would have been millions of numbers……
“ and he caught that specific word of mine “millions” and hence the next 2 questions found
the way on their own.

• In a city with millions of people, I want to sort them on the basis of their age.
Which Sorting Algorithm would you use and why ?There’s a Galaxy with Billions
of Stars and distance of each star from the Sun is given . I want the closest 1 mil-
lion stars from the Sun. Which Data Structure would you use and what would be
the complexity ? (It is a variation of Finding K Smallest Elements in an Array)-
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/
• Find distance between two given keys of a Binary Tree https://www.geeksforgeeks.org/find-
distance-two-given-nodes/

He scrutinized the entire code for any possible errors and found it perfect.

• Discussion about Inner and Outer Joins in SQL. http://quiz.geeksforgeeks.org/inner-


join-vs-outer-join/

Then he stood up and shook my hands with a broad smile and said “ Well Done Man ! ”
and left.
Round 5 : Bar Raiser (F2F)

689
Chapter 279. Set 275 ( Off-Campus SDE-I Experienced)

• Design an Algorithm to Transform One Word to Another through Valid Words


of a Given Dictionary. (It is clearly a variation of the Edit Distance Problem, but
in Edit Distance we do not care about if the intermediate word is valid or not) .-
https://www.geeksforgeeks.org/dynamic-programming-set-5-edit-distance/

Only this question was asked in this round and the discussion went on for about 45 minutes.
All credit goes to https://www.geeksforgeeks.org/ team for providing such an inspirational
and a brilliant platform for coders. Keep it up guys, Way to go !
Suggestion for other candidates interviewing at Amazon :

• Try to write Neat and Clean codes without any cutting or hassle, taking care of all
the boundary cases.
• Be very precise and explicit in your answers. Keep Coding and All the Best !

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-275-offcampus-sde-i-experienced/

690
Chapter 280

Set 276 ( On-Campus SDE-I)

Amazon Interview Experience | Set 276 ( On-Campus SDE-I) - GeeksforGeeks

• Round 1(Online test : MCQ+Coding)


– 18 basic MCQ from OS, C, Shell, DBMS(SQL, NoSQL), puzzle(25 horses, find
fastest three) :attempted 12/13
– 2 Coding questions:
1. Given a string and a pattern state whether it follows the pattern. For eg: s
= “redblueredgreen” matches pattern “abac” but not “aaab” as ‘red’ means
‘a’, ‘blue’ means ‘b’ and ‘green’ means ‘c’ here. String s only contains words
“red”, “green” & “blue” and pattern can have any character.[Done]
2. Given a number n and k(no of swaps allowed), make the biggest number from
n by making at most k swaps. If its already the biggest return the number
itself.

• Round 2(F2F) 1. Given two arrays containing numbers find all possible orderings
(a, b) such that a*b=P(given product) where a belongs to array 1 and b belongs to
array b.
Approach: Store all elements from shorter array in hash and traverse the other and
find if (P/b) is present in the hash. If present print the ordering.

1. Given a circular road having gas stations at varying distances on the road. The cost to
move from one station to another is given. You can refuel at each stations with all the
present at the station as the tank capacity is infinite. Find if its possible to traverse
the complete road and if yes then find the starting position to finish the route.
Approach: Start from beginning and start traversing the road. If fuel finishes at any
point then move the start index backwards and add its gas to the tank. If its still -ve
then keep doing it until you have enough to move forward.

• Round 3(F2F)

691
Chapter 280. Set 276 ( On-Campus SDE-I)

1. Given a N*M matrix, print all squares/rectangles of all possible sizes(all 1*1,
then all 1*2…. 2*1… )
Approach: Brute Force
2. Serialize a Binary Tree
Approach:
(a) Store any two traversals. But it takes a lot of space.
(b) Store all the nodes and store for each node the information if it has left &
right sub-tree or not in a Boolean array.

• Round 4(F2F) 1. Function to find optimal selection of packages from amazon ware-
house. Packages contain varying units of a product for eg: one can have 5 units of
iphones another can have 3 and so on. Each package is present infinitely ie. take one
then there are still infinite left. You can break into a package, you have to take it as
a whole. Also, smaller size packages should be used first. Lot of modifications.
Approach: Suggested subset sum dp solution. Couldn’t handle infinite case properly.
2. Add one to a given number represented using a linked list where MSB was at tail
and LSB at head.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-276-on-campus-sde-i/

692
Chapter 281

Set 277 (On-Campus for


Internship)

Amazon Interview Experience | Set 277 (On-Campus for Internship) - GeeksforGeeks


Recently Amazon visited our campus for interns and placements. For interns it consisted of
1 online + 2 technical rounds.
Online:(90 mins)
20 MCQ’S based mainly on sorting, OS,Networks
2 coding questions:
1. Given a number find the next greatest number formed with same digits
https://www.geeksforgeeks.org/find-next-greater-number-set-digits/
2. Find the largest increasing sequence in an array
https://www.geeksforgeeks.org/dynamic-programming-set-3-longest-increasing-subsequence/
Round 1:(40 mins)
The round started with discussion on projects,my strengths for first 20 mins
Then he asked me to write full working code covering all edge cases for
1) Finding nth node from end of linked list
2) Deleting nth node from end of linked list
Round 2:(45 mins)
1. Find the last non-repeating integer in a stream of integers in O(1) time complexity
2. https://tkramesh.wordpress.com/2011/02/15/kite-cutting-more-on-dynamic-programming-4/
Practice Amazon Interview Questions.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-277-for-internship/

693
Chapter 282

Set 278 (On-Campus)

Amazon Interview Experience | Set 278 (On-Campus) - GeeksforGeeks


Recently Amazon visited our campus for recruitment process. They conducted several
rounds based on the interviewee’s capacity.
Round 1:
90 minutes
20 MCQs and 2 Programming Questions.
Programs were based on Strings and Arrays.
The modules were already given by the company itself.
The first was conducted in HackerRank.
Round 2:
75 minutes.
Pen and paper test.
It is also a programming round.
The number of questions will be get increased based on your solving ability within that 75
minutes.
They need O(1) solution for those questions, if it possible. Otherwise, they need the best
solution for the given question.
They sat in front of me and assess my code.
Programming language is not a matter. You can use your preferable language. I prefer
Python and C programming.
Note: They are very clear in this. Don’t use any inbuilt functions. Sometimes, even striking
out the code was not allowed.
Round 3:
45 – 60 minutes
They ask me 2 programming questions and 3 testing and troubleshooting questions.
As usual, for coding they need only the best solutions.
For testing and troubleshooting, they need at least 30 – 40 test cases and troubleshooting
techniques.
For me, He didn’t ask me to stop until i write 35 for each.

694
Chapter 282. Set 278 (On-Campus)

I wrote 35 as minimum and 68 as maximum.


While you writing the solutions, they thoroughly go through your resumes and ask questions
from that.
After the third completed, You can ask questions to the HR before you come out from the
panel.

Round 4:
Hiring Manager round
This round is different from other rounds.
For me, its 1 hour 45 minutes.
But some of my friends have different timings like 15 to 20 minutes and 45 to 60 minutes.
In this round, there are two HRs for me.
They gave their Self intro with awesome communication. Really awesome.
They ask,
Self Intro
Project Explanation
Testing for my Project
Testing for the project and scenario given by us – I wrote 94 test cases (when I get ready
for 95th test case , she asked me to stop and said, “its enough..” ) .
Troubleshooting for the test cases provided by me to my Project – I wrote 60 test cases.
Troubleshooting for the test cases provided by me to the project and scenario given by us.
Then they ask Database queries and questions.
Programming question based on the File Management System – For this also, I prefer C
Data Structures and Python – The expect more number of solutions as well as the best
solution.
Communication was checked.
Culture fit questions.
Then, question session for me to them.
At last, they said, “Thank you Sathish , we done the interview. We will give the results to
your Placement officer.”
Thank you GeeksForGeeks :
Because, I prefer GeeksforGeeks for my programming preparations. You played a major
role in my placement.
Practice Amazon Interview Questions.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-278-on-campus/

695
Chapter 283

Set 279 (On-Campus for


Internship)

Amazon Interview Experience | Set 279 (On-Campus for Internship) - GeeksforGeeks


Recently Amazon visited our campus. There were total three rounds.
First round was an online coding round conducted on Hackerrank, It consisted of 20 Mcqs
based on Data Structures,Sorting Techniques,Operating systems,Networking and some ap-
titude questions along with 2 coding questions,
The questions were:
1. Sort a linked list which consists of only 0s,1s and 2s.
2. Find the maximum product of three elements in an array which consists of both +ve and
-ve numbers.
I Was able to solve both the coding questions in 15 minutes.
Out of 142 students that appeared, 33 were selected for the next round.
F2F-1
The Interviewers were very friendly and made me comfortable.
The questions asked were:
1. From an Inthreaded B.S.T delete all the nodes with a single child and explain its com-
plexity.
2. A sorted array is rotated K times, find the index of the largest number.(A modified
binary search can be used for this).
3. Largest Palindromic Substring from a string.
A total of 15 students out of 33 were selected for the final round.
F2F-2
1. Find median of infinite stream of integers.
2. Find all subsequences of a string.
3. Divide an integer array in 2 parts such that their sum is equal.

696
Chapter 283. Set 279 (On-Campus for Internship)

At the end 9 people were selected.


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-279-on-campus-for-internship/

697
Chapter 284

Set 280 (Off-Campus)

Amazon Interview Experience | Set 280 (Off-Campus) - GeeksforGeeks


Hiring event in Delhi for Amazon Bangalore. First was written programming test and we
needed to write full working code without a single bug. Guys please focus more on written,
sometimes we don’t take this serious and write code with many bugs.
Written Round:
Write most optimized solution for all problem.
1. Check a linked list is palindrome or not.
2. Search an element in a row and column wise sorted matrix.
3. Number of bits we need to flip from A to get B.
Problems are easy and can be solved if you have practiced for sometime from geeksforgeeks
but the major part was writing clean and bug free code with most optimized solutions.

F2F – 1
After clearing the written round I went for first F2F round.
1. There is one class which has private array list and this array list is initialized in
constructor of this class.
We have one public method getItem(int i) { ” return ith item of array list” }, We need to
know the size of array list. We can only call getItem method.
https://ideone.com/VaE0QL
Please check the above code for more details.
2. Search an element in a BST.
3. Given a set of time intervals in any order, Print all the pair of overlapping intervals .
4. My college project was on RTOS (Real Time OS) and interviewer also did the same
project when he was in college , so we had lot of discussion on project.
He was very impressed.

F2F-2
Here is F2F round 2 where I was not able to give optimized approach for the first problem.
1. Given a string and he asked me to find Longest Repeated Substring in the given string.

698
Chapter 284. Set 280 (Off-Campus)

2. Given a mXn matrix with no obstacle and we can move in right or down direction. Count
the no of paths to reach from top left cell to bottom right.
I gave recursive solution with 2^n complexity and then optimized the solution using memo-
ization.
3. Create sorted list of all unique partitions of given number 5 = { {4, 1}, {3, 2}, {3, 1, 1}
…. }
https://www.geeksforgeeks.org/generate-unique-partitions-of-an-integer/
This round didn’t go well and I was praying L Finally HR came and said you haven’t
performed well in this round so you will have another technical round and I was like “ok no
problem”.

F2F – 3
Finally last round of the day and I knew I have to perform well otherwise I have no chance.
1. You are given a dictionary and a string. You need to check the string is valid (exist in
given dictionary) or not, if its not valid then perform one of the three operation (Insert ,
remove , replace) on string and get a valid string. We need to find another string which
has One edit distance with this string.
Interviewer asked me about the data structure used to implement the Dictio-
nary. I suggested Trie for dictionary. After some discussion he asked me to write
code for insert in Trie and for the above problem.https://www.geeksforgeeks.org/
dynamic-programming-set-5-edit-distance/
2. How to implement Trie. Space optimized version.
This was part of 1st problem and we had discussion on space of a trie when we have 500-600
characters in some language. I suggested HashMap instead of using static array in Trie.
And then he asked me to write structure and Insert method.
3. Max sum tree . every node has its value plus maximum of left and right sub tree sum.
Expected time complexity O(N).
After this round HR told me to leave for the day and I will have one more technical and
one Hiring manager round.
I was happy that I completed all the round.
4. Find maximum sum rectangle in given matrix.

F2F – 4 (Technical plus behavioural)


1. Find the maximum element in an array which is first increasing and then decreasing.
2. Project discussions.
3. Anything that you have done out of your responsibility.( In technical part )
4. Any situation when your manager really appreciated your work.

Telephonic Round with hiring manager.


This was my last round of the process and it was with hiring manager.
1. Tell me about yourself.
2. Your day to day work at current company.
3. Discuss any project which.
4. Any disagreement movement with your manager.
5. Why Amazon? and why are you leaving current company?

699
Chapter 284. Set 280 (Off-Campus)

Guys prepare hard for behavioural questions, these questions are asked to know the person.
Then 2 easy programming questions but again the measuring part was code and the way
we explain our solution.
1. Check a string is palindrome or not.
2. Count no of words in a string.
He asked me to write test case for both the problem.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-280-on-campus-for-internship/

700
Chapter 285

Set 282 (On-Campus)

Amazon Interview Experience | Set 282 (On-Campus) - GeeksforGeeks


I have just entered my third year and Amazon was the first company to visit our campus
for Software Internship. The process was :
ONLINE ROUND
2 Coding questions and 20 MCQs . The coding questions were:

1. http://quiz.geeksforgeeks.org/lexicographically-minimum-string-rotation/
2. It was an easy string question similar to finding that the parenthesis are balanced or
not . Instead of the parenthesis , a and b were to be checked for , For eg )
ababab is balanced ;Its a good string
abbbaa is a bad string .

I had practised MCQS from http://quiz.geeksforgeeks.org/quiz-corner/ and many of the


MCQs I had seen here before that were asked in the test. Sorting, hashing, complexity, re-
cursion based MCQs were asked .
Also, 2 questions on OS , 1 on Networking and 1 on DBMS was present . I did not attempt
these since there was negative marking . I solved around 14-15 MCQs and both the coding
questions . (However, some students completing 1 were also selected .)
ROUND 1
1. https://www.geeksforgeeks.org/serialize-deserialize-binary-tree/
2. Spiral level order traversal of a binary tree from bottom level to top level.( I was allowed
to use extra space(O(n)) .)
ROUND 2
This round was easier than the previous one for me and went smooth .

1. Set the rows and columns of a matrix equal to zero if an element in that row or column
is zero (The elements could be positive or negative too ). I told him the solution using
O(n) space . He then asked me to do it without the auxillary space and I told him

701
Chapter 285. Set 282 (On-Campus)

that it was not possible . (A solution without space could be given if all the elements
were either non-negative or non-positive )
2. Merge k sorted linked lists . I discussed the approach using priority queue . Then he
proposed another method of merging two lists into one and then merging it with the
next . I explained him the complexities of both the approaches and then wrote the
code for priority queue approach . He was impressed.

I would like to thank GeeksforGeeks for providing a huge set of problems for practicing
for interviews. The internship archives were extremely helpful . Also I practiced on https:
//practice.geeksforgeeks.org/ and interviewbit regularly in the summer break.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-282-on-campus/

702
Chapter 286

Set 283 (On-Campus)

Amazon Interview Experience | Set 283 (On-Campus) - GeeksforGeeks


Recently I got interviewed at Amazon on campus. The process was :
Online Round :
———————-
A hackkerank contest with 22 questions inclusive of 2 coding problems and 20 MCQ’s on
OS,Aptitude,DBMS .
Coding Questions :
1. Given a 2d array with only elements ‘#’ & ‘.’ . ‘#’ represents cherry and ‘.’ represents
nothing . Can you divide the array into 2 halves with equal cherries . You could only make
a single cut either horizontal or vertical .
2. Sliding Window of size k . Find max of each window.
Round 1 :
——————
Problem 1: Search in rotated and sorted array .
Interviewer wants all corner cases covered code .And also Max optimized time complexity .
I gave a O(2*logn) solution he got satisfied .
Problem 2: Given a number k , Find no. of ways to make this number using sum of numbers
from 1 to k-1 . Also You cannot take same number more than once in a combination and
also all permutations of a combination count as one way .
For eg: if k= 6, Then all permuations of (1,2,3) count as one way only.
I got shortlisted after this round .
Round 2
————-
It consists of a single problem only but a detailed discussion on that .
Problem : Range Minimum Query .i.e Given an array and a range query (xi,yi) find min
element in the range (xi,yi) . These queries can be very large .

703
Chapter 286. Set 283 (On-Campus)

First i gave bruteforce approach and after that I gave a segment Tree solution to that with
time and space complexity .
He then asked what if we have to update an element and then followed by updating a range
.
After that he asked what if we delete an element . How do you modify your solution to
cope-up with that .
I suggested him to update the element with INT_MAX and maintain a mapping array .
After that he asked what if we add an element in the array ? .
I suggested him to reconstruct segment tree based on that . He suggested to construct it
like a binary root instead of array representation and store the range . There can be some
re-usable subtrees . How can i found those subtrees and how to use them and what will be
the time complexities.
Lastly i was told to code range minmium query with node having following properties
(min,start,end,node* left,node* end ) ;
He got impressed .:)
Round 3
————–
It also consist of only a single problem .
Problem : Given set of coordinates find top k elements whose distance from origin in
maximum .
I gave naive approaches and heap approach . Later he asked me to think more then i come
up with Quick-Sort Partition function approach .
He asked me to code it .
Round 4
—————
It was easiest of all so far .
It consist of problem : Given 2 linked list subtract them and store the result in bigger one
and return that .
Basically he wants us to cover all corner cases for this .
After that a discussion on projects took place.
Thanks Geeks For geeks for huge programming problems database . Doing a great Job � .
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-283-on-campus/

704
Chapter 287

Set 285 (On-Campus for


JD-SDE)

Amazon Interview Experience | Set 285 (On-Campus for JD-SDE) - GeeksforGeeks


There were 5 rounds in total.
Round 1:
MCQs based on mainly OS and OOP.
Q.1 Tell whether a matrix containing 0s and 1s can be divided into 2 sub matrices containing
equal number of 1s.
Q.2 Find maximum elements in an array in windows of size 3.
Technical Interview 1:
Q.1 Discussion on projects
Q.2 Some simple question involving unordered map. Then asked me to first implement the
map and then use it.
Q.3 Several questions on OS (semaphores, mutex, scheduling)
Technical Interview 2:
Q.1 K-heavy problem. Given a binary tree, you need to prune it such that the final tree
contains all root-to-leaf sums more than equal to k.
Q.2 Sort m arrays each of size n. He wanted the divide and conquer approach.
Technical Interview 3:
Q.1 Several questions on CN (Protocols, IP Addressing, High level design of a server system
used in companies like Amazon)
Q.2 Sort a string in linear time.
Q.3 At Amazon.com, users log in and access random pages numbered as 1,2,3… Given at
any time, you need to tell the most popular sequence of 3 pages visited by users.
Eg.
At some time t,
U1: P1, P2, P3, P8, P1, P2
U2: P8, P1, P2
O/P: P8, P1, P2

705
Chapter 287. Set 285 (On-Campus for JD-SDE)

At time t+1, say


U1: P1, P2, P3, P8, P1, P2, P3
U2: P8, P3, P2
O/P: P1, P2, P3
Technical Interview 4:
Q.1 Given an array containing 0s and 1s your aim is to convert all 1s to 0s. You can only
use an auxiliary function for doing this (No swapping or modification to order of elements
can be done otherwise). The auxiliary function void flip(int index) toggles all the elements
to right of index and index itself. You need to return the minimum no. of calls required to
complete the task. Linear time is expected.
Also consider time complexity of flip function while doing complexity analysis.
Q.2 Tricky question which involved usage of hashing in Rabin Karp algorithm. Dont re-
member the exact question.
Note:
50/250 were shortlisted after MCQ round.
19/50 were shortlisted after 2 tech interviews.
16/19 were placed after next 2 interviews.
OS, CN and OOP is a must in addition to DS problems. All the best.
A big thanks to geeksforgeeks for providing such wonderful platform!
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-284-on-campus/

706
Chapter 288

Set 286 (On-Campus)

Amazon Interview Experience | Set 286 (On-Campus) - GeeksforGeeks


Round 1 (Online on HackerRank)
Duration: 90 minutes
20 MCQ questions mostly based on Operating System, Data Structures and Algorithms and
a few puzzles.
2 coding questions
1. Given a string (which may or may not be a palindrome) of length ‘n’. Also given ‘k’
(0 <= k <= n), such that ‘k’ represents the maximum number of characters of the string
that you can replace to convert it to a palindrome. Your task is to convert the string to
maximum palindrome that can be formed by replacing the string with digits 0-9. If it isn’t
possible to convert the string to palindrome, print “-1”.
Note: Leading 0’s in the string are also considered to be a part of palindromic string. Eg.,
00100 is also a palindrome with leading zeros.
Test Cases:
i. n = 4, k = 2. Given input string “1111”, then the output string would be “9119”
ii. n = 4 k = 1. Given input string “1231”, then the output string would be “1331”
2. Given a text and pattern string. The pattern consists of the following characters
‘+’: It can be replaced with 0 or more occurrence of the previous character
‘*’: Matches any sequence of characters (including the empty sequence)
‘?’: It can be replaced with single occurrence of any character
You task is to determine if the string and pattern match after successfully replacing the
special characters in the pattern with the above rules. Print “true” if the text and pattern
match else print “false”
Test Cases: The first string is the pattern and the second string represents the text

i. Input : Am?zon Amazon


Output : true

707
Chapter 288. Set 286 (On-Campus)

ii. Input : Am?z*on Amazon


Output : true

The MCQs were pretty easy to solve if the concepts are clear. The code was manually
verified by team and then students were shortlisted based on the quality of code and overall
score.
Round 2 (F2F) Duration: 60 minutes
The interviewer was in a hurry I felt and he asked me some basic questions like “tell me
about yourself?” and then we discussed about my internship and it went on for 10 minutes
before he came up with a question.
1. Design the shuffle button of a music player such that it maintains random property and
make sure that it plays all the songs uniquely in a cycle (i.e, no song should repeat itself
unless all other songs in a particular cycle are played)
I initially gave him an O(nlogn) approach. He wanted me to optimize it and after some
pen and paper work I came up with an O(n) approach and the interviewer seemed to be
satisfied.
Round 3 (F2F) Duration: 70-80 minutes
The interviewer was very friendly and made me comfortable by offering some snacks and
water. Later he asked me to give my best shot and to not fool him if I had already heard
of the problems he was going to ask. He asked me to tell few lines about myself and then
discussed about my internship for 5 minutes and then fired few questions.
1. Traffic Car Problem. Given n people and n+1 parking slots. Each person has a car and
a parking slot allocated. One night they all go to a party and get drunk. They end up
parking their cars randomly. What’s the best way to go back to the initial configuration
(one where every car is in the right allocated slot). n+1th parking slot can be used to swap
the cars.
I told the interviewer that this question was asked to one of my friends and that I discussed
it with him. He seemed impressed with my honesty. He then moved on to ask the next
question.
2. A variation of stock buy sell to maximize profits problem : https://www.geeksforgeeks.
org/stock-buy-sell/
3. Trapping Rain Water Problem : https://www.geeksforgeeks.org/trapping-rain-water/
Tips: Keep the interviewer involved in the discussion. Give him the approach and if you
are not thinking in the right direction, they are always there to guide you. Don’t jump to
the code as soon as you are given the problem.
I coded the last two problems after explaining him the logic behind it and the interviewer
seemed to be satisfied.
Round 4 (F2F) Duration: Around 90 minutes
Initially there was only one person who was interviewing me but then he was joined by
another person and it looked that I needed both of their approval to move into the next
round.
1. We started off with discussing my previous internships. He was very curious to know about

708
Chapter 288. Set 286 (On-Campus)

what were my key deliverables as an Intern and also seemed to learn from my experience at
those firms.
2. Count ways to reach nth stair : https://www.geeksforgeeks.org/count-ways-reach-nth-stair/
I first explained him how the result can be derived and then after he was satisfied with the
logic, gave him a recursive approach, followed by the memorization approach and then the
iterative Dynamic Programming approach.
3. Tree Isomorphism Problem : https://www.geeksforgeeks.org/tree-isomorphism-problem/
Logic was given and then I coded it. He still didn’t seemed to be satisfied and asked me to
walk him through my code for an example tree and draw the recursion tree for the same.
4. Dynamic Programming (Longest Arithmetic Progression) : https://www.geeksforgeeks.
org/length-of-the-longest-arithmatic-progression-in-a-sorted-array/
5. He asked me to design a student database efficiently.
Raw thinking was what he wanted I felt.
6. Few DBMS related query questions that were simple to answer.
Round 5 (F2F) Duration : 100-120 minutes
The interviewer was very friendly at the beginning. He became little strict as the interview
went on and in the end he again turned back to the amicable mood he started with �
1. We started off with discussing my internships in detail. This went on for about 30 minutes
until he was satisfied with that fact that I had put in lot of effort in making it a successful
project.
2. Stock buy sell problem which was asked in the second round. I told him that this was
asked to me in the earlier rounds and he seemed to be impressed with my honesty. I guess
I got some loyalty marks there.
3. Connect the nodes of the binary tree in the same vertical level by using the next pointer.
The tree could have nodes with at most two parent nodes.
Approach was given and he didn’t seemed to be fully satisfied with my code at first, but
then after some optimizations he said it seems to be fine now.
4. Few question on Paging, Collision Resolving techniques, Page replacement algorithms.
Probably the interviewer wanted to make sure that the new hire is well familiar with other
subjects other than DSA. He seemed to be satisfied with the answers.
5. Why Amazon?
The standard question that everyone is asked in the end of the last round.
Thanks GeeksforGeeks.
Tips: Try to be calm and give the interview. The interviewers are very well experienced
and they not only test your technical skills but also read your expressions (on how well
you respond to what they ask). Sometimes luck might not be on your side, so do not get
disappointed even if you are rejected. Keep practicing and indeed you will crack some good
firm soon �
All Practice Problems for Amazon !

709
Chapter 288. Set 286 (On-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-285-on-campus/

710
Chapter 289

Set 287 (On-Campus)

Amazon Interview Experience | Set 287 (On-Campus) - GeeksforGeeks


Amazon visited our campus for SDE-1. Interview process started with an online coding
round followed by 4 face to face interviews. All interview rounds started with brief intro-
duction about me.
Online Round :
A hackerank contest with 22 questions consisting of 2 coding problems and 20 MCQ’s on C,
OS, DBMS, Networking.
Coding Questions :
1. Given a 2d array with only two elements ‘#’ & ‘.’ . ‘#’ represents cherry and ‘.’ represents
nothing. Can you divide the array into 2 halves with equal cherries. You can only make a
single cut either horizontally or vertically.
2. Sliding Window of size k . Find max in each window.
No need of optimization, brute force was accepted.
F2F 1 (30 minutes , Director + Technical)
1.You have a 2-d matrix , you have to print matrix in Spiral Order Form. Production code
was required.
2. What is the most funniest and craziest data structure you have ever used.
I said Segment Trees. He asked me to explain it. Why to use it, explain it through some
example, prove its complexity.
F2F 2 (40 minutes, Technical )
1. You have a 2-d array (m*n) , where every row and column is sorted in increasing order.
You have to return an array which is sorted (basically have to sort given 2d array)
Approach 1- insert all elements in map/set . ( O(mnlog(mn)) ) .
Approach 2- insert first element of each row in a heap (same as sort k sorted list of equal
length), then call extract-min and insert next element from the required row.
Complexity- O(mnlog(m) )

711
Chapter 289. Set 287 (On-Campus)

Follow up question- what if m>>n ?


Solution- Transpose the given matrix and follow the same procedure as above.
2. Given a binary tree containing positive and negative values, you have to find maximum
sum that passes through parent. ( O(n) solution was required ).
Proper code was required for both the questions.

F2F -3 (1 hour ,Technical )


Several questions on Operating Systems and Computer Networking.
Operating Systems- Difference between multi -tasking, multi-processing and multiprogram-
ming, Virtual Memory, why to use Virtual memory, issues related to virtual memory ,
paging, segmentation , multithreading, difference between process and thread.
Computer Networking- What happens when you type www.amazon.com in Web Browser,
how server handle requests, how routing works, difference between HTTP and HTTPS, how
TCP works.
Coding Question- Given an array, find min element in the range (xi,yi) . Queries can be
very large.
First i gave brute force approach (0(n) for each query ) and after that I gave a segment Tree
solution to him. He told me to prove time and space complexity.
Follow up question- What if we delete some element from segment tree. How do you augment
your data structure.
I said that instead of deleting we can update it to INT_MAX value.
F2F-4 (1 hour, Technical)
Given a string consisting of 3 types of brackets ( ‘(‘, ‘{‘, ‘[‘ ) , there are priorities assigned
to each bracket. You have to check if given string is balanced and valid.
Definition of valid- Higher priority bracket can’t be inside lower priority bracket.
I solved it by a single Stack .
Follow up question-
Find the length of longest valid substring which is balanced and valid.
Then he asked if you have any questions.
Interview tips-
Interviewers don’t want most optimized solution. They see how you approach a question ,
Interact with interviewer if you get stuck ,don’t jump directly to code, think loud and be
confident.
A big thanks to geeksforgeeks and other online judges.
All Practice Problems for Amazon !

712
Chapter 289. Set 287 (On-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-287-on-campus/

713
Chapter 290

Set 288 (On-Campus)

Amazon Interview Experience | Set 288 (On-Campus) - GeeksforGeeks


Amazon visited our campus for SDE-1 . Interview process started with an online coding
round followed by 4 Face to Face Interviews. All Interview rounds started with brief intro-
duction about me.
Online Round :
A hackerank contest with 22 questions inclusive of 2 coding problems and 20 MCQ’s on OS,
DBMS, Networking and C/C++.
Coding Questions :
1. Given a 2d array with only elements ‘#’ & ‘.’ . ‘#’ represents cherry and ‘.’ represents
nothing . Can you divide the array into 2 halves with equal cherries . You can only make a
single cut either horizontally or vertically .
2. Sliding Window of size k . Find max of each window.(no need of optimization, Brute-
Force was accepted).
F2F 1 ( 1 hr 20 min, TECHNICAL ) :
1. Find floor of a number in a sorted array. Production code was required.
2. Given a number k , Find no. of ways to make this number using sum of numbers from 1
to k-1 . Constraints: You cannot take same number more than once in a combination( for eg:
k=6, {1,1,4} can not be considered in solution) and also all permutations of a combination
count as one way ( for eg: if k= 6, Then all permutations of (1,2,3) count as one way only).
(Solution : Recursion, DP)
F2F 2 ( 40 min, DIRECTOR + TECHNICAL ) :
1. Given an API :- bool isValidWord(string) and a list of sentences. For each word in a
sentence, you have to print all the substrings and reversed substrings in that word which
are valid (validity of a string is checked by above API).
2. Discussion on Egg Drop Puzzle.
3. What happens when you type www.amazon.com in your Browser .

714
Chapter 290. Set 288 (On-Campus)

F2F 3 ( 1hr , TECHNICAL ) :


1. Given a linked list, write a function to reverse every alternate k nodes. Need to handle
all the Corner cases .
2. Given millions of sorted lists and a God Processor that can work on infinite threads at
a time, make a sorted list using all the elements of given lists considering the advantage
provided by such a processor.
(My approach 1: use Priority Queue, but he said that only one thread can use the PQ at a
time.
My approach 2: use technique similar to Merge Sort) .
F2F 4 ( 1 hr 20 min, TECHNICAL ) :
1. Given a robot which is on Origin in a number line and a string that contains either ‘L’
, ‘R’ or ‘?’. ‘L’ means turn left and ‘R’ means turn right. ‘?’ can be assumed to be ‘L’ or
‘R’. Find the maximum distance from origin the robot can go at any point of time. ( My
approach 1: Backtracking, 2: Backtracking+Memoization, 3: using two variables )
2. Discussion on data structure used for dictionary, Hash table vs Trie, collision handling
in hash tables.
Print all the substrings of a given string that are present in the dictionary. Then he asked
to optimize the solution. Then I used technique similar to Rabin-Karp algo + Hashing
assuming collision is not a problem. Interviewer was satisfied after this solution. Code was
not required.
Interview tips : Interviewers don’t want most optimized solution. They see how you ap-
proach a question , Interact with interviewer if you get stuck ,don’t jump directly to code,
think loud and be confident.
A big thanks to GeeksforGeeks and other online judges.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-288-on-campus/

715
Chapter 291

Set 289 (On-Campus for


Internship)

Amazon Interview Experience | Set 289 (On-Campus for Internship) - GeeksforGeeks


Amazon was the first company to visit our university this year. They have taken 3 rounds
for selecting students for internship program.
1. Online coding round : This was as usual. 2 coding questions and 20 MCQs. MCQs
were from probability, permutation, output, tree, DBMS and OS.
Coding questions were easy. The first one was finding-next-greater-element-with-same-set-
of-digits. I’ve to implement the function long nextGreater(long n);
There were hidden test cases. That means, if you submit successfully, then also your code
might be wrong. You’ve to design and test your code.
Second question was easy, finf max(|Ai – i| – |Aj – j|) from an array with i!=j.
There were students who were not selected just because they answered only 3 or 4 MCQs.
Actually, the selection was not done based on the coding questions. Two of my friends
answered both the coding questions an didn’t answer any MCQ and were not seected.
2. 2nd round was a F2F round.
The interviewer was very frank, friendly and helpful as well.
At first he gave me the problem of finding triplets in an array that adds up to a given value.
I told him that I’ve solved it before and he told me to explain the algorithm. I did.
Then he gave me another problem. Given a BST and a range, return all the elements in
that range. I told him one recursive approach and I had to write the code on the paper. He
told me that there are two bugs in the code, find it. Later I figured out and modified the
code.
Then he gave me infix to postfix conversion and evaluation of postfix. I solved it but then
he told me it was wrong. Then I’ve to find out what was wrong with my code. I took an
example and debugged my code.

716
Chapter 291. Set 289 (On-Campus for Internship)

Then he gave me a chance to ask him questions if I had. I asked him, “How many hours
do you code in a day?” He replied, “Sometimes I don’t write code at all, sometimes it is
12-16 hours.” He also mentioned that his wife doesn’t like him. I told him, you should have
married a CS girl. He was laughing. I asked some other questions and it was really an
awesome conversation.
3. 3rd round was HR round. The interviewer started talking about the life and culture
at amazon.
Then he asked me the problem of finding whether two nodes in a Binary tree
are cousins or not. I was not able to solve it at first. I was nervous. I wrote the code but
again it was wrong, he told me you’ll get 2 more minutes for 5 times. But he gave more
than 10 minutes to solve it. Actually he was trying to confuse me.
2nd question was a math question, it was easy and then he told me to implement insert
method
of MaxHeap. I told him that I can’t. I can use MaxHeap but I’ve never implemented
MaxHeap. He said, “Then implement it now.” I did and said, “Have you ever implemented
MaxHeap insert method in O(1) time ?” He just stared at me and then I said, “I don’t like
remembering algorithms that I don’t even understand. And I never needed this algorithm
as well”.
Later I apologized for the arrogance that I showed. He asked me lot of questions like why
do you want to work at amazon ? Then he gave me a chance to ask him quetions. I asked
the same question,
“How long do you code ?” He said, “I don’t write codes at all.” I said, “Why ?” He said,
“Because I’m the HR manager” I said, “I thought that there will be one more round and
that’ll be the HR round.
And I heard that the HR manager likes to ask mathematical questions”. He laughed and
said, “I asked you one.”
And one advice that I can give you is that You don’t need to know thousands of algorithms.
Apply your brain to develop them because they’ll give you sufficient time to do that. Re-
membering algorithms is a bad habit. And be confident and proud of what you already
know. Thanks geeksforgeeks for giving me such an unexpected happiness.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-289-on-campus-for-internship/

717
Chapter 292

Set 290 (On-Campus for


Internship)

Amazon Interview Experience | Set 290 (On-Campus for Internship) - GeeksforGeeks


Recently, Amazon visited our campus and as a matter of fact it was the first to visit.
They took 3 rounds to select interns.
1st round – Online test
There were 20 MCQs, which included questions from C, C++, Java(Multi Threading) and
few aptitude questions.
Then, there were 2 coding questions-
1)http://quiz.geeksforgeeks.org/lexicographically-minimum-string-rotation/
2) Given a string, check whether string is Good or Bad(Condition – String is composed of
‘a’ and ‘b’ characters only and you can add only “ab” anywhere in the string to form a Good
string).

2nd Round – F2F interview


Interviewer gave me one question – Count possible paths from top left
https://www.geeksforgeeks.org/count-possible-paths-top-left-bottom-right-nxm-matrix/
He first asked me to give recursive approach and then optimize it further by creating an
extra matrix.
Finally, he asked me to give DP solution of the problem.
Interviewer was very helpful and discussed every step of my solution. He wanted to see how
I approach the given problem and further optimize it gradually.

3rd Round – F2F Interview


Interviewer started with my projects and slowly came to Operating system. He asked few
questions related to it-
1) What is a page fault?
2) How does it affect the CPU performance?

718
Chapter 292. Set 290 (On-Campus for Internship)

3) How to minimize it? (I talked about LRU)


He asked me to design LRU using appropriate Data Structures.
I did it using doubly linked list and map. Then, he talked about complexity of my solution
and wrapped up the interview by asking if I had any questions for him.

Few advises – First, be cool and don’t be nervous because interviewer wants you to be
interactive and confident. Think out loud and keep discussing with interviewer about any
of your queries. Lastly, just memorising algorithms won’t do any good. One has to learn
the art of developing logic of a problem.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-290-on-campus-for-internship/

719
Chapter 293

Set 291 (On-Campus for SDE1)

Amazon Interview Experience | Set 291 (On-Campus for SDE1) - GeeksforGeeks


Amazon visited our campus for SDE_1. The entire interview procedure was divided into a
coding round and a set of 4 face to face interview.
Online coding round:
It was a 90 minutes test with 22 questions(20 MCQs + 2 coding) set hosted on HackerRank.
Coding questions:
1. Reverse words in a string.
Example: Let the input string be “i like this program very much”. The function should
change the string to “much very program this like i”https://www.geeksforgeeks.org/
reverse-words-in-a-given-string/
2. Largest length of subarray with given sum.
https://www.geeksforgeeks.org/find-subarray-with-given-sum/
MCQs consisted of OS, Geometry, Basic Maths, C ,Recursion and such topics.
Whoever solved atleast two questions were chosen for the interviews.

F2F 1(Technical):
He asked me about my Summer Internship Project at Microsoft India Development Centre,
Hyderabad and asked me about several technologies involved in it and why I had used
certain things.
Then he moved on to two technical questions.
1. Given a sorted and pivoted array, find an element given to you.
I had given him a O(logn) solution with pivot finding and then doing binary search in
either halves. But it was a O(logn) + O(logn), so he asked me to modify it to a one
O(logn) question. After giving him the solution, he asked me to write production level code
considering all corner test cases.
2. Given a BST which consists of marks of students in a class. It is found that all even
ranked students have cheated,so we reduce k marks from their score. Modify the BST to

720
Chapter 293. Set 291 (On-Campus for SDE1)

make the change of marks without considering that after this operation, the BST might not
remain a BST anymore.
I gave him a modified inorder traversal so that elements are sorted and solved it using a
counter variable. He asked me to modify it to using neither a static counter variable nor
a pointer passed to the recursive calls. For both questions, he also asked me the time and
space complexity.
F2F 2(Technical):
He asked a very brief idea about my Summer Internship again. Then he asked me 2 questions
again.
1.Given a k sized window in an array,find max element in each window.
https://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/
I discussed a lot with him as to which data structure could be used and finally came up
with a Queue solution. I was asked to code it again considering all the corner cases.
2.Implement a queue using stacks with the operations (Enqueue,Dequeue,IsEmpty,Size).
While I was telling him the solution,he even asked me whether I would prefer Arrays or
Linked List implementation when i make a normal queue.
(Space and time complexity for both)

F2F 3(Technical):
He also asked me a brief introduction to my Summer Internship Project.
He began with the pros of cons or arrays and linked lists. Then a question on arrays:
1. Given an array with all even elements present even number of times except one which is
present odd number of times. Find that element.
I started with XOR solution, but he told me the OS doesn’t support XOR.So,I gave him a
HashMap solution. He went on asking me to optimize further. So at the end I had a space
complexity of O(k) where k= number of unique elements.
Asked me the Space and Time complexity of the most optimized solution.
2. Given four types of array

a)Increasing(1,2,3,4)
b)Decreasing(4,3,2,1)
c)Increasing-decreasing(1,2,3,4,7,6,5)
d)Decreasing-increasing(7,6,5,1,2,3,4)

Find the type of array in O(1) and then find the maximum element in the array.
Except case c, max element is O(1). For c, I gave binary search solution. he asked me to
write the code considering the corner cases.
F2F 4(Bar raiser):
He asked me what my favorite subject was. I told DS,so he asked me from DS.

721
Chapter 293. Set 291 (On-Campus for SDE1)

1. Write a class of circular queue using array implementation with Enqueue and Dequeue
member functions.
2. Given a binary matrix( filled with 0 and 1 only) where 0 depicts water and 1 depicts land.
We can traverse either up or down or left or right.Given a source and destination,find if we
can reach the destination.
He then modified it to finding the path followed and then the minimum path possible.
(Code wasn’t required)
3. Given a series of operations to build a project along with the time taken by each operation.
Some operations are dependent on previous operations. Find the minimum number of days
needed to finish the operation.
I wasn’t very sure of the solution I was thinking,so he said it was okay and concluded the
interview.
Tips:
1. Keep sharing your idea with the interviewer, he would help you a lot.
2. Don’t give up, you might come up with a brilliant idea with a little more thinking.
And do remember:
“If it doesn’t end well then it probably hasn’t ended yet”
I would like to thank all my friends for all the support and a special thanks to GeeksForGeeks
for their awesome website. Cheers! �
All Practice Problems for Amazon !
Subarray with given sum

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-291-on-campus-for-sde1/

722
Chapter 294

Set 292 (On-Campus for


Internship)

Amazon Interview Experience | Set 292 (On-Campus for Internship) - GeeksforGeeks


Amazon came to our campus for hiring interns.At first there was a coding round then 2
personal interviews
Coding round: There was 20 mcq questions based on DS , OS , IQ and output questions
And there were 2 coding questions

1. Given a string print the lexographically smallest possible rotation of the string.
(N square sol. Passed)
2. Balanced parenthesis
I did bith coding questions and attempted 17 mcq and got selected for next round
Out of 500 ,47 were shortlisted

2nd round:(Personal interview)


First he asked me about myself then he gave me a question

1. suppose there is a matrix filled with zeros and ones then find if there is a path between
(0,0) to (n-1,m-1 )
I explained my approach(trivial dfs) Then he asked me to write a code for printing all
possible pathsI implemented it using backtracking
2. Game of nim
3. Number of all possible bst for keys 1 to n
4. number of all possible labeled binary trees for given n nodes
5. https://www.geeksforgeeks.org/dynamic-programming-set-31-optimal-strategy-for-a-game/
6. https://www.geeksforgeeks.org/check-whether-a-given-string-is-an-interleaving-of-two-other-given-strings-set

24 students were shortlisted


3rd round:

723
Chapter 294. Set 292 (On-Campus for Internship)

• Design a data structure for a server which can store atmost 100 records, 2 functions
are used to access server get(k) ,put(k,v,x).
Where k is key and v is corresponding value and x is the expiry time before which this
record cant be removed
Implement a data structure to implement these function optimally. I implemented
using self balancing bst and an unordered hash map
• Then he asked me to construct an avl tree for keys from 1 to n.

Cheers i got selected!!


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-292-on-campus-for-internshp/

724
Chapter 295

Set 293 (On-Campus)

Amazon Interview Experience | Set 293 (On-Campus) - GeeksforGeeks


Round 1(Online Test) It consisted of two coding questions and 20 MCQs. Round
2(Technical Interview)

1. Write a function to find ‘a’ raised to the power ‘n’.Then he asked me to find the time
complexity of the function.
2. He was about to ask me the question of ‘finding the number of islands’- https://
www.geeksforgeeks.org/find-number-of-islands/ but I told him that I already know
the solution so he moved to the next question.
3. There are n boxes given that are 1-D. You have to find the best fit for the given item
that can fit into the box. For ex- An array of boxes is given as {7,9,12} and we need
to find the best match for the item of size 10 then the box with dimension 12 will be
our best match. I suggested him to use BST. We can arrange all the boxes in a BST
and find the successor for the given item in the BST. He then asked me to code it.
4. He then asked me about my project.

Round 3(Technical Interview)

1. He asked me a question of joining strings which is similar to the below question –


https://www.geeksforgeeks.org/connect-n-ropes-minimum-cost/ I suggested the same
approach and coded it.He was satisfied.
2. There is a audio player given which picks up a random song from the playlist and
plays it.The song should not be repeated until all songs are played atleast once.The
sequence number of the songs are given in an array.Design such audio player without
using any extra space. I suggested him to use a pointer say ‘pivot’ that initially points
to the last element of array. The songs to the left of the array are not yet played
and the songs to the right are already played and cannot be repeated. Each time a
song is picked form left of the pivot and played.That song is then replaced with the
pivot element and pivot is moved left by one position. If the pivot points to the first
element that means all songs have been played once and the pivot again moves to the
rightmost element.

725
Chapter 295. Set 293 (On-Campus)

Round 4(HR+Technical) He asked me some HR questions for about half an hour.After


that he shifted to the technical part.

1. What all data structures you know.Give the real life examples of when can we use
them.
2. Write a code for preorder traversal of a binary tree without recursion.

Round 5(Technical Interview)

1. A boolean matrix question – https://www.geeksforgeeks.org/a-boolean-matrix-question/ I


already knew the question so she just asked me to code it.
2. An array of strings is given in which some strings are anagrams of one another. You
have to find those strings and store indexes of those strings in a vector. I suggested
to sort all the strings and then use a hashmap<String,vector> to solve the above
question. She asked me to code it.

And yayy!! I got selected :p


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-293-on-campus/

726
Chapter 296

Set 294 (Experienced)

Amazon Interview Experience | Set 294 (Experienced) - GeeksforGeeks


Round 1

1. Pivoted array search, modified that array can have duplicate values need to return
first occurance of element.
2. Is pair of given values present in BST or not?

Round 2

1. In FB when we enter person name to search then their are multiple name FB gives us
as a suggestion. Design a DS for showing these name.(gives him trie DS solution)
2. Behavioral Questions
(a) Things u learn in 3 years of experience which makes u different from fresher guy?
(b) Project description

Round 3

1. LCA in binary tree. Both elements parent must not be equal to given elements.
2. Check if pair is present in array or not. modified to return all unique pair in it.
3. Integer stream is coming find largest K element.(K is fixed)
4. Design a DS where below operation is performed in O(1) time.
(a) Insert
(b) Delete
(c) Search
(d) GetRandom

Round 4

1. Lot of discussion on projects. HLD and LLD of project.

727
Chapter 296. Set 294 (Experienced)

2. There is file of million number you have to find out largest k element.
3. Give all pair present in array. Duplicate can be present in it.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-294-experienced/

728
Chapter 297

Set 295 (On Campus)

Amazon Interview Experience | Set 295 (On Campus) - GeeksforGeeks


Amazon visited our campus for FTE’s (Full Time Employees). Interview process started
with an online coding round followed by 4 face to face interviews. The level of difficulty
increased as we move to the further rounds. All interview rounds started with brief intro-
duction about me.
Online Round:
A hackerank contest with 22 questions inclusive of 2 coding problems and 20 MCQ’s on C,
OS, DBMS, Networking.
The 20 MCQ’s are mainly based on Algorithm analysis for example time complexity space
complexity for a particular snippet of code, basic C, java output based questions, OS Mu-
tex ,semaphores, IPC, synchronisation etc..
Here are some of the questions i remember

1. Which of the following sorting algorithms have worst case nlogn complex-
ity?
Ans:merge sort,heap sort.
2. Time to insert an node after a given node in a linked list?
Ans:O(1).
3. Number of child process created when fork() system call is called n times?
Ans:2^n-1(i guess).
4. Int arr[5]={1,2}, cout<<a[2]<<a[3]<<a[4];. . . what is the output of the
following snippet? Ans:0,0,0.
5. The average time taken for searching an element in an array using linear
search assuming that the searched element is always present in the array?
Ans: (n+1)/2.
6. You will be given array ,you have to find out which of them represents a
max/min heap?
7. You are two traversals of a binary tree„you have to find out the asked
traversal? For ex: Inorder=4, 8, 10, 12, 14, 20, 22. Level order=20, 8, 22, 4, 12, 10,
14 Find preoreder? Ans:20,8,4,12,10,14,22

729
Chapter 297. Set 295 (On Campus)

8. You are given a binary search tree and a key time taken for the Searching
given key? Ans:O(log(n)) worst case for balanced BST O(n) worst case for Normal
BST (this case occurs for left/right skewed trees).

Coding Questions :

1. You are given a array of positive integers which represents heights of buildings.Width
of each building is assumed to be 1. You have to find max rectangle area of buildings.
Ans: https://www.geeksforgeeks.org/largest-rectangle-under-histogram/
2. You are given a string let say “saideep” ,s-1,a-1,i-1,e-2,d-1,p-1 is the frequency of each
character.VALUE of the string is defined as sum of squares of count of each distinct
character.value of above string is 1+1+1+1+4=8; Your task is to minimize the
strings VALUE of the string after removal of ‘k’ characters.
Ans: Its a straight forward question where you take a 256 array to store frequency of
each character ,for k times you find a maximum frequency character and decrements
its frequency by 1. After k iterations print the VALUE function you get by remaining
characters.

F2F 1 ( 1 hr 30 min, TECHNICAL ) :


Interviewer is a lady, probably 3-4 years senior to me.She asked me two coding Questions:

1. You are given a binary tree ,you have to print extreme nodes of it.? Give me an
algorithm that is robust,works fine for all cases,explain the space complexity and time
complexity of you algorithm?
For Example:

1
/  \
2    3
/  \   \  
4    5   8
         /  \
      6    7

Output: ( 1 2 8 6 ) or (1 3 4 7)
Ans: It is just a modification of level order traversal,keep track of a Boolean flag
variable and flip it after each iteration. She then asked me write complete code neatly.
2. You will be given two linked lists that consists of digits 0-9 only in each node. Each
linked list represents a Number ,you have to add two numbers represented by a linked
list?
For Ex:

Input:
First List: 5->6->3 // represents number 365
Second List: 8->4->2 // represents number 248
Output
Resultant list: 3->1->6 // represents number 613

730
Chapter 297. Set 295 (On Campus)

I said i already know that question she skipped to the next question
Ans: https://www.geeksforgeeks.org/add-two-numbers-represented-by-linked-lists/
3. You will be given a linked list that contains loop inside it,if exists detect it and

remove it?For Example: Ans:


First i gave a hashing kinda solution that works for sure for all the cases. The idea is
that whenever I see a node i make a lookup in the hashtable to see whether it exists in
the table already r not, if exists then there is a loop and i make that node ==NULL.
Else Iwill insert that node in hash table and move to the next node.
She was ok with that solution but it required O(n) space of hash table, so she asked
me to do in O(n) time and O(1) space.
Then i got that 2 pointer method (floyds cycle detection algo ),so i gave that
method,by this method we can detect a loop easily,but removing it requires some
mathematics(related to kinematics in 1-D).
She then asked me write complete code neatly.

F2F 2 ( 1hr 30 min TECHNICAL ) :


He gave me two coding questions

1. You are given a string with distinct characters and you have to print all the permuta-
tions of it?
For ex: Input:”AB”
Output: AB,BA
Its a straight forward question and i gave him an back tracking approach and he
asked me to explain how that backtracking works using an example.i explained him
by taking various examples that involves corner cases and made sure that it works
for all the cases. He then asked me write complete code neatly.
Ans: https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
2. You are given a maze which describes the way for a goat to reach its house.Maze is
usually a M*N grid consisting of only 0’s and 1’s .Goat initially is at (0,0) point in the
maze and it has to reach point(M-1,N-1).The only possible move the goat can make is
go RIGHT,DOWN,RIGHT-DOWN(DIAGONAL) i.e from a point (i,j) goat can move
to(i+1,j) or(i,j+1) or (i+1,j+1) point.Goat can make only one step at a time. Your
task is to find number of such paths for the goat to reach its house.
Point (0,0) and point(M-1,N-1) are abviously 1. A 1 indicates that the point can be
used and 0 indicates that the point is blocked in the sense we cannot go to the point
at any cost.
Ans: I gave him a recursive solution initially and explained him about the drawbacks
of that solution, that it takes exponential time to solve that problem.

731
Chapter 297. Set 295 (On Campus)

I then explained how i can use Dynamic programming to solve this problem and gave
him a DP solution.He was very much impressed with my solution and asked me the
time and space complexities of that solution.He then asked me write complete code
neatly.

F2F 3 ( 1hr TECHNICAL ) :


The interviewer went through my resume and my previous interview rounds performance
and said introduce yourself. I introduced myself: He asked me if I had done any internships. I
said no sir,i got chance in some of the companies but i didn’t take it. He then asked me
what did you learn in this summer ,I said I prepared for the placements and I’ve done 1-2
mini projects.
He then asked me why didn’t you take that interns. I told him i don’t like those companies
hiring process itself how can i work in the company.I said that they all asked memorizing
concepts which i am very weak in and didn’t even ask me single logical question.he even
didn’t ask me single coding question.
He said lets start our process you are here because of your coding skills, but in this round
I am gonna ask you theoretical questions.
He asked me

1. Difference between trigger and stored procedure?


2. Difference between thread and process?
3. Define deadlock and race condition?
4. How deadlock is detected?
5. What is resource allocation graph and how its related to deadlock,what are the nodes
in that graph?
6. He asked me what all the data structures i know and give their real time examples?
7. Indexing in DBMS
8. Types of indexes
9. How indexing is done in DB(b-tree and b+trees)
10. Views ,types of views its advantages

He then gave me a coding question: You have to replace every element of an array with its
immediate smaller element to the right. If such an element doesn’t exist don’t replace it.
Ans: I gave him a stack solution which he was very much satisfied and asked me to code
taking care of corner cases. He then asked me write complete code neatly. He is satisfied
with my code and asked me to wait outside for further round.
F2F 4 ( HR+TECHNICAL ) :
He started by asking me to introduce myself and gave a coding question.It’s the tough
question
You will be given a floor say(m*n) dimensions and sub rectangles that can fit inside the big
rectangle..you have to print the floor plan for given dimensions of small sub rectangles.
He explained me that it requires construction of SLICING TREE and then printing floor
plan. He asked which all the data structures you will use to construct it and asked me think
of it.

732
Chapter 297. Set 295 (On Campus)

Ans: I gave him an stack/queue based approach .I told him that i’ll sort the sub rectangles
by lengths/breadths and push them in stack in d=increasing order. .he was very much
satisfied with my algorithm and asked me to code it.I coded it completely and showed him
. .I just solved the problem and i didn’t print the floor plan which is our actual problem. .i
then implemented the print function inside it.
He said that he’s done with the interview and asked me if any queries.
I asked him about the kinda of project he’s currently working and some casual discussion
on technologies.
PS:- Everyone knows the algorithm but it’s implementation with robust,clean code is re-
quired which covers all test cases.they will certainly give corner cases that our code fails
to execute so make sure you write a universal code.Make sure you ask any doubts if any
to clarify the given question/scenario.The interviewers are a lot helpful and they give you
hints if you are struck.
Thanks GeeksforGeeks . .It helped me a lot in my preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-295-on-campus/

733
Chapter 298

Set 296 (On Campus for


Internship)

Amazon Interview Experience | Set 296 (On Campus for Internship) - GeeksforGeeks

Online round (1 hour 30 min)


20 MCQs + 2 coding questions-
1) Given an expression string exp, write a program to examine whether the pairs and the
orders of “(” and “)” are correct in syntax
2) Given preorder and inorder traversal of a binary tree, print preoder and inorder of the
tree after modifying it such that each node stores the sum of its left and right subtree.
(building the tree was not required)
Technical round 1 ( 1hr 30 min) F2F
1) Given a string of characters find the first non repeating character.
did it with hashing.
He asked me to do it using one loop. I did it by taking two pointers.
2) Given a list of vehicles group vehicles by their property.
All vehicles with same production year and other parameters are to be grouped together.
He asked me to write object oriented code.
I did it with list of lists.
Then He asked me to modify the code considering the production year and other parameters
as objects and not just integer or string variables.
He was looking for some better method for comparison of two vehicles . I did it operator
overloading inside the vehicle class.
Technical round 2 (1 hour 30 min) F2F
1. Given two numbers return the sum of the two numbers considering all the cases(like
integer overflow, underflow etc).
2. Given array of elements denoting price of some objects, print the maximum sum that
can be obtained following some constraints-
i)only one of the two ends from the array can be selected at a time

734
Chapter 298. Set 296 (On Campus for Internship)

ii)the seller can sell only one item per day


iii)the value of each of the elements gets multiplies by the number of days passed.
I did it with dynamic programming.
3. Print next greater palindrome of a given array with each element denoting a single digit
of an integer.
4. Connect nodes at same level with O(1) extra space.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-296-on-campus/

735
Chapter 299

Set 297 (On-Campus for SDE)

Amazon Interview Experience | Set 297 (On-Campus for SDE) - GeeksforGeeks


Amazon visited our campus on 12th August. There were 5 rounds namely –
1) Written round
2) – 5) All technical rounds with increasing difficulty levels
The written round consisted of 20 mcqs ( OS, DBMS, CPP , C , JAVA and Aptitude basic
level ) and two Hacker Rank coding questions –
1) Overlapping subsets problem and
2) The longest path in a given binary tree
The technical rounds took 1 hour each.
In the first technical round I was asked to check whether a given tree is a complete binary
tree or not and then to code both recursive and non-recursive version of it. It also included
another question like to find whether a number is a power of 2 or not.
The 2nd technical round had questions like what is a symmetric number, how will you check
if its a symmetric number. And then he asked me to find all the symmetric numbers of
given n-digits. I wasn’t able to do the last part.
The 3rd technical round consisted of a string compression problem. Given a string like
AAABBBCDEFGHIJKLLLLLLLLLLLLLLL – you have to compress it to a string like
A3B3C1D1E1F1G1H1K1L15. The question was to be done in O(n) and inplace.
The 4th technical round consisted of the popular dynamic programming problem of cutting
sticks of various length and merging them to form a bigger stick keeping in mind that you
have to decrease the overall cost of merging.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-297-on-campus-for-sde/

736
Chapter 300

Set 298 (On-Campus for SDE-1)

Amazon Interview Experience | Set 298 (On-Campus for SDE-1) - GeeksforGeeks


Recently Amazon came to our campus for placement (SDE-1).
I want to share my experience.
Round-1
20 MCQs many from GeeksQuiz and 2 coding questions.
1. Find a range in array of bits(0 and 1) such that by flipping it, the count of 1’s in complete
array becomes maximum.
2. https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations/
Interview-1
Brief introduction.
Two coding ques. were asked:
1. Clone a link list with random pointers.
2. In an array of +ve integers, all numbers are occurring even no. of times expect one. find
it.
Interview-2
Two coding ques. were asked:
1. find the largest palindromic substring.
2. Merge 2 binary trees to make a binary tree.(Solved using conversion of binary tree to
Doubly linklist and then merge two DLLs and the convert DLL to Binary tree.)
Interview-3
Brief introduction.
Discussion on projects. They focused on team projects.
Then gave a situation: n no. of vendors and m no. of warehouses(n , m very large). We
have to shift the products from vendors to warehouse and then from warehouse to customers.
Aim is to fasten the product delivery and reduce the cost to company.
In this we had to make assumptions and make cases.
Interview-4
Brief introduction(Only technical one).

737
Chapter 300. Set 298 (On-Campus for SDE-1)

Two coding ques. were asked:


1. 2 sorted arrays of size m and n (m > n) are given. There are n empty spaces at the end
of the array1. Make the array1 consisting/merging the elements from both the arrays and
store it in array1.
2. Connect siblings at same level in binary tree.
What do you mean by time complexity(in depth)?
Concepts of OS like virtual memory, paging, page fault were asked.
Other ques. asked to other people:
1. BST two nodes swapped. correct them.
2. Square root of no. (correct to 2 decimal places).
3. Diameter of the binary tree.
4. Add 1 to a number represented by link list.
5. largest substring having unique elements.
6. Diff. b/w process and thread (in detail).
7. Coin change problem.
I want to thank geeksforgeeks.org for its content.
I got selected because of it.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-298-on-campus-for-sde-1/

738
Chapter 301

Set 299 (On-Campus for


Internship)

Amazon Interview Experience | Set 299 (On-Campus for Internship) - GeeksforGeeks


AMAZON came to our college for both FTE’s and two month summer interns.

The First Round was an Online Coding Round along with MCQ’s.Remember to
attempt some MCQ’s correctly in order to improve your chances in getting through this
round as the Coding questions may not be very difficult.
Q1. Find the next greatest number using digits for a given number. STL usage is allowed!
Q2. In a given array A find the maximum value of |Ai – i| – |Aj – j| where i not equal to j.
This is pretty simple!
MCQ’s were standard and were from permutation and combination and probability
mostly.Also outputs for code snippet.
There is a 5:1 selection ratio here.

The Second Round : Face 2 Face Interview 1


Asked for the favorite data structure and questions on them. I answered trees and linked
list.
So, the questions were from the basics of trees.
Q1. Check if a given binary tree is a Binary Search Tree.
Then questions stemmed out from the in-order successor part and the in-order successor
had to be coded with and without using the parent pointer.
Q2. Implement Stack using Arrays Linked Lists and Queues. And comment on their advan-
tages and disadvantages.
Q3. Implement Queues using Stacks and comment on the complexity.
Questions were simple enough but code was required.
20 people out of 31 were selected.

739
Chapter 301. Set 299 (On-Campus for Internship)

The Third Round : F2F Interview 2


A different interviewer in the same setting.
Found the questions to be of higher standard compared to the previous round and more
time consuming.
Q1. Maintain the First Non-Repeating character in a stream of incoming and out going
characters or digits simply in O(1).
Gave some solutions for O(n) at a particular instant of time.
But used a Hash and Queue but that did not allow maintaining the first non-repeating
character as the elements could not be accessed randomly.
There were a lot of hints and finally i understood that the interviewer was hinting at a deque
where the hash value is the node pointer in deque.
I just had to sum up the small things and give a final solution with all the bits and pieces
arranged.
Not Very Satisfactory.
Q2. Cloning of a Binary tree with random pointer:
Did the cloning of the normal binary tree but could not do it for the random pointers
because I need the links and paths.
Gave a O(nlogn) solution storing all the paths from the node to its random pointer node.
Finally, I came up with a Hash Map Solution which seemed fine.
The interviewer told me to practice more qustions and increase the depth of knowledge in
Data Structures.
This was all for the interview!
Though the questions were not common for me, these are standard questions and can be
found in gfg.
But somehow I kept thinking and collected the hints for the answer and summed it up.
I thank the huge amount of online resource that is available for learning and practice,
especially geeeksforgeeks.org.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-299-on-campus-for-internship/

740
Chapter 302

Set 299

Amazon Interview Experience | Set 299 - GeeksforGeeks


Online round (1 hour 30 min)
20 MCQs + 2 coding questions-
1) You have given two stings.You have to write function to check weather any anagram of
second string is substring of first string or not.
2) You have given one mathematical expression containing +,-,*,/ in form of string which
is space separated (” “). You have to write a function to solve this expression and return
value of expression.
MCQ questions mostly based on data structures(trees, linklist ,arrays),2 questions from
database and some questions from basic concepts (like give output of given program). 2 or
3 questions on aptitude.
Technical round 1 ( almost 50 mins ) F2F
1) Given two very large integers and calculate the sum of given integers without using BigInt
library in java.
I did it by taking input number in form of string and traverse both string from right to left
and added integer one by one from right to left.
2) Given two arrays and one product.You have to write function to print all pairs(p,q) such
that p*q=product and p belong to first array and q belongs to another.
He ask me to do it in linear time.I did it using hashing.
Then He asked me some questions about my projects.
Technical round 2 (almost 60 to 70 mins) F2F
1) Given an array and one sum.You have to write method for checking weather any pair
exist in array that sums equal to given sum or not.
He ask me to solve in linear time.I did it with hashing.
2) He gave me an stack and ask me to find minimum element in stack at any point of time
in O(1) time.
I did it using another stack containing current minimum at top of stack. Then he asks me
to reduce memory of program.
3) What are the advantages of quick sort over merge sort and advantages of array over link

741
Chapter 302. Set 299

list.
4) He ask me to explain binary search and proof of its complexity(O(log n)).
According to me the key for selecting is don’t stop interacting with recruiter at any cost
and be loyal with him/her.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-299/

742
Chapter 303

Set 300 (On-Campus for


Internship)

Amazon Interview Experience | Set 300 (On-Campus for Internship) - GeeksforGeeks


1. Written Round
20 MCQ from simple data structures, Networking, DBMS and some maths.
2 coding questions.
A) Interval merging problem. ( https://www.geeksforgeeks.org/merging-intervals/ )
B) Finding the diameter and printing the path of a binary tree from one end to other. If
there are more than one
diameter then print the one which is lexicographical small.
2. Technical Interview 1
A) Discussed the second problem of the written round.
Asked me to code it.
B) Implement a circular queue using 1-D array.
Handle all the case like condition for full, empty. Write push, pop, isEmpty function.
C) Given three arrays. Find all the pair from the two array such that the sum of those
element is in the third array.
3. Technical Interview 2
A) Given the preorder and the inorder traversal of a binary tree. Construct the tree.
B) Now he said if the tree is binary search tree how you’ll solve. Asked me to optimize as
much as possible
4. Technical Interview 3
A) Asked me about my projects. Asked me about problem in that. Asked me to solve those
problems.
B) There is a file in secondary storage consisting name, address, phone and many other
details. Now sort that file on the basis of phone no. Constraints: I have very low memory.

743
Chapter 303. Set 300 (On-Campus for Internship)

I can’t bring all the content of file to main memory. Using indexing I have to solve that
problem. I gave k-way merging approach. Now asked me to do in a different way. He gave
me hint for bst. Told me to write the code.
5. Technical Interview 4
A) You have an infinite number coming to you. Device an algorithm to get the minimum
at that time. Solved using two stack. Asked me write proper code, handle all corner cases.
B) Given the marks of a class in BST.
Subtract 5 marks from even ranked student. Asked me to code.
C) Questions from OS, threading.
And many more questions, some I don’t remember.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-300-on-campus-for-internship/

744
Chapter 304

Set 301(On-Campus for


Internship+ FTE)

Amazon Interview Experience | Set 301(On-Campus for Internship+ FTE) - GeeksforGeeks


Round 0: (Written): 20 MCQs + 2 Coding Questions:
MCQs – Topics:

• OS – Page fault, Waiting time (RR Scheduling), Paging, Semaphores, etc.


• DS – Hashing (simple chaining based numerical)
• Aptitude – 1 Probability question, Puzzle – 1 question, C– 2 questions, etc.

Coding Questions:

1. Given a list of n strings group all anagrams together


Example:
i/p: cat act pat mad dog god
o/p:
cat act
pat
mad
dog god
2. Given a binary square matrix of size n, find the size of largest region i.e. find a region
of connected ones (horizontally, diagonally, vertically).Example:
i/p:
0100
1110
0010
1000
o/p: 5

745
Chapter 304. Set 301(On-Campus for Internship+ FTE)

DAY 2: (Interview Rounds)


Round 1 (Technical Interview – 1 hr. approx.)
The Interview started with the interviewer telling me that we don’t have much time so he
will ask few questions on data structures and algorithms and I will need to tell him the
approach.

1. Reverse a linked list.


• I gave two approaches, one using stack and one using pointers (in-place).
2. Print top view of a binary tree.
• Well simple question but don’t know why I started using DFS approach (Pre-
Order Traversal)
• Tried using pre-order but he gave me test cases where it failed.
• Tried different approaches within pre-order found issues with one or the other
test cases and I was also using HashMap to keep track of nodes to print.
• So he asked me to do it without auxiliary storage.
• I tried level order approach (w/o auxiliary HashMap)and it worked fine for all
test cases.
• He was satisfied with the approach, so asked me to write production level code.

Round 2 (Technical Interview – 45mins. approx.)


The interviewer introduced himself briefly and asked me to introduce myself. No follow up
questions from the introduction (although I was hoping something on projects or company
:P).

1. Find Kth Max occurring element in the Array.


• Used HashMap and Heap to solve the question.
• Time O(n*logn)
2. DP question: https://www.geeksforgeeks.org/how-to-print-maximum-number-of-a-using-given-four-keys/

Round 3 (Technical Interview – 45 mins. approx.)


The interviewer introduced himself briefly and asked me to introduce myself. No follow up
questions from the introduction again.
He gave me a string based question and asked me if I knew it already (which I didn’t), so
he asked me to come up with an approach.

• Given a string find a repeating substring of maximum length.


Example:
i/p 1: banana
o/p 1: ana
i/p 2: indiaindianttindiaindia
o/p 2:india india
I thought of using KMP but complexity was high with this approach. I tried using
Longest Common Substring to see if there is any pattern or way to solve it using LCS,
I found an approach told it to the interviewer he was very happy with the approach.

746
Chapter 304. Set 301(On-Campus for Internship+ FTE)

Round 4 (Technical Interview – 25mins. approx.)


Short round as it was my last round.
Only one question:

• Given an infinite integer number line, find minimum steps required to reach a particular
point. 0 is the starting point and at ith step we can move +i or -i steps from current
position.
Tried using tree and realised it is DP problem told him the approach and complexity
and why DP and why BFS (to get minimum steps).He was satisfied with the approach.

ALL THE BEST :):)


Thanks GeeksforGeeks for all the material, it helped me a lot during preparations. Keep
it up !!

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-301on-campus-for-internship-fte/

747
Chapter 305

Set 302 (On-Campus)

Amazon Interview Experience | Set 302 (On-Campus) - GeeksforGeeks


0th Round: (Online): 20 MCQs + 2 Coding Questions:
MCQs Topics: OS Page fault, Waiting time (RR Scheduling), Paging, Semaphores, etc.
DS : Hashing (simple chaining based numerical)
Aptitude : 1 Probability question, Puzzle: 1 question, C: 2 questions, etc.
There were 4 rounds of interviews(all technical). Each round was for 45-50 minutes.

1st Round:
In this round the interviewer asked me the below two questions.
1.a) Given a number find the next greater number with the same set of digits.( https:
//www.geeksforgeeks.org/find-next-greater-number-set-digits/ )
I had to write the complete code covering all the edge cases.
Since I had practiced this question, it didn’t take much time to code for it.
1.b) Given a Binary Tree, convert this to a tree where each node contains the sum
of the left and right sub trees in the original tree.( https://www.geeksforgeeks.org/
convert-a-given-tree-to-sum-tree/)
For this question, first I discussed the approach, confirmed the edge cases and then wrote
the code using recursion.

2nd Round:
This round started with questions from Operating Systems.
The interviewer asked me questions on Process and Threads, Process Scheduling, Mutex
and Semaphores and Memory Management.
Some of the questions that were asked:
a) Difference between process and thread.
b) Advantages and disadvantages of using threads.
c) Difference b/w Scheduler and Dispatcher.
d) Name all the process scheduling algos and explain the Round Robin Process Scheduling.
e) At max how many threads can be active at a time in a machine?

748
Chapter 305. Set 302 (On-Campus)

f) What is race condition and how do we avoid it?


g) Difference between Semaphores and Mutex?
h) What is secondary memory and why do we use it?
i) What is thrashing?
Then he asked me questions on Computer Networks.
a) Explain OSI reference model and write all the layers present in this model along with the
protocols used at each layer.
b) Difference between TCP and UDP.
Finally he gave me a problem and told me to first discuss the approach with him and then
code the same covering all the edge cases.
The problem was as follows:
You are given an infinite stream of numbers, at any instant of time you have to print the
earliest non-repeating number.
eg: 2 3 4 2 5 6 output 3
2 3 4 2 3 7 8 output 4
I discussed my approach with him, he told me to further increase the efficiency and gave
me hints.
With his hints, I came up with the final solution (using Doubly Linked List and HashMap)
and wrote the code.
He evaluated it and spotted 3 errors.

3rd Round:
In this round the interviewer asked me questions on the Internship project.
He told me to briefly explain the complete project and asked various questions on the same.
Then he gave me a coding question and asked me to first explain the approach and then
code.
The question was,
You ar given an infinite stream of numbers and an integer k, at any instant of time you have
to print the top k elements scanned till that point.
I explained the naive approach of using an array of size k and then inserting the elements
at proper position thus making sure
that the array always remained sorted. Complexity O(k)
He was not satisfied with this solution and told me to further improve it ie aim for O(log(k)).
I did some brainstorm for a while and then gave the final solution to him using a min heap
of size k.
He also asked me to write down complete code for min heap.
The next question was on Caches.
He asked me to tell different page replacement policies.
Then he asked me, “How would you implement LRU Cache”?
I told him that it can be implemented using Priority Queue.
Then he cross-questioned me on Priority Queues, its internal implementation and complex-
ities.
He didn’t ask to code for it.

4th Round:

749
Chapter 305. Set 302 (On-Campus)

The interviewer gave me 45 minutes to solve the below coding problem.


You are given an infinite stream of numbers, at any instant of time you have to print the
median of the elements scanned till that time.
Median of an array here refers to the middle element of the array after sorting.
First I told him that I would maintain a sorted array, thus order of insertion would be O(N)
and order of query would be O(1).
He told me to further optimize it.
I thought of using heaps and somehow try to achieve O(log(N)) for both insertion and query,
but then he told me that it can be further optimized.
He told me to aim for O(log(N)) and O(1) for insertion and query respectively.
Suddenly I got the idea that I could make use of a minheap and a maxheap to solve the
problem.
I discussed my approach with him. He was impressed.
Finally I coded the problem.
At last he asked me, “Given an inorder traversal of a BST, can u build the tree”?
I told him yes. Then he asked me, “How many such trees are possible”?
I knew answer to this question, as it was taught in the class.
I told him about Catalan Number.
Verdict: 3 selected out of 33 interviewed.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-302-on-campus/

750
Chapter 306

Set 303 (On-Campus)

Amazon Interview Experience | Set 303 (On-Campus) - GeeksforGeeks


Round 0: (Written): 20 MCQs + 2 Coding Questions
MCQs – Topics: OS ,DS ,DBMS – (Serialization etc.), Aptitude (simple puzzle kind.)
Coding Questions:

• Given a string output reverse string (string could have multiple spaces between the
words).
Example:
i/p: I am a proud Indian.
o/p:
Indian proud a am I.
• Given a no in string format output another string which is the biggest no formed from
using same digits , otherwise print -1:

i/p:
0000
132
4312
11
o/p:
0
321
432
-1

So the solution is : http://stackoverflow.com/questions/12493591/given-an-array-of-


integers-find-the-largest-number-using-the-digits-of-the-array

DAY 2: (Interview Rounds)

751
Chapter 306. Set 303 (On-Campus)

Round 1 (Technical Interview – 45 min approx.)


The Interview started with his introduction , what his department is , what do they do and
so on.

• Given a link list of 0’s and 1’s sort it so that all the 0’s are at beginning and 1’s at
the end. It had to be in-place.
You cannot swap values only pointers.Order of 0’s and 1’s was to be maintained . I had
to write production level code for this with all boundary conditions checked!
• Given an array of 0’s and 1’s again and a variable k , print the size of the smallest
window which contains exact k 0’s .
– discussion about the best optimised approach .
– I solved it by storing indexes of all 0’s and calculating min diff b/w every k
elements.

Round 2 (Technical Interview – 1 hr approx.)


The interviewer asked me to introduce myself and then my projects.

• A person has to cross a road and with each step he either gains some energy or loses
some (this info is provided as an array) . Find out the min amount of energy he should
start with so that at any level his energy is not less than 1 ).
Simple question done in O(n).
• How to solve (a*b)%m , where all a,b,m are of the order 10^15. Modulo’s distributive
property is one thing .
1st approach suggested was breaking the no’s to binary as solving for eg:- [ ( 2^5 +
2^3 + 2^0) * (2^5) ] % [(2^3 + 2^2 + 2^0)] is feasible, but he wanted faster approach.
I suggested O(lg b) approach using divide n conquer (recursive solution) .
• He asked me if I know about the data structure Tier , I had heard about it and its
use but never implemented it. He explained a briefly what it is , then told me to code
its structure , its functioning (finding / adding a new word) .
Then asked a few questions on it , some cases where it will falter , some more discussion
on it.

Thanks Geeks ! Result – Selected �


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-303-on-campus/

752
Chapter 307

Set 304 (On-Campus for


Internship)

Amazon Interview Experience | Set 304 (On-Campus for Internship) - GeeksforGeeks


Eligibility Criteria: CGPA >= 5.0
Round 1: Technical Test
An online test held on HackerRank which consists of 20 MCQ’s and 2 coding questions.

• Coding Question 1: Find a tour that visits all the stations


• Coding Question 2: An array consists of 0’s and 1’s. A flip operation is one in which
you turn 1 ? 0 and a 0 ? 1.You have to do a “Flip” operation at most once on a sub
array. Then finally display the maximum number of 1 you can have in the array after
one flip operation.
In both the questions brute force solutions were accepted, i.e O(n^2).

MCQ’s
They were pretty simple you just need to have basic knowledge about Scheduling Algorithms,
Threads and Time Complexity. In this section major portion was from the Operating Sys-
tems.
I would suggest you go through last minute notes on OS, they were life savior for me in
Online round as well as in further round.
We were told that there will be only 2 Technical Rounds and No HR round.
Face to Face Round 1: (~1 hour)

• Questions 1: Fold a LinkedList :


1 ->2->3->4->5->6 is converted to 1->6->2->5->3->4
My approach :
– Step 1: Find the middle of the link list.

753
Chapter 307. Set 304 (On-Campus for Internship)

– Step 2: Reverse the second half of the link list and keep the head as head2 for
the second half of the linklist.
First Half
1->2->3
Second Half after reversal
6->5->4
Now traverse both the halves simultaneously and then take a node from first list
and then from second list, do this until you reach the end of first and second list
and make new links and maintaining the links to the next Node. Asked me to
cover all corner cases.
Finally asked me to give a proper working code on paper.
• Question 2:
If one of the nodes in BST in not is correct position place that in correct position in
the bst. First by some observation I figured out that the there will 2 nodes which will
be in wrong order.
So this question became similar to Two nodes of a bst are swapped ,correct the bst. I
gave an in order traversal approach but missed some corner cases, after giving a few
he told me I am missing some more test cases, then he moved to next question.
• Question 3:
A music player has N songs , you have a random number generator rand(n) which
generates a number from [0,n-1] .Your task is to play a random song from given N
songs such that each song is played once and your program should terminate once you
have played all the songs.
– Approach 1:
We will use a HashMap to store the index of the song played and then whenever a
random song is played check its occurrence in the HashMap if is is already there
generate a random number again and do this till the size of the HashMap is N.
He told me that is a buggy code, and asked me to find out the bug.
The problem with the code is that it might end in an infinite loop in the worst
case, assume that the first time rand(n) generates a number k (k<n) and we put
that in the hashmap , now assume every time the rand(n) generates k so we will
end into an infinite loop and our program might never terminate.After a lot of
thinking, I couldn’t come up with a good approach.
Hint given by interviewer: What if you can swap some of the songs?
– Approach 2:
Step 1: Take a variable last initialize it to N.
Step 2: Generate a random number using rand(last),let it be k.
Step 3: Swap(a[last-1],a[k])
Step 4: last–;
Step 5: Goto Step 2 till all the songs are played(last!=0)By the last variable I
simply keep track of all the songs that are played(after last).
He was satisfied with the approach.

Round 1 was over.


Face to Face Round 2 (~1.5 hour)

• Question 1:

754
Chapter 307. Set 304 (On-Campus for Internship)

He started with graphs asked to find the followers of a person told him to do a bfs
and some basic questions related to bfs.
• Question 2: Clone a LinkList with random pointers.
Gave him a solution using Hash Map, he was not satisfied asked me to do in O(1)
extra space.
I thought for 20 minutes but couldn’t come with the O(1) approach.
Hint given by interviewer: What if you change some links in the original list?
Again thought for about 10 minutes still couldn’t come with an O(1) approach.

Then he asked me to code the HashMap approach, while coding I figured out the approach
with O(1) extra space. Once I was done with the code I told him the other approach, he
was satisfied, code wasn’t required for the second approach.

• Question 3: If you have 2 very big numbers how will you add them? Told him
BigInteger is there in Java use that.
I : No without using that.
Take two strings and simply convert every character to digit and then add them up.
I: No you don’t have to convert a character to a digit.
Take 2 arrays.
I: Tell the constraints with the array.
Then I finally told him to use a LinkList.
And then finally told me the approach to add them without reversing the list.(Did by
recursion)
• Then there were many small questions related to quick sort, heaps, hashing, time
complexity for various algorithms.
What are different phases in Compiler?
I never expected that!
I thought for about 2 minutes and tried to collect as much as possible whatever I have
read in Compiler design. Then I gave him 4 phases of Compiler: Lexical Analyzer,
Syntax Analyzer, Semantic Analyzer, Intermediate Code generation and then told
him that I don’t remember anything more that this since I haven’t prepared CD and
studied a long time ago.
• Then he asked me questions from OS.
What is Threading?
Why thread better then process?
What is thrashing?
What is LRU?
And some more basic questions on OS.

That was all for the interview.


Result: Selected �
Best of Luck to all of geeks for their placement season!!
All Practice Problems for Amazon !

755
Chapter 307. Set 304 (On-Campus for Internship)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-304-on-campus-for-internship/

756
Chapter 308

Set 305 (On-Campus for


Internship)

Amazon Interview Experience | Set 305 (On-Campus for Internship) - GeeksforGeeks


Eligibility Criteria: CGPA >=7.5 (with no history of arrears)
Round 1: Technical Test (1 hour 30 min)
An online test held on HackerRank which consists of 20 MCQ’s and 2 coding questions.

• Coding Question 1: Find next greater number with same set of digits
• Coding Question 2: Merge two sorted arrays with O(1) extra space

MCQ’s
They were pretty simple and straight forward. 5 questions were from general aptitude like
probability, permutation and combinatorics. Rest of the questions were from Data Structure,
Algorithm and C and C++ output questions. Reading GeekQuiz helped me a lot.
Around 300 students took the test out of which 21 were shortlisted. I was also one of them.
We were interviewed the following day.
Face-to-Face Interview 1(~1 hour)
The interviewer asked me to introduce myself. After I gave my introduction, he went straight
to the questions.
Question 1: A program to check if a binary tree is BST or not
Given a binary tree, we need to check if it’s a binary search tree. He wrote the following
function
bool isBST(Node *root)
I asked him if I could modify the function template to include min and max values. He said
that I can modify the function template. So I gave my approach as described here. After

757
Chapter 308. Set 305 (On-Campus for Internship)

reviewing the solution, he asked me to explain it with an example. I drew a small tree and
explained it to him. He was satisfied and we moved on to the next question.
Question 2: Maximum sum such that no two elements are adjacent
Given an array of positive and negative numbers find the maximum sum in the array such
that no two elements are adjacent. The question can be found here.
As soon as he gave the question I said it is a Dynamic Programming problem. He asked
me to write code. I wrote the code by using a dp array of size n (size of array) and I gave
a top-down approach. He thoroughly checked if my code could handle all the corner test
cases. He asked me to run the code for array of size 1 and 2. I explained it to him. He was
satisfied and we moved on to the next question.
Question 3: Find a given word in a matrix of characters.
Given a NxM matrix and string s, check if the string is part of the matrix. We can move to
top, left right and bottom from a given cell. The question is similar to this.
Initially after giving the question I said we should use Depth First Search. But he gave me
a case where it won’t work and asked me to modify the approach. I said BFS and he asked
me to write code. I wrote the code by handling all edge conditions. But I missed the visited
array part. He read my code and gave me a case where it would run into an infinite loop.
Now, I found out what was missing and said I have to include the visited array. He was
satisfied and asked me to add that part to the code.
After this, the interview was over. He asked me if I had any questions for him. I asked him
a few questions and we were done.
Out of 21 students, 12 students were selected for the second interview. Fortunately, I was
also selected.
Face-to-Face Interview 2(~1 hour)
The interviewer read my resume and asked me to introduce myself. After I gave my
introduction, he went to the question.
Question 1: Count Possible Decoding of a given Digit Sequence
Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the number of
possible decoding of the given digit sequence. The question can be found here.
I gave my approach using Dynamic Programming. He asked me to reduce the space com-
plexity. I gave an approach like finding nth Fibonacci number. He was satisfied. Then, he
asked me to generate all the possible decoding instead of counting them. I gave my approach
using backtracking and he was satisfied.
Question 2: Identify the classes required to play chess game.
This was like a general question. I said four classes like – pieces, board, clock, player and
game. He asked me to identify the attributes and functions of each of the class and how
they interact with each with other. I told them. He was satisfied.
Finally, he asked me if I had any questions for him. I asked him a few questions and we
were done.
That was all for the interviews.

758
Chapter 308. Set 305 (On-Campus for Internship)

General Tips:
Don’t be nervous when speaking to the interviewer. And don’t think for a long time. Speak
out your thoughts so that they can help if you go wrong. Preparing from GeeksforGeeks
helps a lot.
Best of Luck!

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-305-on-campus-for-internship/

759
Chapter 309

Set 306 (On-Campus)

Amazon Interview Experience | Set 306 (On-Campus) - GeeksforGeeks


Amazon came for FTE as well as internship.
MCQ consisted of 20 questions.18 were related to mathematics and ds/algo. Everyone
found ds/algo questions simple while maths questions were fro topics like pipes/cisterns,
distances, log, etc were quite complicated. I managed to get about 10 + correct and both
coding questions correct to crack the online round.
The two coding questions were:
1) Largest subarray sum (O(n^2) was even getting accepted!)
2) Reverse individual words of sentence
eg-
i/p This is a game
o/p-game a is This
Round 1:
First round consisted of following questions:
1) Given an array of string and array of characters find the string with atleast one and
the most occurence of all characters in array of characters.If there is tie print first occuring
string.
eg:vector<string> = {“abcda”, “aaaaaaa”, “abcc”}
vector<char> = {‘a’, ‘b, ‘c’};
answer should be abcda
2) Check wether tree is balanced or not i.e check balance factor O(n) solution was expected
3) Given a string find longest substring with no repeating characters: O(n) solution was
expected
I solved all of the q’s in first round with best complexity and interviewer was quite impressed.

Round 2:
In round 2 following q’s were asked
1) Given n points in 2 d space and two functions JOIN(A,B) and istransitvelycon-
nected(A,B).
Join assigns A,B to same set while istransitvelyconnected(A,B) checks wether belong to

760
Chapter 309. Set 306 (On-Campus)

same set.Solved using disjoint set using path compression


2) Clone a doubly linked list with random pointer.
Got confused and stuck in this question..but somehow managed to solve with O(n) space
using hashing..
Interviewer was not very impressed coz of 2nd q but still I managed to reach 3rd round.

Round 3:
Two questions were asked
1) Find path with root to leaf sum as equal to target.
2) Given an infinite string defined by function f(x)=x+”0�+f(complement x) find k’th bit
Solved first one easily,got stuck in second one so solved using brute force…
However,managed to reach 4 th round
Round 4:
Interviewer was little arrogant to my surprise..he kept staring and grinning while I solved
the problem..he also said since it is 12:30 I wont waste time asking to introduce you.although
ALL other people had theoretical round involving OS,CN,DBMA concepts I was asked to
solve coding problems again..
I was asked my favorite Data structure..I said tree..
1) Find shortest distance between two nodes of binary tree..after 2 mins. I said just find
LCA in one traversal and then the path of the nodes in other traversal..
soln is O(n)..he asked me to write LCA code ..i wrote in O(1) space using recursion…maybe
he wanted solution in 1 traversal..although he did not tell me that..
2) The RAM of pc is 4 gb and file is 40gb in size .File contain numbers..sort the numbers..I
came up with dividing files and using heap to sort all the file..
Asked me to writ the data structure…gave something like this..

struct heap
{
int element;
FILE *f;
}
heap arr[];

Got confused with complexity a bit…


Result came out after 1 hour.. I was not selected :(..We asked about internship they told
they did not come for internship although they said this during their presentation the same
morning!!But can’t help..life is unfair…
Some of the students got rejected despite having excellent coding skills and
amazing profile at codeforces,topcoder,codechef,etc..
Questions asked from other people:
1. Flattening of tree
2. Word break problem
Thanx @geeksforgeeks!!
All Practice Problems for Amazon !

761
Chapter 309. Set 306 (On-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-306-on-campus/

762
Chapter 310

Set 307 (Off-Campus)

Amazon Interview Experience | Set 307 (Off-Campus) - GeeksforGeeks


I got call from consultancy for Amazon. After profile shortlisting, i received online test and
then had telecom interview. After I went to Pune for f2f interview. HR shares all the topics
need to study for interview. Below are the details of all rounds.
Round 1: Online test
Hackerearth
2 programs with 75 mins duration.
Round 2: Telecom interview
2 coding programs here too. Initially approach need to discuss, and once it’s concrete and
finalized they will ask to write code.

1. Find level with maximum nodes on binary tree


2. Addition of infinite size of integer

Round 3: F2F design round

• Design parking system

Round 4: F2F design round

• Design notification system

Round 5: Coding round

1. Remove half nodes from binary tree


2. Swap elements in linked list

Round 6: coding round

763
Chapter 310. Set 307 (Off-Campus)

1. LRU cache implementation


2. Copy binary tree and create new. Binary tree has left, right and random pointer

In any round they will discuss your project in dept. And asks for alternatives for technologies
used in your application.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-307-off-campus/

764
Chapter 311

Set 308 (For SDE)

Amazon Interview Experience | Set 308 (For SDE) - GeeksforGeeks


I was recently interviewed for the position of SDE-1 at Amazon. It was a 3 round process:
Round 1:
On paper coding:

1. Given a binary tree print it in vertical order. The problem is stated here: https:
//www.geeksforgeeks.org/print-binary-tree-vertical-order/
2. Given a linked list convert it into given format:

1->2->3->4->5->6
to
1->6->2->5->3->4

Round 2:
It was an in-person interview.I was asked only one question. He asked me about various
approaches. With least space complexity, least time complexity, different data structure
usage for the following problem:
https://www.geeksforgeeks.org/trapping-rain-water/
Round 3:

1. I was asked to implement a queue with any data structure, discuss its time complexity,
why the particular DS was chosen etc.
2. Second question was to find the number of islands given a graph, i.e. find number of
disconnected graphs given a graph.

All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-308-sde/

765
Chapter 312

Set 308 (On-Campus for


Internship)

Amazon Interview Experience | Set 308 (On-Campus for Internship) - GeeksforGeeks


Online Round (1 hr 30 min): 20 MCQs and 2 coding questions
MCQs : There were 20 MCQs based on DS, OS, IQ and output questions.
Coding questions:

1. Given an expression containing alphanumeric characters and parenthesis, check if “(”


and “)” are balanced. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
2. The preorder and the inorder traversals of a binary tree are given.Convert this
to a tree where each node contains the sum of the left and right sub trees in
the original tree. The values of leaf nodes are changed to 0. Print the preorder
and theinorder traversals of the modified tree. https://www.geeksforgeeks.org/
convert-a-given-tree-to-sum-tree/

Technical Round 1 (around 1 hr)

1. 1. The interviewer asked me about my project, mainly the database part.


2. Given a rectangular matrix and n moves. If you are at a position (x,y) , you can move
to (x+1,y) , (x-1,y), (x,y+1), (x,y-1). What is the probability that after n moves ,you
will remain inside the rectangle?
3. https://www.geeksforgeeks.org/find-four-elements-a-b-c-and-d-in-an-array-such-that-ab-cd/

Technical Round 2 (around 1 hr)

1. The interviewer asked me what data structures I know. Then he asked me the appli-
cations of graph.

766
Chapter 312. Set 308 (On-Campus for Internship)

2. Suppose there is a social networking site like Facebook. Every user gets some friend
recommendations (i.e. People you may know!). Now, if there is a user A and he has
100 friends and each of his friends has got 5 other friends,A can get these 500 recom-
mendations. But the condition is that he should only get the top 10 recommendations
with whom he has the maximum number of mutual friends(If A and B are friends and
B and C are friends, then A and C have a mutual friend, B). Suggest an efficient data
structure for this and how to implement it. The implementation should be flexible as
at any moment, any user can make new friends and he may also unfriend someone!
3. Applications of heap. Insertion in a heap ( insertion of strings in a heap, priority is
decided lexicographically). Time complexity of insertion.

Thanks GeeksforGeeks �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-308-on-campus-for-internship/

767
Chapter 313

Set 309

Amazon Interview Experience | Set 309 - GeeksforGeeks


0th Round: (Online): 20 MCQs + 2 Coding Questions In hackerrank platform:
MCQs Topics:
Quantitative aptitude(speed,mixture,ratio etc)
C apps (find o/p time complexity)
Os,DBMS
MCQs based on quants was little bit challenging.
Coding Questions:
1) Size of Largest subarray with given sum.
2) Reverse Individual words in a string.
i/p : This is a game
O/p: game a is This
After this round 39 were short listed.
There were 4 rounds of interviews(all technical)

Round 1:(1 hr written round)


1)zigzag traversal of a binary tree.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2) Find the size of largest island from a group of islands.
A variation of: https://www.geeksforgeeks.org/find-number-of-islands/
There were 13 people 39 were divided to thirteen groups and one was eliminated in each
group.
Round 2:(1 hr Face to face)
First question was tell me about yourself.
Thoroughly went through my resume.
Asked me about my projects and internship experience.
Then a question came in Arrays.
Q) Replace every element by its Immediate greater element

768
Chapter 313. Set 309

i/p: 5 6 3 10 9 12
o/p: 6 10 10 12 12 12.

Then os questions came.


1) what is virtual memory?y is it so called?
2) paging and segmentation concepts.(in and out)
3) size of virtual memory.
Then he asked me “do u hav e any questions?” . I asked few questions in Amazon cloud
drive.
Round 3:(1hr 15 min Face to face)
First question was “tell me about yourself”.
Then the Questions came:
1.Find Minimum in each k sized window.

i/p:12 3 4 10 6 5
k = 4
o/p: 3 3 4

I told him the Queue approach he is not satisfied. Then I started with dequeue ,he stopped
me and asked me to use data structure other than queue. I told him min heap approach.
He seemed to be satisfied .He asked me to write a production level code for that.
2. A new tree data structure is given in which each node has two values top and bottom,
when all the nodes are arranged in tree, the top vales of all nodes must follow BST while the
bottom values must follow min heap. elements can be inserted in any order(not the order
of arrival).
I gave my solution. He was satisfied and asked me to write a production level code for that.
Finally, “do u have any questions?”
Round 4:(1hr 30 min Face to face)
1. The celebrity problem: https://www.geeksforgeeks.org/the-celebrity-problem/
2. Count possible decoding sequence: https://www.geeksforgeeks.org/count-possible-decodings-given-digit-sequence/
3. We are receiving a stream of data from a social network, how will you display k max
persons based on number of friends?
He was satisfied with my approach of max heap.
Finally, “do u have any questions?”
After each interview some were eliminated.
Thanks to geeks for geeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-309/

769
Chapter 314

Set 310 (For Internship)

Amazon Interview Experience | Set 310 (For Internship) - GeeksforGeeks


Technical round 1:
1 I was asked to implement L.R.U.(least recently used cache) using any DS i want
2 Build a Binary Tree using inorder and preorder
Technical round 2:
1-Quick sort
2-Questions about DBMS and DS to make it more efficient
3-Find minimum and maximum number in an array with minimum number of if statements
4-Discussion about c++
They didn’t conducted more technical rounds.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-310-for-internship/

770
Chapter 315

Set 311 ( On Campus for


Internship and FTE)

Amazon Interview Experience | Set 311 ( On Campus for Internship and FTE) - Geeks-
forGeeks
Recently Amazon came to our college for both FTE and interns. Here I am sharing my
interview experience. There was 1 online round and 4 F2F interviews. Online round had
2 coding questions and 20 MCQs (based on OS, sorting complexity, Recursion, DBMS ,
geometry etc).
F2F 1
He introduced himself and asked me about my project which I had done in Samsung Research
Institute this year.
Then He asked me these questions
1. Suppose there is only one platform and n number of trains. So at any point of time only
1 train will stay in platform. N time intervals are given which represent the timing duration
of n trains.You have to find what is minimum number of trains that have to be postponed
such that no collision take place.(full code was required covering all corner cases)
2. Suppose a string “abca” is given. Print all of its permutation such that no 2 same
combination will be printed twice. (Considering string can have duplicate characters).(full
working code required)
3.Asked me what DS I will use to evaluate a given expression? Then Asked to write the
code of Infix to Postfix conversion.
4.There is an array of N numbers ranging from 1 to N. Only 1 number is missing, return
the index of that number.
F2F 2
Asked me many question regarding my project for first 10 minutes.Then asked the following
questions

771
Chapter 315. Set 311 ( On Campus for Internship and FTE)

1. A matrix is given containing only 1 and 0. So whenever you access a 0 make the entire
row and column as 0.
I was using o(n2) space first, he said to use o(n) space only.
2. Given a binary tree find the minimum root to leaf height.
I told him a level order solution where I was en queuing the level also with each node. He
said not to push the levels with each node, so I kept on delimiter which I was pushing only
after one entire level traversing was over and returned as soon as I got a leaf node.
F2F 3
This interview was taken by the senior most person among the interview panelists. I was
nervous while entering the room and as a result I messed up the interview.
He directly started asking question without any introduction which made me more nervous

1. He wrote one nested recursive program(around 12-15 lines) on a page and asked me to
draw the recursion stack of that program and show him in what order one function is called
and stored in the stack and in what order it is returned back to its callee function. And to
prove what is the space complexity through that recursion stack.
I was nervous and was loosing confidence so could not solve it properly.
2. Find the second largest and second smallest in a given array in single traversal.
3. Find power(x,y) without using pow function.(divide and conquer approach was required)
After this round I did not get a call for the last round. Some of my friends were asked
questions on basic BFS application, topological sorting , LRU cache implementation , Boxing
stack problem in the last round.
Tips
1. Questions asked will be very easy at most of the times. Be confident. Whatever be the
question you were asked try to solve it as long as you can, share your approaches with your
interviewers.They will certainly help you out.
2. Have a clear idea of your project, they will ask you several questions regarding that.
3. Work very hard. �
All the best �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-311-on-campus/

772
Chapter 316

Set 312 (For SDE II)

Amazon Interview Experience | Set 312 (For SDE II) - GeeksforGeeks


I was not able to recall phone interview question from Amazon for SDE – II . After few days
from phone interview, I got an email invitation to fly for face to face interview. Below are
the questions that I was asked during the in-person interview.
Round 1:
Write a program to check whether it is a valid binary tree or not.
Check all test cases (e.g. No left Node case).
Behaviour Questions
Round 2:
Behaviour Questions
Tell me your current job roles, responsibilities , Challenges and improvements that you can
make on your current project
Round 3:
A lot of Behaviour Questions again
Introduction, your current roles and responsibilities
Round 4:
Various Types of Behaviour Questions
Design a kind of kindle fire application where we can subscribe news channel and read the
news from all publishers as a digital format.
Round 5:
Behaviour Questions
Design an OOP concept for an application where employee can dispatch their incoming
phone call according to their seniority level if they are not able to solve.
All Practice Problems for Amazon !

Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-312-for-sde-ii/

773
Chapter 317

Set 312 (Off Campus)

Amazon Interview Experience | Set 312 (Off Campus) - GeeksforGeeks


I got a call from amazon for F2F discussion for SDE1 at hyderabad. There were totally four
rounds and asked to leave for the day.
First round:

1. Find the kth smallest element in row wise and column wise sorted matrix. (No Heap
solution)
2. There is a given data with time and number of orders at that time and it will random.
Then there will be a query of how many orders placed between a given interval of
time.

Second Round:

1. https://www.geeksforgeeks.org/minimum-number-of-swaps-required-for-arranging-pairs-adjacent-to-each-oth
2. There given a list of strings out which we have to print the unique strings. Unique
string is a string which is not repeated.

Third Round:
It was a discussion on my current project and the challenges I faced and how I managed
when I am unable to meet the deadlines.

1. There given a 2 Lists with int values. We need to find the longest chain. Eg: L1 = {
2,7,4,8,9,10}, L2 = {1,2,8,9,4}. Here the solution is 2 (chain is 2,4 or 8,9). Because 7
is present in L1 which is not L2.
2. Given a equi-weighted uni directed graph and need to find the max distance possible
from a given node.

Fourth Round:

774
Chapter 317. Set 312 (Off Campus)

It was again discussion on my current project.


Final question of my interview: Add 1 to the integer represented by a linked list with O(n)
time and O(1) space.
First I start with the recursion and he suggested me without stack space too. Then I
suggested for the reversing of linked list and then adding the number. He was again asked
me without reversing of linked list. Then I came up with the solution with linear search.
Thanks GeeksforGeeks for your work in helping so many programmers!!

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-312-off-campus/

775
Chapter 318

Set 313 (For SDE II)

Amazon Interview Experience | Set 313 (For SDE II) - GeeksforGeeks


1st Round(Written) – 60 mins
It was a test on HackerEarth with two programming questions

1. The Maximum Subarray problem: Given an array A of N elements, find maximum


possible sum of
a. Contiguous Subarray
b. Non Contiguous Subarray
2. Connected Cell in grid problem. Find the number of cells in largest region.

2nd Round (DS and Algo) – 45 min

1. Palindrome Partitioning– Spilt a string into minimum number of substring such that
each substring is a pallindrome.
2. Find the diameter of a binary tree

General discussion on current role.


3rd Round (DS and Algo) – 45 min

1. find differnce in height of two nodes in a binary tree.

4th Round
Detailed Discussion on current role and responsibilities.
Discussed complete architecture of my current project- in terms of classes and methods,
databases and cache used and then discussed improvements that i could suggest in architec-
ture of my project.
5th Round
Discussion on current role and responsibilities. Discussed on architecture of my previous

776
Chapter 318. Set 313 (For SDE II)

projects and technologies i have worked on.


Design question- Design a enhanced search that can help customer executives to search for
the query asked by user through all the possible sections like- payment, order etc.
6th Round
Design a job scheduler.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-313-for-sde-ii/

777
Chapter 319

Set 314 (For FTE)

Amazon Interview Experience | Set 314 (For FTE) - GeeksforGeeks


Recently Amazon came to our college for both FTE and interns. Here I am sharing my
interview experience. There was 1 online round and 3 F2F interviews and 1 Bar Raiser
round.
Online round had 2 coding questions and 20 (MCQs based on sorting complexity, Recursion,
quantitative aptitude , geometry etc).
F2F 1
He introduced himself and asked me about my project.
Then He asked me these questions
1. Find the maximum of all subarrays of size k.-https://www.geeksforgeeks.org/
maximum-of-all-subarrays-of-size-k/.
I gave him a o(n*n) approach, then o(n*log(n)) approach using segment tree, then
o(n*log(k)) using max heap and then o(n) approach using deque. He asked me to write the
full production level code.
2. Find the first non-zero digit starting from right in n! Simply keep the last digit of every
multiplication, gave an o(n) approach. He seemed to be satisfied.
F2F 2
He asked the following questions
1. He asked me to make a dictionary in which i had to search a string and if it is not present
, i had to insert in dictionary. Gave a o(n*log(n)) approach using map. He asked to optimize
it , then gave a trie approach. He asked me to write full code for it.
2. He asked me, what is LRU cache and how it is implemented. Then he asked me to write
the full production level code for it.
F2F 3
This interview was a design round as well as theoretical round.

778
Chapter 319. Set 314 (For FTE)

1. Firstly, he asked me about my favorite subjects. I told him operating system. Then he
asked me about process scheduling algorithms and then he asked me how will you allocate
memory to a newly formed file. I told him about first fit, best fit and worst fit. He asked
me what are the advantages and disadvantages of these.
2. Then he asked me a design question. Let’s say you have a 13 floor building and it has 6
lifts in it, you have to design an algorithm such that if a user click the lift button, any of
the available lift should reach to him in minimal time.
3. Then he asked to give the design for top k trends of twitter of facebook. I told him that
i’ll keep a trie for storing the count of the number of users associated with a particular trend
and will keep this count in max heap and will extract top k trends.
Solution for design varies from candidate to candidate. so you should design your own
solution rather than searching solution on google.
F2F 4
This was a Bar raiser round and it was telephonic. He asked about my project and we had
discussion on it in detail . After 40 minutes he asked me to write the full production level
code on implementing LRU using circular linked list. It was easy and i had done that in
second round also, so i wrote the whole code and he was satisfied.
verdict: selected �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-314-for-fte/

779
Chapter 320

Set 315

Amazon Interview Experience | Set 315 - GeeksforGeeks


Interviewed for Mumbai location.
Round 1 (Written round – 45 min)
1. Count the number of occurrences in a sorted array : https://www.geeksforgeeks.org/count-
number-of-occurrences-in-a-sorted-array/
2. In given range, print all numbers having unique digits. e.g. In range 1 to 20 should print
all numbers except 11.
3. Given a node, you can even find the next highest node in O(log(n)) time :
http://stackoverflow.com/questions/20990808/bst-finding-next-highest-node
Round 2 :
1. Tell me about yourself
2. A ‘plus’ pattern of size 1 is defined as following :

1
1 1 1
1

size 2 :
1
1
1 1 1
1
1

Find size of largest plus pattern in given 2D mattrix which has only 0s &1s.
Round 3:
1. check if a binary tree is BST or not :https://www.geeksforgeeks.org/a-program-to-check-
if-a-binary-tree-is-bst-or-not/

780
Chapter 320. Set 315

2. Min Cost path : https://www.geeksforgeeks.org/dynamic-programming-set-6-min-cost-path/


3. Check if two linked lists merge : http://stackoverflow.com/questions/1594061/
check-if-two-linked-lists-merge-if-so-where
4. Count ways to reach nth stair : https://www.geeksforgeeks.org/count-ways-reach-nth-stair/
The guy opened geeksforgeeks link in front of me and was asking from there directly!
Round 4 (Skype Round):
1. Tell me about yourself.
2. Tell me most challanging project you did. 30 min detailed discussion about project. (So,
choose answer to this wisely �
3. Find the smallest window in a string containing all characters of another string : https://
www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-characters-of-another-string/
4. How HashMap is implemented? (https://tekmarathon.com/2012/12/04/hashmap-internal-implementation-analys
*This is most favourite question of Amazon*
Round 5 (Skype round):
1. Tell me about a situation when you had conflict with manager.
2. Tell me about situation you screwed up something.
3. What is the most technical challanging work you did?
4. Implement LRU cache : https://www.geeksforgeeks.org/implement-lru-cache/
Unique Numbers
Smallest window in a string containing all the characters of another string
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-315/

781
Chapter 321

Set 316 (Off-Campus)

Amazon Interview Experience | Set 316 (Off-Campus) - GeeksforGeeks


Amazon Off Campus Interview Experience(SDE-1, Experienced)
Round 1:
1) Tell me about yourself.
2) Trapping Rain Water : Given n non-negative integers representing an elevation map
where the width of each bar is 1, compute how much water it is able to trap after raining.
https://www.geeksforgeeks.org/trapping-rain-water/
3) Print left view of a binary tree.
https://www.geeksforgeeks.org/print-left-view-binary-tree/
Discussion : I gave two approaches one with DFS and other with level order traversal.
He asked to compare two approaches and implement the efficient one. DFS is the efficient
one because in level order, you need to store all the nodes at each level, some of them may
not be a part of the left view of BT.
Round 2:
1) Tell me about yourself.
2) Find sum of n elements after kth smallest element in BST. Tree is very large, you
are not allowed to traverse the tree.
Discussion : Since the array traversal is not allowed so we need to do some prepro-
cessing over the tree, something like storing sum of all its predecessor nodes. For finding
kth smallest element, use order statistics approach:
https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/
3) Given a sorted array which has been rotated n number of times. Find the value of n.
It is similar to below post where you need to find only the pivot element. If you have the
Index of pivot element, you can get the number of times the array is rotated.
https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/
Round 3:
1) Count ways to reach nth stair.
https://www.geeksforgeeks.org/count-ways-reach-nth-stair/

782
Chapter 321. Set 316 (Off-Campus)

It is similar to fibonacci series. Interviewer asked various ways to implement the same –
Recursion, 1-D array, with 3 variables and complexity of each.
2) Design recommendation engine.
It’s like auto suggestion. I gave the trie approach. The interviewer seemed fine with this
approach and asked me to write full code with time and space complexities. Implementation
of Tries:
https://www.geeksforgeeks.org/trie-insert-and-search/
Round 4 (Managerial Round – Over video call)
Tell me about yourself.
Current work
Which project you liked working the most.
Any case where you had conflict with your manager.
Any idea/technology suggested by you to your team which then got implemented and worked
out.
Any case when you had to work out of your comfort zone.
The most critical feedback received from your manager/team members.
What do you do to enhance your technical knowledge apart from your project work.
And many more.

Round 5(Final Round – Telephonic)


Initially I was asked questions about the work I had done, the projects I did and some
managerial questions.
Then I was given a coding problem to solve. They use Collabedit tool in phone screen
interviews where the same screen is shared by both interviewer and interviewee.
Ques : Print all the non-repeating words out of two given sentences.
Eg. Statement 1: I have a blue pen.
Statement 2: I got a red pen.
Output : have blue got red
Discussion : I suggested the hashing approach. The interviewer asked to implement the
same.

Points to take care:


You must know how to calculate time and space complexities.
In each round they ask you about the project you recently did/ the project you liked working
most/ most challenging work etc – so you should be prepared well for at least one project
with in-depth details.
Start with the naive approach for each question asked and then proceed with solutions with
better space and time complexities.
No need to waste time reading about Operating Systems, Networking, DBMS etc. They
only care about the projects you did and your coding skills whether you cover all the edge

783
Chapter 321. Set 316 (Off-Campus)

cases while writing code, know time and space complexities, have better approaches for
solving same problem and so on.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-316-off-campus/

784
Chapter 322

Set 316 (On-Campus)

Amazon Interview Experience | Set 316 (On-Campus) - GeeksforGeeks


Round 1- 90-100 min

• First Ques- So what you know about Amazon- I wasn’t prepared to start my interview
with this ques. But I had read months earlier how Amazon was established and was
able to satisfy him with answer.
• 2 ques- Tell me about Summer Intern at wipro- It took around 20 min. Deep discussion
on project, all in and out.
• 3 Ques- How does the program gets compiled internally, I told him I have not studies
this part as my branch is ECE.He then asked me what have you studied- I told him
DS algo ,OS, Networks and convinced him that ECE is strongly related with CS in
terms of Algorithm.
• 4 ques- As i told him that I like competitive coding, He asked tell me 1 quess you have
solved- I told him- Find the K-most frequent occurring word till now in a running
stream of words by using Trie(modified) and Heap concept. He asked why I am using
min heap and not Max heap and I gave the reason.
• Everything about Min Heap-> Insertion deletion modification.
• Given data How will you sort them. I told him quick sort , merge sort are possible
ways.He asked which you will prefer I told him QuickSort .Why not Merge sort? I
told him because of external memory use but then he asked that can’t we do it in-place
, later on I was able to do inplace merge sort and he again asked which algo you will
prefer I told still quicksort because it is more Cache Friendly and he was satisfied.
• Given 100 gb data, you need to sort them how will you proceed. I told him external
sorting and he straight away told me I don’t want merge sort. Then I tried to twist
the situation by asking what type of data is available. He was in doubt why am I
asking that, So I told him if all the data is in limited range then I can simply apply
counting sort and he was impressed as well he forgot about the actual question. �
• He was done with the interview and said do you have any ques. ME- What role will
be playing in the team if selected.

In 2 min They told me that i was cleared for 2 round.

785
Chapter 322. Set 316 (On-Campus)

Round 2
I went for 2 round without wasting time as Spot On offers were to be given. Interviewer
was slightly weired and he straight on went for the ques.
There is data available for different vehicles and all vehicles have n parameters which dis-
tinguish it with other vehicle so given huge data you need to separate them in different
lists based on some parameters matching. How will you proceed->Then he said 3 parame-
ters are there and if all 3 parameters match then they belong to same list.
I told him lets sort the data according to first parameter then for then sort acc to 2 para
and so on..(something like Radix sort).
He told me to use Hash-Map and model the whole idea….building the structure for each
vehicle and then use key to do hash-mapping.
I implemented it but due to too much overwriting, He was not looking impressed but he
told its correct.
DO u have any questions.
After this Round I was rejected.
TIPS-

1. Please be prepared for Hash_MAP it is very important to have deep knowledge as this
part is rarely covered in.
2. Try to write clean codes and by clean code I mean you shoud use good variable name,
dont scribble much and try to write comments along with it.(I made a mistake here.)
3. You should know all in and outs of the project and remember interview can ask any
project.
4. Puzzles don’t matter much…

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-316/

786
Chapter 323

Set 317 (SDE-1 Off – Campus)

Amazon Interview Experience | Set 317 (SDE-1 Off - Campus) - GeeksforGeeks


Round 1:

1. Tell me about yourself.


2. Trapping Rain Water :Given n non-negative integers representing an elevation map
where the width of each bar is 1, compute how much water it is able to trap after
raining.
https://www.geeksforgeeks.org/trapping-rain-water/
3. Print left view of a binary tree.
https://www.geeksforgeeks.org/print-left-view-binary-tree/
Discussion : I gave two approaches one with DFS and other with level order traversal.
He asked to compare two approaches and implement the efficient one. DFS is the
efficient one because in level order, you need to store all the nodes at each level, some
of them may not be a part of the left view of BT.

Round 2:

1. Tell me about yourself.


2. Find sum of n elements after kth smallest element in BST. Tree is very large, you are
not allowed to traverse the tree.
Discussion : Since the array traversal is not allowed so we need to do some preprocess-
ing over the tree, something like storing sum of all its predecessor nodes.For finding
kth smallest element, use order statistics approach:
https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/
3. Given a sorted array which has been rotated n number of times. Find the value of n.
It is similar to below post where you need to find only the pivot element. If you have
the Index of pivot element, you can get the number of times the array is rotated.
https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/

Round 3:

787
Chapter 323. Set 317 (SDE-1 Off – Campus)

1. Count ways to reach nth stair.


https://www.geeksforgeeks.org/count-ways-reach-nth-stair/
It is similar to fibonacci series. Interviewer asked various ways to implement the same
-Recursion, 1-D array, with 3 variables and complexity of each.
2. Design recommendation engine.
It’s like auto suggestion. I gave the trie approach. The interviewer seemed fine with
this approach and asked me to write full code with time and space complexities. Im-
plementation of Tries:
https://www.geeksforgeeks.org/trie-insert-and-search/

Round 4(Managerial Round – Over video call)

1. Tell me about yourself.


2. Current work
3. Which project you liked working the most.
4. Any case where you had conflict with your manager.
5. Any idea/technology suggested by you to your team which then got implemented and
worked out.
6. Any case when you had to work out of your comfort zone.
7. The most critical feedback received from your manager/team members.
8. What do you do to enhance your technical knowledge apart from your project work.
And many more.

Round 5(Final Round – Telephonic)

1. Initially I was asked questions about the work I had done, the projects I did and some
managerial questions.
2. Then I was given a coding problem to solve. They use Collabedit tool in phone screen
interviews where the same screen is shared by both interviewer and interviewee.
Ques : Print all the non-repeating words out of two given sentences.
Eg. Statement 1: I have a blue pen.
Statement 2: I got a red pen.
Output : have blue got red
Discussion : I suggested the hashing approach. The interviewer asked to implement
the same.

Points to take care:

• You must know how to calculate time and space complexities


• In each round they ask you about the project you recently did/ the project you liked
working most/ most challenging work etc- so you should be prepared well for at least
one project with in-depth details.
• Start with the naive approach for each question asked and then proceed with solutions
with better space and time complexities.
• No need to waste time reading about Operating Systems, Networking, DBMS etc.
They only care about the projects you did and your coding skills whether you cover
all the edge cases while writing code, know time and space complexities, have better
approaches for solving same problem and so on.

788
Chapter 323. Set 317 (SDE-1 Off – Campus)

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-317-sde-1-off-campus/

789
Chapter 324

Set 318 (For SDE Intern)

Amazon Interview Experience | Set 318 (For SDE Intern) - GeeksforGeeks


The First Round of test was taken online by Amazon on Hackerearth.
First Round:

• 20 MCQs
• 2 Coding Questions:
– Find zeroes to be flipped so that number of consecutive 1’s is maximized
GFG Link: https://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-1s-is-
– Find the first circular tour that visits all petrol pump (Similar to this)
GFG Link: https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations

2 Technical Rounds:
They take time in declaring results as they ensure that all eligible candidates make it to the
Technical Interviews. Technical Rounds also consists of coding. Here, you need to discuss
your approach with the interviewer and then code it on paper.
1st Technical Round:
General question of Tell My About Yourself. Following this were technical questions mainly
coding.
Q1. Find the position of the rightmost set bit.
I gave various approaches, firstly dividing by 2. Then they asked for a solution using
bit operations. Gave them solution using OR. GFG Link: https://www.geeksforgeeks.org/
position-of-rightmost-set-bit/
Q2. Time complexity of Binary Tree: Searching, Inserting
2nd Technical Round:
Again asked Tell My About Yourself. There were 2 coding questions asked.
Q1. Large number sum using Linked List.
2 Approaches: Reversing the linked list and then adding or Recursion. Gave both the
solutions. Then the question was: In case of a billion digits, which would you prefer?
Recursion has a lesser time complexity but, a normal system won’t be able to operate so

790
Chapter 324. Set 318 (For SDE Intern)

much on recursion, as there will be a stack overflow. Hence for a billion digits we have to
go with reversing the linked list and then adding each digits.
GFG Link: https://www.geeksforgeeks.org/add-two-numbers-represented-by-linked-lists/
Q2. Find an element in a strictly row sorted and column sorted 2 dimensional array
without brute force.
GFG Link: https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/
Q3. Questions on Sorting and Searching algorithms complexity.
Q4. Questions on Networking
What is BGP(Border Gateway Protocol)?
What is Link State Routing? How does it work?
What is OSPF?
TCP/IP model and OSI model.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-318-sde-intern/

791
Chapter 325

Set 319 (On-Campus)

Amazon Interview Experience | Set 319 (On-Campus) - GeeksforGeeks


Online Round:
There were 20 MCQs based on basic programming, C output questions, OS. There were 2
programming questions.
1. Given an array with only 1s and 0s, You have to maximize numbers of 1s
in this array. You are allowed to do max one flip operation which can be ap-
plied to a range of continuous indexes. I used something like max sum con-
tiguous subarray dynamic programming approach. This problem is similar to
https://www.geeksforgeeks.org/maximize-number-0s-flipping-subarray/
2. You are given a linked list.
for i=1 to n/2, subtract (n-i)th number from ith number. Print modified linked list in the
end.
Technical round 1:
1. Given three numbers A, B and M. Calculate (A*B)%M. All numbers are in a range of 1
to 10^15 so prevent overflow. First I gave brute force approach for running a loop A times,
each time adding B to the answer and taking the mod. Then, I improved from O(n) to
O(logn) by calculating A*B/2 recursively and multiplying it by 2. The interviewer asked
me to write complete code for it.
2. He asked me whether I know about trie data structure and I said yes so he asked me to
write node structure of trie. I wrote the basic node structure. Then he asked me if I want
to add and match exact strings then how would I modify node structure. I told him to add
a boolean in the node signifying an end of the string. Then he asked me to write complete
code for adding a string in trie root.
Technical round 2:
He asked me introduction and questions asked in previous interviews.
1. Given a binary tree, print the edge nodes of this binary tree.
https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
2. You are given an array of contacts. Each contact consists 3 strings: name, email and
phone number. If any of these parameters match with any other contact’s parameter then

792
Chapter 325. Set 319 (On-Campus)

these 2 contacts are same. Find groups of same contacts. I suggested having a hashmap with
parameter string as key and index as value. Then when we encounter matching strings in
the hashmap, connect this 2 contact indexes as we do in Disjoint set Quick Union approach.
In the end. find matching contacts using find operation.
Technical round 3:
This interview was mostly based on resume discussion. He asked me about my internships
and projects and also asked me some OS questions. Then he gave me a chess problem. I am
given initial positions of 8 pawns and a knight. I have to answer whether I can remove all 8
pawns using my knight. Then he simplified question and now only 1 pawn is there. I wrote
full code for recursion to solve the problem but time complexity was exponential. Then he
asked me how do I find the minimum number of steps in which I can remove this pawn. I
modified my existing code to return a number of steps now.
Technical round 4:
This was kind of like HR round. Initially, he asked me about my latest internship work
and started with specific questions. What was the toughest challenge I solved during any
of my projects? What kind of problems you encounter when working in a team and how
can those be resolved? Did you ever write non-maintainable code and why did you write it?
Did it ever happen to you that you suggested some good approaches but they were thrown
to trash by higher authority and how did you tackle with that?
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-319-campus/

793
Chapter 326

Set 320 (Off-Campus)

Amazon Interview Experience | Set 320 (Off-Campus) - GeeksforGeeks


Recently i attended interview at amazon hyderabad for SDE-1.
Written round Two questions

1. Find the unique character from two strings


http://stackoverflow.com/questions/29794233/how-to-print-unique-alphabet-from-
two-strings-using-java
2. Parenthesis match problem
https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/

Face to Face

1. Two colors are given(yellow, blue), we have to color such that no consecutive blue
color is painted
Given the arrival and departure time of various trains in a station. Calculate the
minimum number of platforms required such that no train has to wait for another
train to vacate the platform.
The question basically means calculate the maximum number of trains that would be
present in the platform at any given time.
Answer
sort the arrival time and sort the departure time, keep a count initialized to 0. compare
the first element of the arrival time with the first of departure, increase the value of
count if the value at current Index at arrival is less than the value index at departure
and increment the arrival index, and vice versa. Keep the maximum count that you
see.

Second face to face

1. Implement stack using queue


https://www.geeksforgeeks.org/implement-a-stack-using-single-queue/

794
Chapter 326. Set 320 (Off-Campus)

2. Reverse linked list form n occurence ————–not so good


https://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/ 1->2->3->4-
>5->6->7->8
if k=3;
3->2->1->6->5->4

Third face to face

1. Design elevator in OO perspective.


2. How class is loading in JVM:- Discussed about eden, perm space. using graph and
BSF & DFS.
3. Clone the binary tree.

I didn’t got call after that.


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-320-off-campus/

795
Chapter 327

Set 321 (Online Assessment)

Amazon Interview Experience | Set 321 (Online Assessment) - GeeksforGeeks


Just completed Amazon’s online assessment that was given a week in advance to prepare
for.
It consisted of two tests on:

1. Code debugging (20 min)


2. Reasoning (35 min multiple choice)

The first part were 6 questions. Each with a provided code where it asks you fix and make
changes so it can compile/run correctly. Most of these problems were errors with syntax,
parameters, operators, and others along the same lines. The second part were 24 questions
on patterns, logic, and some others like concluding a given passage. Everything during the
test is monitored and questions can be returned to if moved on. Before starting it gives the
option of selecting a programming language from C, C++, or Java. For me I chose C. If
you ever coded at a university in a beginner/intermediate computer science class, then you
should have no problem getting through this. I just graduated last month so everything was
fresh to me still. I reviewed several old homework assignments that helped out a lot with
the basic understanding of algorithms and memory allocation. A lot of people told me to
study from the “Cracking the Code Interview” by Gayle, which I vaguely looked over and
found it did not help as much for this assessment, though it might for the next interview
processes. The most difficult aspect for me was the limited amount of time, especially the
first portion that requires you to read code line by line. I highly suggest you take your
time to read the question once and carefully, then answer if you can and if you cannot then
skip it and return if time permits. Other than that, I found it far simpler than what I had
expected and overly prepared for. They said I will be contacted for the next interview step
within a week.
All Practice Problems for Amazon !

796
Chapter 327. Set 321 (Online Assessment)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-321-online-assessment/

797
Chapter 328

Set 322 (Off-Campus)

Amazon Interview Experience | Set 322 (Off-Campus) - GeeksforGeeks


Recently I attended interview at Amazon for SDE 1 profile.
Round 1 (Written):
3 questions were given and I was asked to write the executable code in any language.

1. Check whether the tree is BST. (O(n) time).


2. Check whether the Linked List is Palindrome. (O(1) space).
3. One array (Array 1) of size m with m sorted elements and another array (Array 2) of
size (m + n) with n sorted elements, you have to put all the elements from both the
arrays in Array 2 in sorted order. (O(1) auxiliary space and O(m + n) time).

Round 2 (F2F):

1. Given a stack of integers of size n, you have to sort it using only push and pop
operations (you are not allowed to copy the numbers in auxiliary array and sort it and
then push back in array). (I gave O(n^2) approach and O(1) auxiliary space).
2. Stepping on stairs: A valid move is defined as either a single step or 2 steps. Starting
from 1st stair you have to reach nth stair in minimum valid moves. I gave dp approach
then rolled down it to Fibonacci formula which can be solved in O(log(n)) time using
Matrix Exponentiation.
3. Stepping numbers: A stepping number is defined as a number in which the absolute
difference between the consecutive digits is not greater than 1, A stepping number
cannot be a single digit number. You have to find the number of stepping numbers
between n1 and n2 where n2 > n1 and n2, n1 > 0. First I gave brute force approach
i.e. traverse from n1 to n2 and print i if i is a stepping number. They asked me to
optimize it, after a little while I came up with BFS solution, where a node in graph
(directed) represents a number and nodes directly connected to it have one more digit
appended at the end. Stop when number dequeued from the queue is greater than n2.
4. Iterative version of Tower of Hanoi. I gave stack version of TOH. Since recursion uses
recursion stack. I removed recursion and used stack to imitate recursion instead. They
were satisfied with the solution.

798
Chapter 328. Set 322 (Off-Campus)

Round 3 (F2F):

1. In any point of time print the first non-repeating number in a stream of numbers. It
took me quite a while and after little brainstorming I came up with solution using
DLL and map.
2. Delete node in a BST. I had forgotten how it was done so again I had to think hard,
realized that deleted node must be replaced with its inorder successor to maintain the
BST property and coded the solution.
3. This was the most exciting round. They seemed happy with my approach.

Round 4 (Design Round):

1. Design a Parking Lot.


2. Create queue using stack.
3. Discussion on all the OS scheduling Algorithms.
4. How to implement SRTFS (preemptive SJF).
5. Discussion on Inter Process Communication : Shared Memory and Sockets.
6. Why sockets are preferred over Shared Memory.
7. Where shared memory is stored (in user space or kernel space) ? and why ?

Round 5(Hiring Manager Round):

1. General Discussion.
2. Infix to Postfix conversion.
3. Return a maximum length sequence containing consecutive numbers from a binary
tree. i.e.

90
/ \
1 66
/ \
2 67
/ \ /
5 4 68
/ \
99 100

Consecutive sequence of maximum length: [66, 67, 68] of length 3.

I had the hunch but was not able to code it at first, so he asked me to do it later then after
some discussion, i was given 15 min to complete it and finally in those 15 min it clicked and
I managed to do it.
Some advice:

799
Chapter 328. Set 322 (Off-Campus)

1. Practice coding on paper, try to do write clean code without overwriting.


2. Brush up important concepts of OS.
3. They concentrated more upon the thought process to reach the final solution. So think
loudly and you will receive hints ;).
4. Keep calm and remain confident.

Thank you Geeksforgeeks !!!


All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-322-off-campus/

800
Chapter 329

Set 323 (Software Development


Engineer – Off-Campus)

Amazon Interview Experience | Set 323 (Software Development Engineer - Off-Campus) -


GeeksforGeeks
I applied off campus for the role of Software Development Engineer at Amazon, Hyderabad.
Round 1 (Telephonic) : 1 hour
Interview began with my intro and briefing of my work at current company.Then he asked
me two coding questions :

• Ques 1 : You are given an array of size n. Now print the number of distinct elements
in the array for every frame of size k.
• Ques 2 : A binary tree and a number, say k are given. Print every path in the tree
with sum of the nodes in the path as k.(A path can start from any node and end at
any node, i.e. they need not be root node and leaf node; and negative numbers can
also be there in the tree)

After two weeks, I got a mail to come for the face to face rounds of interviews.
Round 2 (F2F) : 1 hour
Interviewer was very friendly. I was tensed before entering into the room but after talking
to him for a minute, I started feeling comfortable. He started with his introduction and
then asked me about myself and the work I am doing in my current company.
Then, he moved on to the coding questions.

• Ques 1 : A binary tree is given.You need to print every path in the tree starting
from root with sum of the nodes of an path equal to a given number, k.(Numbers can
be negative too)
Sol : https://www.geeksforgeeks.org/given-a-binary-tree-print-all-root-to-leaf-paths/

801
Chapter 329. Set 323 (Software Development Engineer – Off-Campus)

• Ques 2 : A linked list is given in which every node has two pointers, one to its next
node and the other one, random pointer, pointing to some other node in the linked
list.You have to clone the given linked list.
Sol : https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/

Some questions that arose as a result of discussion on OS were :


Q1 . What is critical section problem and how is it solved?
Q2 . What is Semaphore?
Q3 . What is race condition?
Q4 . What is write lock and what are the conditions of it?
Q5 . What are threads and processes?
Then he asked me if I had any questions and then I was asked to wait for the result of this
round.
I was called after sometime for the next round.
Round 3 (F2F) : 1.25 hour
In this round, two people were there, both were looking like some senior persons at Amazon.
They discussed only about my project in the current company in detail.They didn’t ask
anything else in this round.
Round 4 (F2F) : 1 hour
Interviewer started with his introduction and asked me for mine.Then he asked me to brief
my company project.
Then he asked two coding questions :

• Ques 1 : A browser is being designed and you have to implement the history feature
in that, which will have two functions, one is to fetch recent 100 urls ( getHistory() ),
and other one to update that recent 100 urls list whenever a url is hit ( updateHistory()
).
• Ques 2 : An array is given and it can be of four types :
(a). increasing
(b). decreasing
(c). first increasing then decreasing
(d). first decreasing then increasing
Without traversing the array we need to tell its type.There was a long discussion on
this question.

Round 5 (F2F) : 1.5 hour


Interview started with the introductions of me and the interviewer.
Then, he scanned my resume and started asking me about the projects I mentioned. Then
he told me to select any of the projects and explain everything from scratch including my
role, number of persons involved in the project and the role of each person. He also asked
me the title of research paper I used to implement the project but I didn’t remember the
title so he asked me name of any one author who was part of the research paper. I told him

802
Chapter 329. Set 323 (Software Development Engineer – Off-Campus)

a name and he searched for the paper on his laptop there only.Discussion on the project was
approx 45 minutes long.
After discussing the project in detail, he gave me a coding question and we discussed that
question also for approx 45 minutes.
Question – There is a number given in the form of a string.Number can be any long.Now I
have to tell just greater number of the given number which is a palindrome also.
Sol : https://www.geeksforgeeks.org/given-a-number-find-next-smallest-palindrome-larger-than-this-number/
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-323-software-development-engineer-off-campus/

803
Chapter 330

Set 324 (For SDE2)

Amazon Interview experience | Set 324 (For SDE2) - GeeksforGeeks


I got a call from an consultant for recruitment drive in Delhi.

1. first round (1 hour 30 minutes): online written


It was online written round on a platform called Stockroom.io
two questions
A) Two string a haystack and needle is given find at what all indexes needle occurs in
haystack as an anagram(0 based indexing)
for eg:
INPUT
ABACDABCABA
BA
OUTPUT
0,15,8,9
time complexity O(n) expected. The only thing to pay attention was that ASCII characters
starts from A
B) Given A company’s hierarchy where each employee reports to exactly one manager. and
one manager can be reported by multiple employees, implement necessary setter getter
functions in object oriented way. also write a helper instance methods to return lowest
common manager for two given employees
answer to this question was simple but had to write object oriented code and zip it then
upload it.
2. second round(1 hour): Design round
this was most critical and important round.
A) Design a geographically partitioned multi-player card game, that supports multiple play-
ers, multiple games at a time.
Each game will have one contractor like ones we have in a bar, He can play a game or just
watch it. integrate payment systems.
first HLD was required, use cases, flow diagram. then a low level design was required all

804
Chapter 330. Set 324 (For SDE2)

necessary classes where will u use polymorphism, where inheritance, multithreading, syn-
chronised approach if needed, socket connections
other things that surfaced and he asked as interview goes : round robin load balancer,
hash-map based load balancer, two layer caching, nosql db, design patterns, solid principles,
ACID property, CAP theorem etc.
interviewer was a senior person and knew a lot. I was nervous in this round but answered
well.
B) many behavioral questions
3. third round (1 hour): technical
A) many behavioral and “what if you were in a situation” questions
B) Given an array of words which comes in a dictionary of some language in the same order.
tell if its possible?
ans. represent characters of words as a graph and find out if graph is cyclic (cycle in directed
graph)
the interviewer was very supportive. He gave me few important hints in terms of question
understanding.
4. fourth round (1 hour): technical
he asked me what you like , I said array questions � He started laughing.
A) given an array of integers and two types of queries point update and range sum?
ans: I said binary indexed tree then he asked for other ways I said segment tree, He asked
more , I said prefix array or sqrt decomposition.
he asked me to write code for the same. made some variations like lazy propagation.
B)topological sorting. given a words of dictionary tell alphabet ordering.
C) many behavioural questions
Hr came and told me that we are done for the day one more interview is there which was
on next day.
Hr was very supportive she gave me some constructive feedback and told me to get prepared
well and come next day as next day was
with a Bar Raiser.
5. fifth round (1 hour): technical+ design + behavioural, Bar Raiser
A) asked tree related questions , how to represent and model a tree.
B) Design a Netflix type system. start from HLD to LLD. detailed discussed happened on
this
discussion on search, video serving, authentication, encryption, dns lookup, which caching
strategy would you chose?
serving multi quality video etc.
C) few behavioural questions.
Few things to remember:
1. for technical go through geekgsforgeeks practice test and interview experiences
2. for design have a look at carreercup
3. review OS concepts.
4. recruiters and hr is very supportive
5. prepare for behavioural questions well.
6. prepare “do you want to ask any questions?”
All Practice Problems for Amazon !

805
Chapter 330. Set 324 (For SDE2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-324-sde2/

806
Chapter 331

Set 325

Amazon Interview experience | Set 325 - GeeksforGeeks


1st Round(Hackerrank)

• Given an array, find largest sum of

1) Contiguous subarray
2) Non Contiguous Subarray

• Largest region of cells problem

2nd Round(Written test)

• Add two numbers represented by linked list


• Get a number, find next greater element with same digits
• Given a sorted array find if a[i]+a[j]=0 (i != j)

3rd Round(ftf)

• Max Sum level in a binary tree


• https://www.geeksforgeeks.org/print-nodes-binary-tree-k-leaves/

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-325/

807
Chapter 332

Set 326 (For Application


Engineer)

Amazon Interview experience | Set 326 (For Application Engineer) - GeeksforGeeks


Requirement was that the candidates should have strong troubleshooting skills, strong knowl-
edge of scripting in any language + Strong coding skills and problem solving skills.
Round 1: Written test (Elimination Round)
There were total 6 questions. 2 coding and 4 scripting questions.
1. Write a function to print the run length encoding of a given string.
Example :
I/P String – wwwwwxxxxddaaaww
O/P String – w5x4d2a3w2
[5 marks]
2. Write a function to print the spiral of a matrix. [5 marks]
3. The file is given as follows containing records of length 10 having mix of numbers,
alphabets and alphanumeric characters.
1234567890
0987654321
ABCDEFGH
123456789X
1234567890
123456789X
Write a script command to print the distinct records containing only alphanumeric charac-
ters.
Expected Output : 123456789X
[2 Marks]
4. Write a script command to rename all .JPG files to .JPEG files in the current directory.
[2 Marks]

808
Chapter 332. Set 326 (For Application Engineer)

5. Write a command to kill a process using process name. [2 Marks]


6. Script command to calculate the total size of all the PDF files in the directory. [2 Marks]

Round 2 : Technical/Problem Solving F2F Interview


The customary – “Tell me about yourself”. �
Then the interviewer asked me whether my code for the run length encoding asked in the
written round will run for all the inputs. I was pretty sure that it would run. He gave me a
case where my code was failing. He told me to modify my code. Also, I had used Hashing
technique for this problem so he asked few questions on HashMap how it works.
1. How will you find whether any permutation of a word would be a Palindrome.
I explained him the logic using Brute force approach with O(mx2^m) time complexity, where
m is the size of the word. He told me to optimize it. I told him the following approach:
We will keep track of the counts of each character in the word. If the length of the word is
even and if all characters appears even number of times, a palindrome can be formed.
Similarly, if the length of the string is odd and all characters but one appear even number
of times then Palindrome can be formed.
Else, in all other cases Palindrome won’t exist in the word. He seemed to be satisfied with
my approach and told me to write the full code.
2. Find all the pairs with a given sum.
3. He gave me a problem to solve. Given two identical ropes of equal length, ,if it takes
60 minutes to burn out the whole rope, how will you measure 45 minutes using these two
ropes. You are provided with only these two ropes and a lighter to ignite.

Round 2: Debugging and Troubleshooting/Scripting


Tell me about yourself.
1. Given the contents of the file as follow:
Company1 400
Company2 500
Company3 600
Company2 150
Company1 350
Write a script command to find the total cost incurred by Company1.
2. Script command to print the sentence in reverse order.
I/P – “You are in Amazon”
O/P – “Amazon in are You”
3. Troubleshooting scenario – If a customer complains that he is not able to sign in to hi
Amazon account, how will you troubleshoot?
She told me to write as many points in the paper as possible. Whatever point I was
mentioning, she was like – “Anything else? Anything else? :P”
She modified the question and asked me if 3-4 customers complains the same that they are
not able to login to their Amazon account, how will you troubleshoot the issue.

809
Chapter 332. Set 326 (For Application Engineer)

Debugging – How will you debug the issue whatever you have troubleshooted.
4. If there is sudden increase in the requests count in the system and you need to answer
to the higher authorities, how will you handle the situation?

Round 4: Troubleshooting/Debugging/Problem Solving/ Managerial


1. Tell me about yourself.
2. Given a file containing some sample text, write a script command to count the number
of occurrences of the word “Amazon”.
3. Given a file containing some sample text, write a script command to change all occurrences
of the word “Amazon” with “It” in the file.
4. Given an array of positive and negative numbers, find the maximum product of the pair
of numbers in the array.
5. He asked me what project am currently working on. I told I was mainly a backend
developer in DB2 as core database. He gave me a query to fetch the 2nd highest value from
the column.
6. Tell me a situation where you were working with your team and the team was stuck with
some issue for which you were digging out the main problem where the issue is arising and
finally you figured out the same.
7. Troubleshooting – A customer is having 2 devices – tablet and android. He is using
Kindle app in the tablet and he has made notes and read till 500th page of a book in the
kindle app. Next day he wishes to read the same book from 501st page, but he observes
that all his notes are lost from 401st-500th page. How will you troubleshoot this issue.
At last, HR called me and told that I am rejected. �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-326-application-engineer/

810
Chapter 333

Set 326 (For SDE II)

Amazon Interview experience | Set 326 (For SDE II) - GeeksforGeeks


1st
1. reverse the linklist in pair manner
Q: 1->2->3->4->5
A: 2->1->4->3->5
2. third highest value in tree
Full code required.
2nd
put the given random pointers in linklist to point to next greater node such that if u
transverse list in using random pointer, list become sorted. duplicates are allowed.
Full code required
3rd
Design a solution to search the given value in system. You are given a value which need to
be searched. The system will respond basis of type.
If its app based it will return app names. if it is web based it will return web pages hitsetc.
A detailed discussion design and development.
No actual coding
4th
Get the local maxima or minima in array.
Bar raiser:
distance between two nodes in binary tree.
Hiring manager 1
Design chess game
Hiring manager 2
Design inventory system. (eg: library)
All Practice Problems for Amazon !

811
Chapter 333. Set 326 (For SDE II)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-326-sde-ii/

812
Chapter 334

Set 327 (Off-Campus for SDE-1)

Amazon Interview experience | Set 327 (Off-Campus for SDE-1) - GeeksforGeeks


I was Invited to attend Interview at amazon Hyderabad for the position of SDE 1 and I had
the following rounds.
Round 0 coding —

1. Given an array find the maximum consecutive and non consecutive sum and
print them.
2. Given a matrix find the number of 1’s in the maximum island MAT[i][j] = {0,1}.
Round 1 Data Structure —

1. Given a tree return the number of elements for the level with the maximum ele-
ments.
PS : all null nodes between two non null nodes need to be counted and null nodes can have
null children which also can be counted.
eg– [null,2,1,null,null,3,null] in this level all nodes between 2 and 3 will be counted i.e. 5
2. Asked about what data structures I knew and what data structure will I use to make a
cache.the answer was Hashing.
3. Asked what data structure would i use for maintaining cricket scores.
the answer was priority queue.
Round 2 Algorithms —

1. Given a binary tree find out if it is a BST


2. Given a binary tree root and a node ,print all nodes at K distance from the node.
3. Given an array it can be of 4 types
(a) Ascending
(b) Descending
(c) Ascending Rotated

813
Chapter 334. Set 327 (Off-Campus for SDE-1)

(d) Descending Rotated


find out which kind of array it is and return the maximum array.
Round 3 Design —

Asked me the word breaking problem which I couldn’t solve and this round didn’t
go well.
Round 4 Managerial —
1. Asked about my current company and work done over there.
2. Asked me a problem to convert Integer to Roman while handling all the corner cases.
3. Asked about process and Threads
4. I asked about the team and kind of work to be done

I would like to thank GeeksforGeeks to provide such a huge variety of problems and a
progressive way to approach any problem.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-327-off-campus-sde-1/

814
Chapter 335

Set 328 (For SDE-1)

Amazon Interview experience | Set 328 (For SDE-1) - GeeksforGeeks


Started with online test at Hackerearth. It had 2 questions.
1. Find subarray with max sum. Array have both -ve and +ve integers.
2. Consider a matrix with rows and columns, where each cell contains either a 0 or a 1 and
any cell containing a 1 is called a filled cell. Two cells are said to be connected if they are
adjacent to each other horizontally, vertically, or diagonally;
If one or more filled cells are also connected, they form a region.
Output the length of the largest region.
Ex: in the following example, there are 2 regions one with length 1 and the other as 6.
00110
10110
01000
00001
https://www.geeksforgeeks.org/find-length-largest-region-boolean-matrix/

1st Round (telephonic)


1. Given a string and integer k, in-place rearrange the string such that last n-k characters
comes before the first k characters.
Ex: abcdef and k=3, so result is : defabc
2. Given a binary tree, sum all the root to leaf nodes and return the sum.

Ex:
1
/ \
2 3
/ \ \
4 6 7

815
Chapter 335. Set 328 (For SDE-1)

here ans: 124 + 126 + 137 = 387

2nd Round
1. Given a large file having strings(for understanding, given an array of strings). Find the
string which repeats the most. Ignore the case.
2. Given the link-list and integer value ‘k’, reverse every k nodes of the list.
Ex. k = 3, list: 1-2-3-4-5-6-7-8
ans: 3-2-1-6-5-4-8-7
3rd Round
1. Questions on my projects.
2. Given a binary tree with each node having parent pointers. Find the LCA of two nodes.
4th Round
1. Given a 2-D grid, number of steps to take, say k and intial position of a Robot. print the
paths possible from initial position after k steps. Robot can move in top, right, left, bottom.
In one path, robot can’t move to the location it has previously visited.
2. Check if a binary tree is balanced. Balance criteria was difference of height between left
and right subtree should be <= 1. 3. Given a binary tree, a node of that tree, and integer
k. Print all the nodes which are at distance k from that node. NOTE: there is no parent
pointer in the node. 5th Round
1. Behavioral Questions. Read front pages(before technical stuff) of Cracking the coding
interview book. Prepare them well.
2. Given a string, count all the palindromes in that string. Only consider substring palin-
dromes.
Thanks to geeksforgeeks for helping me prepare for interviews.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-328-for-sde-1/

816
Chapter 336

Set 329 (Off-Campus for SDE-1)

Amazon Interview experience | Set 329 (Off-Campus for SDE-1) - GeeksforGeeks


I applied off campus for Amazon Bangalore SDE-1. It started with two face to face rounds.
Face-2-Face (Round 1) :

1. A binary tree is given print the binary tree in vertical order.


I gave him a hashmap based approach then he said can you improve it and finally I
came up with space optimized solution using DLL.
https://www.geeksforgeeks.org/print-binary-tree-vertical-order-set-2/

2. He asked do you like DP. I said yes so He asked me a puzzle. There is a stream of
integers and two players are playing. Each player can take one integer from either of
the corners. I need to tell if player A is playing first then what will be his maximum
score. I gave him recursive approach he said its perfectly fine. He asked me to optimize
my solution cause it was exponential finally I gave him a dp approach he was satisfied
and then told me to write full bug free code for the same.

3. N number of identical nodes are given. You need to calculate how many no of binary
trees are possible?

Face-2-Face (Round 2):


He started introducing himself and then asked me some behavioural questions.

1. Tell me about yourself.


2. Your industry experience.
3. Why do you want quit so early?
4. What courses you did?

817
Chapter 336. Set 329 (Off-Campus for SDE-1)

And then he asked me one dynamic programming question.


A matrix is given and each cell has some value. You can enter from any cell of first row
and make three different moves down, south-east and south-west i.e. from (i,j) to (i+1,j+1),
(i+1,j-1),(i+1,j). You need to calculate maximum value when you reach last row.
I gave recursive solution of complexity O(3^n) and then finally gave him dynamic program-
ming solution in O(n^2). He was not done yet then he asked me to print the path as well.
I did.
Both interviews were good so I was waiting for results. After 2 days I got the call you have
cleared both the rounds and they want to conduct two more rounds. Next step was two
more face-2-face rounds.
Face-2-Face (Round 3):
It was a bar raiser round very crucial for the whole process. Interviewer introduced himself
and asked me behavioural questions like:

1. Tell me about yourself.


2. Interests, strengths and weekness.
3. Then he asked me about my final year project which was based on Machine Learning.
He discussed everything in details. After that he asked me about office life and working
culture etc.

I was currently working on Blockchain so he asked me about this technology cause its
totally new and amazing tech so he was pretty impressed. He asked if I have any question
for him. I asked several question related to his work and Amazon visions.

Face-2-Face (Round 4): Hiring manager round


This round was behavioural round and cultural fit. He asked so many questions related to
projects and current work.

1. Why do you want to join Amazon?


2. Why are you quitting?
3. What are your future expectations?

Then he asked me explain current company project and project architecture, my role in
team etc. Guys prepare well for behavioural questions, they look for culture fit.
Coding question:
Print the vertical sum of a binary tree.
https://www.geeksforgeeks.org/vertical-sum-in-binary-tree-set-space-optimized/
Result : I got the call after 3 days and hr said congratulations, you are placed and It was
like dream came true.
Thanks to my parents, Upendra Bhaiya and Prajakta for all the support. I want to thank
geeksforgeeks team, it’s an ideal platform for preparing coding interviews.
All Practice Problems for Amazon !

818
Chapter 336. Set 329 (Off-Campus for SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-329-off-campus-sde-1/

819
Chapter 337

Set 330

Amazon Interview experience | Set 330 - GeeksforGeeks


I recently gave interview for Amazon SDE-I role in Bangalore for AppStore team.
Online Test (Hacker Earth):
1. Given a number N, you have to print “Prime” if its a prime number or “Not Prime” if
its not.
2. Given a string S, print the number of digits and number of english alphabets in it.
eg :…..Input = “a5$&45NdG”
………Output = 3, 4
3. Given a list of words, print them in lexicographical order, given the following priorities.
…..a) If two words have same spelling, lowercase characters take higher priority.
…..b) The words can have spaces in them. A space takes higher priority over any alphabet.
eg : Input = [“funny” , “fun”, “fuNny”]
…..Output = [“fun”, “funny”, “fuNny”]
I could not solve the third question fully. Got partial marks.
Round 1 :
1. Given a large number (can contain upto 10^5 digits), find the number of substrings that
are divisible by 8. A substring cannot start with a 0 except if it is just 0.
ex : Input = 10888 , output = 9 {0, 8, 8, 8, 88, 88, 888, 1088, 10888}
Initially, I gave a brute force O(n^2) solution iterating over all substrings and then came up
with O(n) solution.
2. The question was a bit vague. It ultimately boils down to finding the number of distinct
elements in an array.
I gave the solution using HashMap and he was satisfied.
Round 2:
1. https://www.geeksforgeeks.org/find-number-of-islands/
I gave the solution using dfs and he asked me to implement it. I wrote the solution but did
not keep track of visited cells and my solution was running into an infinite loop. He pointed
it out to me and I corrected it.

820
Chapter 337. Set 330

2. https://www.careercup.com/question?id=5693863291256832
I gave him a solution where I start with empty string and in each step I pick the most
frequent character and add it. I also check if the character I am adding is same as the
previous character. He was satisfied with my approach and did’t ask me to write code. He
said this question is for testing problem solving skill.
3. https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
He asked whether I came across this question and I said no. I gave the solution using bfs
but I used HashMap which was not necessary. He asked me to think on using a simpler
data structure. I struggled a bit but finally came up with set to store elements.
Round 3 (Managerial):
1. Tell me about yourself.
2. Tell me a situation where you had conflict with your manager.
And many more behavioral questions.
3. A DBMS question about Amazon’s product catalogue. I had no clue how to approach
this. She asked if I know any DBMS concepts and I said “No” and told her that I am from
a Non-CS background.
Overall I didn’t feel good about this round and my confidence went low. Luckily, my first
two rounds went well and they decided to give me another chance by taking another coding
interview.
Round 4:
1 http://stackoverflow.com/questions/2473114/how-to-find-sum-of-elements-from-given-index-interval-i-j-in-consta
At first I gave a solution using segment tree (overkill ) . He asked me to think of a simple
solution. And then I remembered the solution where we keep an auxiliary array to store
the cumulative sums. Then the queries can be answered in constant time.
2. https://www.geeksforgeeks.org/find-the-longest-substring-with-k-unique-characters-in-a-given-string/
I already solved this problem previously and I immediately told him the solution using
two-pointers.
Round 5 (Managerial):
1. Tell me about yourself.
2. What was the hardest bug that you have encountered. How did you fix it.
And many more behavioral questions.
3. https://www.careercup.com/question?id=64946
This is an object oriented design question. I practiced these type of questions before going
to the interview from “Cracking the coding interview” book and felt comfortable during the
interview.
Compared to the first managerial round, this went pretty smooth.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-330/

821
Chapter 338

Set 331 (1 Year Experienced for


SE-1)

Amazon Interview experience | Set 331 (1 Year Experienced for SE-1) - GeeksforGeeks
A big big thanks to geeks for geeks for constructing this platform where candidates find
suitable question sets.
1. 1st Round (Coding round on hacker rank) :
Two questions. Each of 100 marks. Total time given was 2 hours.
Question 1: https://www.geeksforgeeks.org/find-length-largest-region-boolean-matrix/
Question 2: https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
2. 2nd Round (Tech) :
Two questions. Here the basic knowledge of data structures and algorithm is tested to
determine whether candidate is eligible for onsite interview rounds or not.
Question 1: https://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-1s-is-maximize
Question 2: https://www.geeksforgeeks.org/a-program-to-check-if-a-binary-tree-is-bst-or-not/
3. 3rd Round (Tech):
Two questions. Knowledge of algorithms and data structure was tested. Along with it,
production level code had to be written on paper and it was to be made sure that no edge
cases remain uncovered.
Question 1: https://www.geeksforgeeks.org/print-nodes-at-k-distance-from-root/
Question 2: https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
4. 4th Round (Tech):
Same checks as present in 3rd round. Since i did not perform well in the 2nd question of
3rd round, more stress on my coding part was given in this round. They were thoroughly
checking my code and pointing all the edge cases if any.
Question 1: https://www.geeksforgeeks.org/clone-linked-list-next-arbit-pointer-set-2/
Question 2: http://stackoverflow.com/questions/6179635/what-is-a-good-data-structure-for-storing-and-searching-2
5. 5th Round (Hiring Manager – Tech & Non Tech):
Checks were same as above rounds. Along with those, whether the candidate was a good
fit at amazon was checked.

822
Chapter 338. Set 331 (1 Year Experienced for SE-1)

Question 1: Given a stream of integers, at any point of time, fetch the count of integers
which are smaller than a given number.

Example :
at time t1:
stream : 1, 4, 3, 2, 6, 7
input : 5
output : 4

at time t2:
stream : 1, 4, 3, 2, 6, 7, 2, 1, 5
input : 8
output : 9

Question 2: HR Questions
– give an instance where your manager and you disagreed.
– give an instance where you outperformed yourself.
– expiain your project and your role in it.
– explain the most difficult project you’ve faced.
6. 6th Round (Bar raiser Tech and Non Tech) :
This guy will thoroughly check everything starting from code, algorithm, data structure,
behavior etc. It is necessary of every candidate to crack this round.
Question 1:
Given the below pattern, write a recursive code for all values of n.

N = 3

- - -

- -

- - -
N = 4

- - - -

- -

823
Chapter 338. Set 331 (1 Year Experienced for SE-1)

- - -

- -

- - - -
N = 5

- - - - -

- -

- - -

- -

- - - -

- -

- - -

- -

- - - - -
N = 6

- - - - - -

824
Chapter 338. Set 331 (1 Year Experienced for SE-1)

- -

- - -

- -

- - - -

- -

- - - - -

- -

- - - -

- -

- - -

- -

- - - - - -

825
Chapter 338. Set 331 (1 Year Experienced for SE-1)

Question 2:

Explain internals of hash map's put method and write code for it.
Question 3: HR Questions

- give an instance where your manager and you disagreed.

- give an instance where you outperformed yourself.

- expiain your project and your role in it.

- explain the most difficult project you've faced.


Practices :

1. Practice code with pen and paper.

2. Cover all edge cases.

3. Take time to code but make sure once done, the code is impeccable.

4. Do practice HR questions seriously.

5. Try to cover as many geeks for geeks amazon interview sets as possible. As you can see my inte

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-331-1-year-experienced-se-1/

826
Chapter 339

Set 332 (Off-Campus)

Amazon Interview experience | Set 332 (Off-Campus) - GeeksforGeeks


Amazon Interview Experience (Off Campus)

Round 1: Online Test


1. Circular tour that visit all petrol pumps.
2. Find a sub-array in an array of 0 and 1 such that flipping bits maximizes no. of 1s.

Round 2: Telephonic Interview 1


1. Mirror Image of binary tree (Recursive Solution Required)
2. Mirror image of binary tree (Iterative Solution Required)
3. Mirror of n-ary tree.
4. Generate all k length combination from n length string, characters can appear multiple
times, print unique combinations only.

Round 3: Telephonic Interview 2


1. Sqrt of an integer till given decimal places. (Expected complexity – logn and only a
single function can be made which has to deal with all the cases)
2. Merge two balanced binary search tree.

Round 4: F2F
1. Isomorphic binary tree check.
2. Count all possible decodings of a string of digit.
3. Given log files consisting of product bought and customer id, print top k purchased
items at any time. If billions of items are there and it is not possible for a single ma-
chine to handle them then how will you handle this condition. Discussed several approaches.

Round 5: F2F
1. Top view of binary tree.
2. Given an expression number of different ways to evaluate the expression.
Exp. 1+2*3, can be evaluated as (1+2)*3 or 1+(2*3)
Later he asked me to find out all the possible answers as well.

827
Chapter 339. Set 332 (Off-Campus)

Round 6: F2F (Technical + hr)


Discussion about project I completed during internship.
Technical Questions asked were –
1. K-th largest element in bst.
2. Array vs Linked list.
Several behavioral questions.

Round 7: F2F
1. Hotel booking problem.
2. Next greater number with same set of digits. O(n) solution was required.
3. Discussion on TRIE.
I would like to thank GeeksForGeeks for providing a variety of questions of all topics.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-332-off-campus/

828
Chapter 340

Set 333 (For Internship)

Amazon Interview experience | Set 333 (For Internship) - GeeksforGeeks


Round 1: Aptitude test
An aptitude test was conducted, comprising of 20 MCQs and 2 coding questions. MCQs
were very easy. MCQs were based on data structures/asymptotic notations/data structure
and quantitative and verbal aptitude.
In coding section there was an easy question which was based on strings and brute force
based. The question was to check if the substring of one given string is an anagram of the
other.

Input: zamo amazon


Output: Yes

Second question was of moderate level in which input is an expression string and you have
to evaluate that given string is valid. If yes return the value of the expression, else return
-1.

Input : 5+7*2
Output : 19

Input : 5++4
Output : -1

I solved one complete and one partial.


Round 2: Technical Interview 1 (around one hour)
After Aptitude they selected 18 candidates and announced that interviews would begin
within next 15 minutes.
Firstly he introduced himself and then asked for my introduction, it was just for creation of
amicable environment. After that I was asked technical questions.
Question 1:
You have been given an alphanumeric string extract maximum numeric value from that

829
Chapter 340. Set 333 (For Internship)

Input: 100klh564abc365bg
Output: 564

Answer: I gave him a o(n) approach, he gave me a few test cases and tried to prove my
logic wrong, for one case I was wrong because I had used int data type so as to rectify the
mistake, I told him that I would be using long int instead. Then I asked him if I can use
string.h library? He said yes sure, then I gave him iotn() approach. Then he told me to
write the code.
Question 2:
You have been given a generator string ab from which any number of strings can be generated
recursively by inserting ‘ab’ at any location. You have been given an input string to check
if that given string is valid or not.(i.e. generated by given with given string.)

eg.
Input: aabbab
Output: valid
Input: abbaab
output: Invalid

Answer:
First I gave him o(n^2) approach then he told that he wanted o(n) approach. After about
5 minutes I gave him o(n) approach involving two pointers. Then again he told me that I
would be traversing the input twice. What if I wanted to achieve it in one pass? Afterwards
I gave him solution using count variable. (It was PDA problem there is also a stack based
solution but I didn’t give that solution because that solution didn’t strike at that time)
Then he asked me,”Do you have any question for me?”
I asked him about job profile,his projects and his experience in Amazon
Round 3: Technical Interview 2(1 Hour)
After one hour of round 1 they told me that I was selected for round 2. Just like round 1
he asked me to introduce myself. Then he started asking technical questions.
Question 1: Delete a node from doubly circular linked list.
Answer: It was easy question, so I asked him about constrains, like if there was any condition
that node can exist or not and data constrain. After listening to constrains I wrote a code
covering all possibilities and hence we checked few test cases manually for that code.
Question 2: He observed that I was little tensed he asked me the reason of my nervousness.
I answered saying, as it is my first interview and I was feeling anxious. He asked me why
why was that so, though few companies had visited campus before Amazon, guessing that
I must have had at least one interview experience.
Answer: I told him that I was not eligible because of low pointer then I told him that why
my CPI was low and how I’m good at coding. �
Then He encouraged me which was very good and positive thing for me(usually interviewer
will do it if you show your positive side). Then he asked few question related to my hobbies
to make my mood fresh.
Coming back to technical stuff …

830
Chapter 340. Set 333 (For Internship)

Question 3: You have been given stock prices for n days and find optimal buy and sell day
i.e. maximize the profit.
Answer : I told him that I have solved similar question in Morgan Stanley Hackathon, Then
I gave him o(n2) approach and told that when I implemented this approach in the contest I
got TLE(time limit exceeded) message hence I had modified it and found a o(nlogn) solution
which got AC(all correct) in contest. Then I explained o(nlogn) solution using STL. He told
me not to use STL and asked me if I can solve this question in o(n)? I replied I shall
try. Then after 10 minutes, with dp approach I successfully solved that question. We then
checked some test cases.
After this question he asked me if I had any questions. Taking reference from first interview
we discussed for around 10 minutes about projects currently going on in amazon and his
experience in amazon.
(I think this question matters a lot because this question reflects your confidence about
selection as well as your interest.)
Couple of days after the interview I received a mail stating I was selected for the internship
hope you will also get a similar mail.
How to prepare for internship?
Quant and Verbal Aptitude:
indiabix.com is more than enough.
You can also use RS Agrawal books.
Technical Aptitude:
Any book of DSA and DBMS you can use.
Data structures made easy is awesome and enough for DSA
You must solve MCQs on quiz.geeksforgeeks.org
Coding Round:
This is totally different from MCQs. You have to write and debug code, so practice is very
important for this round. To study algorithm and data structures’ implementations refer
geeksforgeeks, also try to solve questions on practice.geeksforgeeks.org
For standard algorithms follow codemonk series by hackerearth.
Logic development usually takes more time so try to practice on codechef and hackerank.
Also try to participate in live contest of codechef (every months codechef long challenge).
Technical Interview:
In technical interview you should be aware of commonly known data structures and algo-
rithms. Learn that from geeksforgeeks and implement on codechef. If you are prepared for
coding round then preparing for interview is a cake walk and all you have to be is confident.
To answer the coding questions impressively I would suggest you to go through the career-
cup questions once.
‘Cracking the coding Interview’ is best book for tips of technical interviews. Also if you have
studious friends’ circle, try to conduct mock interviews with friends. (And to be honest,
everyone gets serious once internship procedure starts so you can easily manage that.)
Lastly I would also suggest coding on interviewbit.com if time allows.
Few Tips(Specially for SY’s reading this) :
try to Keep your CPI above 8 else you will miss some opportunities. And another thing
CPI matters only for qualification after that CPI is just a number nothing else . So TY’s
reading this if you don’t have decent CPI then tie your shoes for coding (MY CPI was just
7.8).

831
Chapter 340. Set 333 (For Internship)

Try to code on codechef and hackerank and try to participate in live contest.
Wish you all the best! �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-333-internship/

832
Chapter 341

Set 334 (For 4.5 Years


Experienced)

Amazon Interview experience | Set 334 (For 4.5 Years Experienced) - GeeksforGeeks
Round 1:
– Given binary tree. Find level with maximum sum
– List of modules with Dependencies given. Order the execution of modules (Topological
sort)
Round 2:
– Questions on Projects, Managerial questions
– Design Chess game. After basic design, complicated things by adding various functionali-
ties
Round 3:
– Deep design level discussion on one project that I have worked on
– Design cricinfo live score page
Round 4:
– Clone a binary tree which has random pointer as well
– Design Cache library
Round 5:
– Minimize cash flow among set of friends.
– Questions on Projects, Managerial questions
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-334-4-5-years-experienced/

833
Chapter 342

Set 335

Amazon Interview experience | Set 335 - GeeksforGeeks


First Round : 10 Mins – Introduction of the team , myself , Behavioral questions . Next
45 mins – write a findMatch method for online game where two players are set to play game.
If player X comes online then he needs to be matched with player whose existing rank is
closest possible to that of Player X. This had to be efficient algorithm and scale to millions
of users
Second Round :Given different time periods during which tasks were running find the
time at which maximum tasks are running.
Third Round : Given a String find out if it contains ONLY all strings from another string.
Input : str – FeeO & another String – { “Fe”, “e”, “O”}
Hint : Use DFS to solve this
Fourth Round: Design Amazon address manager app
Fifth round: Behavioral questions only.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-335/

834
Chapter 343

Set 336

Amazon Interview experience | Set 336 - GeeksforGeeks


Round 1 – HackerEarth 2 questions (Online)
1) Find the distance between 2 nodes in a BST(Binary Search Tree)
2) Given a graph, find the Topological Sort.
Round 2 – Team Lead (F2F)
system design to show the list of suggestion when a user is buying and item. Example: the
user will buy a pencil and will see a list of other pencils, pens and erases.
Behavioural questions,.
Round 3 – Senior or principal engineer(F2F)
Almost same behavioural questions : Most challenging project, tell me one time where you
did something without everyone knowing because you thought you could make it better,
time you disagreed with your manager, hardest bug.
Given a log file containing {timestamp,begin/end,requestId} (the begin/end is a flag to
identify when a request started and finished) define the peak of transaction running concur-
rently.
Round 4 – Manager (F2F)
Lots of behavioural and prior project questions(almost the same again)
Given an array, shuffle it(Sort it random).
Round 5 – Bar Raiser(F2F)
Questions about decisions I made in prior project(lots of whys)
Given a set o coordinates( double X and y) and an angle. Calculate the max of points that
could fit inside the angle.
Approach: calculate the angle for each point this way we can have a simple list of angles
and then iterate through them to see if the difference is equal or lower to the given angle
and then count the max points group
All Practice Problems for Amazon !

835
Chapter 343. Set 336

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-336/

836
Chapter 344

Set 337 (For SDE-1)

Amazon Interview Experience | Set 337 (For SDE-1) - GeeksforGeeks


Amazon Banglore/Chennai Interview for SDE 1 role
Round 1 – Pen Paper Test
1) Root to leaf path sum equal to a given number, number can be positive or negative
2) Reverse a Linked List in groups of given size
Round 2
1) Two nodes of a BST are swapped, correct the BST
2) Given two (binary) trees, return the first pair of non-matching leaves
Round 3
1) Print distinct elements in every window of size k
2) Diagonal Traversal of Binary Tree
Round 4
1) Design Pizza Class, mostly OOPs concepts.
2) Print top 500 words in a dictionary on the basis of frequency
Round 5 – Hiring Manager Round
1) Behavioural questions: Why to leave present company, Anything you want to change in
yourself
2) How files are stored in memory? Is it compulsory to save each character in 8-bit? Can
we have a variable length of bit representation? Why ASCII has 8 bit only?
For variable length I have said the Huffman Coding.
Round 6 – Bar Raiser Round
1) Behavioural questions : Anything that you have suggested apart from work, an instance
where you have an argument with your manager, biggest accomplishment, biggest failure,
anything that you have implemented apart from your day-to-day work.
2) What is semaphore?
3) What is design pattern? Explain Factory Design Pattern.
4) Length of the longest substring without repeating characters
All Practice Problems for Amazon !

837
Chapter 344. Set 337 (For SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-337-sde-1/

838
Chapter 345

Set 338 (1st Round for SDE-1


in Delhi)

Amazon Interview Experience | Set 338 (1st Round for SDE-1 in Delhi) - GeeksforGeeks
1st Round – Pen and Paper
Q1: http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
Q2: http://www.geeksforgeeks.org/print-possible-strings-can-made-placing-spaces/
O3: http://www.geeksforgeeks.org/sum-of-two-linked-lists/

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-338-1st-round-sde-1/

839
Chapter 346

Set 339 (For SDE 2)

Amazon Interview Experience | Set 339 (For SDE 2) - GeeksforGeeks


Round -1 (Written Round) Pen and Paper
1) Level order Traversal in spiral form.
2) Design deck of cards with joker (53 cards).
3) 1 array question need to do in O(n).

Round -2 F2F
1) About previous projects and role.
2) In- place rotation of 2D Array by 90 degree clockwise.
3) About Amazon- what are the different projects in amazon.

Round-3 F2F
1) Find sum of all elements in a matrix except the elements in row and/or column of given
cell?
2) Print top view of tree without hashing.
Round-4 F2F Design round
1) If N-files are given containing sorted number list and files are adding at run time. design
a program if 1 st time run then gives min number , 2nd time run give 2nd min number ,
3rd time gives 3rd min number and so on
write a program
Round-5 Design and Coding
1) Design Book My show.
2) 1 problem of their project which will be solved by using map and list.
3) Your Role in previous company, design of your project, flaw in your design and improve-
ments , your strength and improvement area
All Practice Problems for Amazon !

840
Chapter 346. Set 339 (For SDE 2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-339-sde-2/

841
Chapter 347

Set 340 (3.5 years experienced


for SDE 1)

Amazon Interview Experience | Set 340 (3.5 years experienced for SDE 1) - GeeksforGeeks
Recently I have gone through interview with Amazon Chennai for Amazon FIRE TV team.
Here is my positive experience.
Round 1(written):
1. https://www.geeksforgeeks.org/run-length-encoding/
2. https://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/
3. https://www.geeksforgeeks.org/count-substrings-with-same-first-and-last-characters/
Round 2:
1. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2. It’s a two player game. Both the players are equally intelligent to win the game. Give n
no. of stones. A player can choose either 1 stone or k stones or l stone (1<k<l). Suppose
player ’A’ starts game then challenge was to identify the player who will win the game.
Player who picks the last 1 stone or last k stone or last l stones win the game.
Round 3:
1. https://www.geeksforgeeks.org/counting-inversions/
2. https://www.geeksforgeeks.org/print-matrix-diagonal-pattern/
3. http://algorithms.tutorialhorizon.com/dynamic-programming-minimum-cost-path-problem/
Round 4 (Bar Raiser)
1. Detailed discussion on current company project.
2. https://www.geeksforgeeks.org/find-maximum-path-sum-in-a-binary-tree/
Round 5 (Hiring Manager)
1. Design ATM machine.
2. Design a queue using only one stack.
3. Discussion on process & threads, Inter process communication, Lots of discussion on
scheduling algorithm, their implementations, data structures used to implement scheduling
algorithms, scheduling algorithms in real time distributed systems & implementation.
4. Lots of behavioral questions like why amazon, why you are leaving current company.

842
Chapter 347. Set 340 (3.5 years experienced for SDE 1)

Finally got positive response from amazon with decent package.


Thanks GFG for this wonderful site.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-340-3-5-years-experienced-sde-1/

843
Chapter 348

Set 341 (Off-Campus for SDE-1)

Amazon Interview Experience | Set 341 (Off-Campus for SDE-1) - GeeksforGeeks


I had applied to Amazon Hyderbad off campus for SDE-1 role. The first round a telephonic
round. It was a technical round. The questions asked were.
First Round –
1. Reverse words in a given string. I was also asked to handle whitespaces correctly. https:
//www.geeksforgeeks.org/reverse-words-in-a-given-string/
2. Add two numbers represented by linked list. I was asked to solve it without changing the
linked list order.https://www.geeksforgeeks.org/sum-of-two-linked-lists/
Second round –
1. It was an array question which I don’t remember exactly �
2. Print all the nodes that are common for 2 given nodes in a binary tree.
For this I first found the LCA and then printed all the ancestors of LCA.
In this round I was also asked about heap, applications of BST etc.
Then I had a call where I got to know that I was selected. I was called to Hyderabad for
Face to face rounds.
Third round –
The interviewer was very friendly and made me comfortable.
Then he reads my resume very carefully and says its good. He then asked me to discuss any
of my projects in detail.
He also asked one coding question as follows
Add 1 to number represented by linked list without using extra space (no recursion), without
modifying the linked list and in O(n) time complexity.
Interviewer was very friendly and discussed the problem deeply and helped me in reaching
to the solution.
He then asked me to write full production level code covering all corner cases.
Fourth round –
The interviewer was a manager. He asked me details about my work in current company.
Then he asked me coding question as follows

844
Chapter 348. Set 341 (Off-Campus for SDE-1)

1. Find smallest range containing elements from k lists


https://www.geeksforgeeks.org/find-smallest-range-containing-elements-from-k-lists/
2. How to find if words in a file are anagram.
I suggest a Trie approach and he seemed to be satisfied and asked to me just to write how
to implement trie data structure and its applications.
He also asked me some questions like
1. Why do I want to leave my company so early?
2. Why amazon?
Fifth round –
It was purely coding round where 2 persons asked me 2 coding questions.
1. First question was truely mathematics question which had equations and that need to
be solved and finally it was reduced to finding max and 2nd max in an array.
2. Union find problem
In above question I was asked details about disjoint datastructure and other questions to
find the number of nodes etc.
Sixth round –
Interviewer was very friendly and asked me details about me and my work
He then asked me a coding question
1. Minimum number of swaps required for arranging pairs adjacent to each other.
https://www.geeksforgeeks.org/minimum-number-of-swaps-required-for-arranging-pairs-adjacent-to-each-other/
2. It was a data structure question where I had to find the best data structure. There was
a bank account which had information like TTL, amount and time of insertion. TTL is the
time when the account gets expired.
I suggest a hashmap solution and then he had a deep discussion on the question.
He also asked me some theory questions like “what happens when I hit amazon.com in the
browser”, “How does garbage collection works in java” and some more questions on OS and
unix.
For every coding question I was asked time and space complexity.
Thank you geeksforgeeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-341-off-campus-sde-1/

845
Chapter 349

Set 342 (Off-Campus for SDE-1)

Amazon Interview Experience | Set 342 (Off-Campus for SDE-1) - GeeksforGeeks


Round 1: (Written – Pen & Paper)
Q1. http://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/
Q2. http://www.geeksforgeeks.org/remove-minimum-number-characters-two-strings-
become-anagram/
Round 2: Face to Face
Interviewer was expecting full production level code with optimum time/space complexity.
Q1. Find an element in an unsorted array such that all left elements are smaller and all
right elements are greater. O(n) time complexity solution is required.
Q2. Find kth smallest element in row wise column wise sorted matrix.
Round 3: Face to Face
Interviewer was first expecting to explain clear algorithm and then production level code.
Q1. http://www.geeksforgeeks.org/find-number-of-islands/
Q2. http://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array-set-3-worst-
case-linear-time/
Round 4: Hiring Manager Round
Q1. Discussed thoroughly about my company project. My contribution in project.
Q2. http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
Q3. Why Amazon. Why Chennai.
Hoping for call for Bar Raiser round.

All Practice Problems for Amazon !


Element with left side smaller and right side greater

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-342-off-campus-sde-1/

846
Chapter 350

Set 343 (For SDE-1)

Amazon Interview Experience | Set 343 (For SDE-1) - GeeksforGeeks


Round 1 : Written Round
Question 1 : Given an array of number in sorted order count the pair of number whose sum
is less than X.
Question 2 : Given an range of number count the numbers which has same first and last
digits. For e.g. start =7 and End =95 so the numbers are 7,8,9,11,22,33,44,55,66,77,88
Question 3 Suppose there are millions of number and you have to print max 20 elements.
Round 2 : Face to Face
Question 1 : Suppose there are n bags containing different amount of chocolates and there is
wizard and a kid.At every second a kid eat all the chocolates from bag containing maximum
number of chocolates and wizard refills it with the half the chocolates it was containing.
Find how many chocolates does the kid has eaten at t seconds.
Question 2 : Reverse the word in the string for e.g. “My name is khan” to “Khan is name
My”.
Question 3 : Add two singly linked list.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-343-sde-1/

847
Chapter 351

Set 344 (For SDE-1)

Amazon Interview Experience | Set 344 (For SDE-1) - GeeksforGeeks


Round 1: online Test (Hackerearth) 30mins
Given a log file calculate the no of people who came on multiple days. A person can come
on for multiple times in a day.
On Wednesday I got the call for the onsite round to be happening on Saturday.
Round 2 : Onsite round(1 hour)
The interview started with my introduction, asked questions about my profile what was I
doing(5 min discussion).
After that she gave a programming question, There is voting happening in a college to select
an amendment, total 16 professor and there are 4 groups each group consists of 4 prof and
for an amendment to be selected it should be, first selected atleast by a single professor in
each group and finally select the one which appears maximum times.
I gave a solution and then we discussed my solution and asked me to optimise it further
with o(1) memory and o(n) complexity.
Then there were some behavioural questions about working in a team and problems I had
faced with a new team.
https://www.geeksforgeeks.org/diameter-of-a-binary-tree/
Round 3: onsite(1 hour)
Started with my profile and me to explain my projects I had been doing in my current
company
https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
https://www.geeksforgeeks.org/stock-buy-sell/
Round 4 : HM round onsite(1.5 hour)
He started with my profile and one by one we discussed all my projects in details asked me
various questions about them followed by many behavioural questions.
https://www.geeksforgeeks.org/print-common-nodes-in-two-binary-search-trees/
Asked me to write a full fledge code like u write in a project with comments and everything.

848
Chapter 351. Set 344 (For SDE-1)

Round 5: another HM round (skype)(45 mins)


Started with my profile and detailed discussions about my current project, my role in that
project, technologies I have used followed by various behavioural question.
https://www.geeksforgeeks.org/implement-a-phone-directory/
Asked me write the three functions insert, search and suggestions.
Thanks to GeeksforGeeks for helping me out.

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-344-sde-1/

849
Chapter 352

Set 345 (For SDE-1)

Amazon Interview Experience | Set 345 (For SDE-1) - GeeksforGeeks


Round 1: Onsite, Design
– Design an online file repository system
– What are the use cases
– Features
– Security
– HLD
– LLD

Round 2: Onsite, Algo


– Detailed discussion on projects. My contributions to project.
– nth Fibonacci number in O(n)
– Data Structure with O(1) time for:
get(key) :value
set(key, value)
delete(key)
getRandom() :key

Round 3: Onsite, Algo


– Merge two balanced binary search trees into one balanced binary search tree.
– Given an array of 0 and 1, in how many iterations the whole array be filled with 1s if in a
single iteration immediate neighbor of 1 can be filled.
– Given a binary matrix, fill the row and column of any cell containing 1 with 1’s in O(n^2)
time without extra space

Round 4: Telephonic, Hiring Manager


– Detailed discussion on projects.
– Interviewer was trying to find a fit with amazon leadership principles(https://www.amazon.jobs/principles)
with several behavioral questions.
– What was the most challenging project.

850
Chapter 352. Set 345 (For SDE-1)

– What did you do in case of immediate deadline.


– What did you do in case of disagreement with your manager.

Round 5: Telephonic, Bar raiser


– Very detailed discussion on my projects
– Give an example in your work where you exceeded expectations
– Design an analytics system
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-345-sde-1/

851
Chapter 353

Set 346 (For SDE-1)

Amazon Interview Experience | Set 346 (For SDE-1) - GeeksforGeeks


1st Round :
1) Check if tree is a binary tree or binary search tree or not (https://www.geeksforgeeks.
org/a-program-to-check-if-a-binary-tree-is-bst-or-not/)
2) Write a program to output power(m,n)
3) Given an infinitely long sorted array having -1’s at the end search a value in that array
4) Provide the complexities for the above questions.
After 20 minutes 2 guys entered my cabin and straight forwardly they started technical
stuff.They started with my projects,I told that I am working in support project
2nd Round
1) Design a musical juke box with functions
1) add song
2) delete song
3) top 10 played song at any point of time
We had a lot of discussion about this around 40 minutes using different data structures like
hashmap, heap.
2) Longest consecutive path in a binary tree (https://www.geeksforgeeks.org/longest-consecutive-sequence-binary-tre
I told my approach but they didn’t got that then I wrote recursive code and explained.
3)Find the sum of all left leaves in a binary tree (https://www.geeksforgeeks.org/
find-sum-left-leaves-given-binary-tree/)
Initially I told level order traversal approach.They asked me to code.They seems satisfied
but again come up with a question to optimize the space.Told the approach using post
order traversal
3rd Round :
This guy is very friendly.
1) Merge two sorted linked list into one without any extra space
2) Given a binary tree along with a value. The question is to find the mirror of that node,the
value always exist in the binary tree

852
Chapter 353. Set 346 (For SDE-1)

for this tree mirror of 2 is 4 and for 1 mirror is NULL.


3) Given a array with n songs,we have to play all the songs only once.Given only 2 functions
1)playsong(songid)
2)getRandom(n) – return the random values in between 1 to n
Told hashmap approach he told if the getRandom() give the same values million of time
then its sucks.So I modified my approach and he was impressed.
4th Round :
This round was with SDM of another team
1) Segregate even and odd number in the list with out using extra space
2) A kind of design question. Given amazon log files of two days.He asked me to find the
users who logged in both the days. Had discussion using Hashmap,he want to optimise
further I gave solution using trie with little modification in its structure

struct Trie {
int count[2],
bool isleaf;
Trie *child[26];
Trie() {
count[0]=count[1]=0;
isleaf = false;
for(int i=0;i < 26;i++)
child[i]=NULL;
}
};

He appreciated me and left.


5th Round (Bar Raiser)
1) Had discussion about my projects and its extensions.He gave some advise
2) Serialize and deserialize a binary tree
I told the approach using two traversals inorder and preorders.He asked me to code directly
then I explained him but he didn’t got my approach and he continuosly used to ask many
questions .Finally I told using one preorder traversal with markers he told that he know
that solution.
After this round he asked me to leave for the day.

853
Chapter 353. Set 346 (For SDE-1)

I would like to thank my friends and geeksforgeeks who are always with me helping all the
time,
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-346-sde-1/

854
Chapter 354

Set 347 (1.8 Years Experienced


for SDE1)

Amazon Interview Experience | Set 347 (1.8 Years Experienced for SDE1) - GeeksforGeeks
Below is the summary of interview round conducted by amazon. Although i am not able to
remember correctly since its almost 2 months.
1) Written Test
Check if Linked list contains loop.
Create Balanced binary search tree from sorted array
2) F2F (Technical)
Stream of coordinates are given. you need to identify k nearest points for given coordinate
at any point of time
3) F2F (Hiring manager)
Discussion about project
Project which has business impact
Conflict with manager/seniors
4) F2F (Technical)
Given dictionary of alien language. You need to find order of alphabets based on dictionary
– Topological sorting
DS for identifying min from given array for index range x to y.
5) Telephonic (SDM)
Detail discussion about projects
Project which made you rockstar
What you prefer to use for communication between android and backend server –
XML/JSON ? why ?
6) Telephonic (Bar raiser)
Discussion about projects
Conflicts with manager/team
Your role in projects

855
Chapter 354. Set 347 (1.8 Years Experienced for SDE1)

Given array of characters. Identify string with minimum length which covers all characters
present in the string
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-347-1-8-years-experienced-sde1/

856
Chapter 355

Set 348 (For SDE II)

Amazon Interview Experience | Set 348 (For SDE II) - GeeksforGeeks


Recently, I was interviewed by Value Added Services team for SDE II position at Amazon
Hyderabad campus.
Telephonic Round: 1:15 Hours
1) Given a set of words, print anagrams
2) Questions about sorting algorithms.
i) What sorting algorithm should be used for sorting strings?
ii) When merge sort is preferred over quick sort?
3) This question is based on Topological sorting. Question was framed over working of
Maven/Gradle. Given the dependencies of the packages to be installed.
For example,
A -> B, C, D (Which means A depends upon B, C & D. Hence, B,C & D should be installed
before installing A)
B -> F
D -> E
Print the order in which packages should be installed.
Later this question is modified and asked:
Given an order of packages, tell whether with the given dependencies, is it possible to install
packages in the given order or not.
Round 2: (Face to Face) 1:20 Hours
Each of the f2f interviews were taken by the two interviewers. One was asking questions
and other was observing the behavior of the candidate �
This round almost covered everything from Current Project to Data Structures and Problem
solving to Behavioral questions to High level designing.
Asked the architecture of the product that I am currently working on. Asked me to draw
the block diagram and the interactions among the different components for 20mins.
Later moved to Data Structures and Problem solving questions.
1) Given an array find the maximum contiguous sum. Array can have +ve and -ve elements.
2) Sum of two linked lists and store the result in the third one.
Behavioral Questions:

857
Chapter 355. Set 348 (For SDE II)

1) How did you help your colleague?


2) Tell an instance when you proposed some approach but your team lead did not like and
how did you convince him.
Design question: Design BookMyShow website. Asked me, how will I design UI pages?
What things I did not like about BookMyShow? And then designing of DB, tables, con-
straints, etc.
I nailed this round completely.
Round 3: (Face to Face) 1:30 Hours
Asked about my current project.
This round of mine did not go well. It was a purely about Data Structures.
1) Given a binary tree, find the maximum BST subtree with the root of the max BST.
I gave initial approach where I wanted to traverse the tree in Inorder and store it in an
array.
After that find the subarray where elements present in increasing order. Interviewer showed
some issues with that approach.
Later modified the approach to bottom-up approach. Approach was fine but I could not
write clear and running code.
2) Interviewer was confused whether to send me to the next round or not. He asked me one
more question:
Given an sorted array of alphabets find the count of each element. Told him the approach
with Binary search and he was satisfied.
Round 4: (Face to Face) 1:30 Hours
Asked about my current project.
This round was totally on designing.
1) Given a piece of paper with some Java code. I need to review the code and provide the
comments as a reviewer.
2) Design survey monkey like website.
More emphasis was on Admin related activities of creating/editing a survey, showing all the
surveys created by the admin user.
Generate a unique link to each of the survey created by the admin.
Started from UI pages designing to what information should be sent through Ajax calls to
server for each of CRUD operations on survey.
Structure of each table to store the survey information. How will I as a developer create a
layered architecture at server side.
Layered architecture: Ajax -> Servlet -> Class for CRUD operations on surveys –> Trans-
action Handler –> Persistence layer
This round was very satisfying round and everything happened properly.
Round 5: (Face to Face) 1:00 Hour
This round was taken by the manager of Value Added service team.
He was very friendly and gave his own introduction.
Asked about my current project.
1) Given an array of alphabets and a dictionary of english words.
I need to find the maximum possible valid dictionary word can be formed from these alpha-
bets.
I went through Trie approach of storing the dictionary words.

858
Chapter 355. Set 348 (For SDE II)

2) Design Outlook meeting request handler, a low level design question.


I gave some solution and he seemed to be satisfied.
3) Behavioral Question: Tell some instance, when you proposed some idea and it was rejected
by your Product Manager.
Reason for the rejection of the idea.
For SDEII, more than Data Structure and Problem solving, Amazon looks for designing
and approach.
All the interviewers were very friendly and they help during the interview process.
Always try to understand what interviewer is looking for from the given question. If it is
not clear, ask them clearly with no heistation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-348-sde-ii/

859
Chapter 356

Set 349 (For SDE I)

Amazon Interview Experience | Set 349 (For SDE I) - GeeksforGeeks


Telephonic Round:
1. Given a 2D matrix with elements 1 and 0, where 1 is land and 0 is water. Find the
number of islands. ( https://www.geeksforgeeks.org/find-number-of-islands/ )
2. Design a data structure which supports operations: insert, delete, find and findAny in
constant time.
FACE TO FACE
Round 1:
1. Given an array which can be either of the following:
Non-decreasing
Non-increasing
Increasing then decreasing
Decreasing then increasing
2. Find the pivot element. ( https://www.geeksforgeeks.org/type-array-maximum-element/
)
3. Find the first non-repeating character in a stream of integers
4. Explain the situation where you had tight deadlines. What did you do to meet the
deadline?
Explain the situation where excess of work and you knew you could not meet the deadline.
How did you manage then?
Round 2:
1. Print tree in a vertical order ( https://www.geeksforgeeks.org/print-binary-tree-vertical-order-set-2/
)
2. Minimum no of jumps to reach the end of array ( https://www.geeksforgeeks.org/
minimum-number-of-jumps-to-reach-end-of-a-given-array/ )
3. Given rods with different costs, combine the rods in a way such that you get the minimum
cost.
3. When do we use which sort? Example of cases when merge sort is not used.

860
Chapter 356. Set 349 (For SDE I)

4. Explain heapify function of heap sort. Then explain with code what happens when you
remove one element(max/min) from the heap.
5. Have you ever faced the situation when you did not meet the deadlines, but you thought
you were good enough and were on the right track?
7. Have you ever faced the situation when you had to struggle to meet the deadlines? How
did you divide/make progress with the work?
Round 3 (Hiring Manager):
1. Zigzag print of a binary tree (https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
)
2. Rearrange a string such that no two same characters are adjacent to each other ( https:
//www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/ )
3. Client calls server but gets delayed response. What could be multiple reasons? How
could you improve upon them?
Round 4 (Hiring Manager):
1. Can you explain the situation where you have pushed/written your code and your manager
didn’t approve of it, but you thought you had written the right code? What did you do
then?
2. Have you been in a situation where you convinced your manager for something?
3. There is a call/request which takes some extra time in replying. Why could it possibly
be? How do you remove that?
4. Explain caching. What happens when cache is full? Implement LRU cache. Write the
code. ( https://www.geeksforgeeks.org/implement-lru-cache/ )
5. How do you manage work with strict deadlines? If ever you faced such situations.
6. What aspects do you have in your mind when you want to join amazon? What are your
expectations out of it?
7. If you are given some work, how do define and manage it.
8. What will be your course of action if you are assigned some task which you don’t know
at all?
Bar Raiser Round:
1. Given an array of integers, replace every number with the next higher number to its right.
If a number can’t be replaced, we leave it as-it is.
For example, the list: 5, 2, 1, 4, 6, 7 needs to be changed to 6, 4, 4, 6, 7, 7.
4 different approaches were discussed and codes were to be written.
2. Why do you want to switch?
3. Why amazon?
4. Questions about current company, current project, team size, your roles and responsibil-
ities, etc. were asked in almost all the rounds.
All Practice Problems for Amazon !

861
Chapter 356. Set 349 (For SDE I)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-349-sde/

862
Chapter 357

Set 350 (For SDE I)

Amazon Interview Experience | Set 350 (For SDE I) - GeeksforGeeks


Round 1 ( Coding Round + MCQs ):
Platform : Hackerearth
Question 1 : http://www.geeksforgeeks.org/maximize-number-0s-flipping-subarray/
Question 2 : http://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations/
The test cases were very weak and any brute force solution got accepted.
20 MCQs based on OS, DBMS. The questions were very similar to those present on Geek-
squiz.
Round 2 ( Telephonic Interview 1, duration – 1 hour) :
Question 1 : http://www.geeksforgeeks.org/find-smallest-range-containing-elements-from-k-
lists/
Question 2 : Delete operation on a BST.
Round 3 ( Telephonic Interview 2, duration – 35 mins ) :
Question 1 : http://www.geeksforgeeks.org/adding-two-polynomials-using-linked-list/
Question 2 : https://www.geeksforgeeks.org/inorder-successor-in-binary-search-tree/
After this round I was invited for onsite interviews at Amazon Bangalore Office.
Round 4 : ( F2F , duration – 45 mins )
Question 1 : http://www.geeksforgeeks.org/sort-array-according-order-defined-another-
array/
This question can be easily solved using a custom compare function combined with merge
sort, I figured this out later on . I had proposed a different solution based on 2 hashmaps.
Time complexity was O( n log n ). My approach was a little complex and lengthy, so the
interviewer did not ask me to code this.
Question 2 : Reverse a linked list.

863
Chapter 357. Set 350 (For SDE I)

He asked me to dry run my code and checked all corner cases.


Round 5 : ( F2F, duration – 1 hour, 2 interviewers )
Question 1 : Design LRU Cache.
I designed it using unordered_map and doubly linked list. I coded my own DLL class. After
that they framed different test cases and asked me to explain how my code was handling
those cases.
They asked some questions about how hashmap is implemented.
Question 2 : You are given a string and 2 operators ( & , | ). Return the total number of
ways in which you can evaluate to true using the given string and operator set.
Example : Input : TF
Output : 1
Input : TFF
Output : 2 ( T | F & F , T | F | F )
I solved it using parenthesization and memoization. Time Complexity – O ( n3 ).
I used a 3-D array to memoize.
dp[i][j][0] : Number of ways to form 0 using substring( i, j )
dp[i][j][1] : Number of ways to form 1 using substring( i, j )
Interviewer stressed to use only a single 2-D array so I had to include the following precom-
putation to calculate the total number of ways to parenthesize a string of length n, lets say
F( n ).
F( n ) = 1 + summation ( F( i ) * F ( n – i ) ) i varies from 1 to n-1 .
Round 6 ( F2F, duration – 45 mins )
Interviewer warned me to inform him in case I had already encountered any of these ques-
tions.
Question 1 : https://www.geeksforgeeks.org/minimum-steps-to-reach-a-destination/
I told him that I had already solved this question using BFS. He asked me to explain the
approach, but did not ask to code.
Question 2 : http://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-
given-array/
He was expecting an O ( n ) solution. I solved it using 2 pointer approach. He asked me to
dry run my code and handle cases when array values are negative or zero.
Question 3 : http://www.geeksforgeeks.org/maximum-sum-linked-list-two-sorted-linked-
lists-common-nodes/
I told him that this is a classical problem and I have solved it earlier. Told him the approach
and handled all corner cases.
Round 7 ( F2F, 2 interviewers, duration – 30 mins ):
Detailed discussion about my project. Some random questions about the technologies I had
used.
Question 1 : https://www.geeksforgeeks.org/remove-all-nodes-which-lie-on-a-path-having-sum-less-than-k/
All Practice Problems for Amazon !

864
Chapter 357. Set 350 (For SDE I)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-350-sde/

865
Chapter 358

Set 351 (Off Campus – For SDE


I)

Amazon Interview Experience | Set 351 (Off Campus - For SDE I) - GeeksforGeeks
I attended the referral drive in Delhi, so we had to report to 10:00 AM at Amazon’s office.
ROUND 1: Written – Pen & Paper (11:00 – 12:00 PM)
You have to write a short description first of your approach, put comments if necessary to
explain that line’s logic. Full Optimize Code should be written covering all the edge cases.
Also mention the complexities.
Q1. Sorted Array to Balanced BST.
Q2. Detect and Remove loop in linked list.
ROUND 2: Face to Face (02:00 – 03:30 PM)
This was the Technical Round, start with your basic approach and then move further to
optimized ones. Interviewer will expect you to write fully fledged code (the optimized
approach one) covering all the edge cases and also derive it’s complexities. If he’s not
satisfied with any of the space and time complexities he will urge you to provide him that
solution, and this happens a lot in Amazon’s interviews.
Q1. Given a number N, you can do three operations like (N-1, N/2, N/3) find the minimum
number of steps in which N can be reduced to 1 using these three operations.
Minimum Steps to reach 1.
First gave him recursive approach, gave him space time complexities. Then told him dp one
and it’s space time. Then he told me to code the dp approach.
Q2. Max Sum Path across two sorted arrays.
Gave him the solution using space O(m+n) and time O(m+n), wrote the code for it. Then
he demands to solve it in O(1) space and O(m+n) time, spend some time and coded it too.
ROUND 3: Face to Face (05:00 – 06:30 PM)
Again Technical Round, this round was more DS specific, we have to write fully optimized
code which will cover all test cases.

866
Chapter 358. Set 351 (Off Campus – For SDE I)

Q1. Width of a Binary Tree


Gave him many approaches, had discussions on Level Order traversals as well. At the end
wrote the code for it.
Q2. Print Vertical Order Traversal
Told him the approach using Maps of STL but for that i had to sort it for displaying in
the correct order, which would take extra time complexity, so came up with the solution of
adding the results direct to array without using Hashmaps. (as the HDs are consecutive -2,
-1, 0, 1, 2 so you can also take array and manipulate some insertions there).
Round 4: Hiring Manager Round (07:30 – 09:00 PM)
Q1. Started with a technical question : Kth largest element in a stream of integers.
Have to wrote the code using Heap along with all the util functions of Heaps as well.
Q2. Tell me something about yourself, about your company, what kind of projects did you
do, what extraordinary did you do, Was there any kind of appreciation received in your
current company.
Q3. Told me about the work his team is doing, asks me some behavioral questions like, Was
there any kind of conflict between you and your manager at some point of time, how did
you resolve that ? What would you do if the deadline marked by you to complete a task
has been passed ?
After 1 week…
ROUND 5: Hiring Manager Round (Telephonic : 1 hr)
Started asking about myself and getting to know me by asking deeper about my background.
This round was “dive deep” anything you utter from your mouth he will drill into it.
Q1. Technical Question : Have you studied Data Compression. What are it’s various
techniques. I listed Huffman and Run Length.
1.a) He told me to code Run Length.
1.b) Then told me to do an in-place Run Length encoding given a string of chars.
It fails some cases where the original string as many unique characters so that the string
length would increase and thus cannot be converted in-place. I told him so and suggested i
would take a vector in case of any additions is to be made. He then asks for these strings
where compressed length is increase how can we identify that.
1.c) Identify the strings which cannot be compressed using this method and compress those
which can be. Wrote code and explain it to him.
1.d) What can be the practical applications of this algorithm, i told him that warehouses
like AWS Redshift already does Data compression, listed him some other useful one’s like
they already use for Dates Column.
Q2. Projects discussions, and have to explain one project to him in detail. he posed several
design flaws in my project and asked me for their solutions. This part was very critical as
he drilled me to some cases and i had to come up with some technical solution or to correct
him if it was a invalid business use case.
In this way he also checked how much knowledge i have of business apart from technical.
After 5 days : Congratulations from Amazon.com we will be going to offer employment
offer for you �
Status : Selected

867
Chapter 358. Set 351 (Off Campus – For SDE I)

All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-351-off-campus-sde/

868
Chapter 359

Set 351 (Off-Campus for SDE I)

Amazon Interview Experience | Set 351 (Off-Campus for SDE I) - GeeksforGeeks


1) Online test with MCQs on OS, DBMS, basic algo ds.
Coding problem: https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations/
2) Telephonic Round 1
Find height of a binary tree.
Find height of a binary tree when the leaf nodes are connected to each other via a circular
doubly linked list.
Balanced parenthesis no stack solution and with stack solution. And minimum number of
flips to make bracket sequence as balanced
3) Telephonic Round 2
Sum of values in any submatrix for a given matrix.
Maximum sum path in a given binary tree. There may be negative values in the tree. Path
can start and end anywhere.
Given transactions between group of friends. How to minimize the number of transactions
by eliminating redundant cash flow paths? Suggest data structure and solve.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-351-off-campus-sde-2/

869
Chapter 360

Set 352 (For SDE I)

Amazon Interview Experience | Set 352 (For SDE I) - GeeksforGeeks


1) Online coding round of 45 minutes. We had a question where we had to read an
unknown number of lines from a data file. Each line had a formatted date time stamp and
a person’s name.
We were supposed to tell if some person had appeared twice on the same date or not. For
C++, i used getline to take the input and then STL Map did the trick.
2) Onsite Face to Face Round 1
The interviewer asked me two questions and then I coded them after discussions:
He wanted to understand the logic behind the approach rather than just intuition. He asked
for proof of the algorithm in the sense that why this works.
https://www.geeksforgeeks.org/trapping-rain-water/
https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
3) Onsite Face to Face Round 2
He asked me about my internships and projects.
Then he asked me how to design a calculator. This involved discussions on exception
handling etc. He asked me about postfix and prefix expressions and how to use expression
trees etc.
https://www.geeksforgeeks.org/dynamic-programming-set-5-edit-distance/
4) Onsite Face to Face Round 3
The first question was this:
https://www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/
He gave me input constraints of length of string as 10^5.
Then we discussed about detecting cycles in a graph. Can we use a BFS to detect a cycle
in a directed graph? He asked me to code cycle detection for a directed graph.
The last question was this:
You are given a binary 2 dimensional array, find the area of the largest rectangular submatrix
which has 1s only. He was not convinced with the my approach and asked me to give him
test cases where this will fail. We made ten – fifteen cases and tested and it seemed to work.
5) Bar Raiser (Skype):
He wanted me to code a data structure for an auto-completing a search query. I mentioned

870
Chapter 360. Set 352 (For SDE I)

Trie is a way and then we had discussions on Trie and search, insert etc in a Trie.
Then he asked me to code it using a Trie:
https://www.geeksforgeeks.org/auto-complete-feature-using-trie/
Then we discussed about databases. What are normal forms?
How will you design a database with books and authors (many to many relationship).
How do we query for the author with the maximum number of books?
What is a deadlock and what are ways to avoid it?
Give me a real life example of a deadlock.
Explain to me any single project in which you had to meet a deadline and what was your
course of action?
There was one more round after this and that was the Bar Raiser actually. The 5th point
mentioned in the initial post was just a technical interview.
He asked me why amazon?
Have i ever been in a situation where i went against my mentor in a project and what was
the result?
How do i keep myself motivated during tough projects?
How to meet deadlines?
How to make sure the work done by you in a project is easily understandable by a person
after you leave the project?
These were the coding questions: Convert infix to postfix and evaluate postfix. He wanted
me to assume nothing (the input string may not be valid and the code was to report so).
GeeksforGeeks helped me the most during my preparation time.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-352-sde/

871
Chapter 361

Set 353 (For SDE-2)

Amazon Interview Experience | Set 353 (For SDE-2) - GeeksforGeeks


I went through some interview rounds for SDE-2 in amazon. Below is the format.
Round1:
1. LCA of Binary tree
2. Finding minimum cost to combine n pipes of different size.
Round2:
1. Behavioural question.
2. Design Dating application. HLD, then specific discussion of profile search and ranking
based on the users’ interest. Discussion on making it scalable.
Round3:
1. Design cricket score board.
Round4:
1. Architecture of current project.
2. Design an aggregator service that would be serving various services to a lot of clients.
Discussion on how this service can hand billions of data in a request. Code for the service.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-353-sde-2/

872
Chapter 362

Set 354 (For SDE-2)

Amazon Interview Experience | Set 354 (For SDE-2) - GeeksforGeeks


I went for face to face interview and faced following questions.
Question 1: Check if parenthesis are balanced or Not.
https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
Question 2: Given two unsorted arrays A, B. They can contain duplicates. For each
element in A count elements less than or equal to it in array B
Examples:

Input : A = [1, 2, 3, 4, 7, 9]
B = [0, 1, 2, 1, 1, 4]
Output : [4, 5, 5, 6, 6, 6]

All Practice Problems for Amazon !


Count the elements

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-354-sde-2/

873
Chapter 363

Set 355 (For 1 Year


Experienced)

Amazon Interview Experience | Set 355 (For 1 Year Experienced) - GeeksforGeeks


I recently got an interview call from Amazon (Chennai) for the Kindle team. Here is my
experience:-
Round 1 – It was written round (Pen & Paper) consisting of three questions –
1. Run length encoding of a string. Ex – Input – aaaabbcd , Output – a4b2c1d1
2. Given a linked list consisting of characters. Determine if it is a palindrome or not? O
(1) space complexity.
3. Connect nodes at same level. https://www.geeksforgeeks.org/connect-nodes-at-same-level/
Out of 30 people, they shortlisted 6 of them for further rounds. I was one of them.
Round 2 (F2F) – It was purely based on programming standards:
1. Given a binary tree with two nodes, find the lowest common ancestor of them.
2. Adding to first ques, he further asked; find the minimum distance between any two nodes.
3. There is a conference room. N people are joining the conference. You have the start time
and end time of each of them visiting it. You are asked to determine the maximum number
of people that can be inside the room.

Example – Four people are visiting the conference


Person A B C D
Start (hour) 1 3 2 5
End (hour) 4 5 7 10

Answer will be – 3
It went well. I was able to answer all of them. They asked me write production level code
for each of them. Take care of all the end cases. Three out of six were able to make it.
Round 3 (F2F) – This round was grilling and was again on programming standards:
1. Print the top view of binary tree. https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/

874
Chapter 363. Set 355 (For 1 Year Experienced)

2. Find the maximum sum of any rectangle in a square matrix of n x n.


https://www.geeksforgeeks.org/dynamic-programming-set-27-max-sum-rectangle-in-a-2d-matrix/.
They provide you necessary hints whenever needed or if they feel you are not able to find a
solution or thinking in a very wrong direction.
After this, they call me to Chennai for further two rounds of process.

Round 4 (Hiring Manager) – In this round, they focused on my experience and previous
company’s work.
All behavioral type of questions like:
1. How do you measure your success in the whole year?
2. Mention some of the negative and positive feedbacks from you manager.
3. Why you want to leave the firm so early? Why Amazon.
4. Questions on my projects and achievements in current company.
Hints: Just do not blame you current company as answer to any question. A clever way to
deal this round is make them realize you are quite good for amazon.
P.S. Some research on Amazon before the interview would be great.
Round 5 (Bar Raiser) – This was my final round. It was mixture of behavioral and
coding.
Behavioral question were almost same what I mentioned above.
Discussions on my Final year project and what new I can add to it if I am given a chance
to improvise it.
Some coding questions:
1. Given two strings, find the uncommon characters in them using single hash map.
2. Given data of millions of people, (name, age, M/F etc.) Develop an API that will have
age range as input and yield the count of people under this range as output.
Thanks Geeksforgeeks for all the references. You people are doing great!
Key points:
1. Just write clean and crisp code, whenever asked to code considering the end cases.
2. Maintain continuous discussions with interviewer. He/She will help you whenever needed.
All Practice Problems for Amazon !
Maximum sum Rectangle

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-355-1-year-experienced/

875
Chapter 364

Set 356 (For 6 Year


Experienced)

Amazon Interview Experience | Set 356 (For 6 Year Experienced) - GeeksforGeeks


I went through some interview rounds for SDE-2 in amazon. Below is the format.
Round1: It was a test on HackerEarth with two programming questions
https://www.hackerearth.com/challenge/hiring/amazon-hiring-challenge-2/problems/
Round 2:
1. Boundary Traversal of binary tree https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
But output should be 20 8 22 4 25 10 14
2. Find four elements a, b, c and d in an array such that a+b = c+d https://www.
geeksforgeeks.org/find-four-elements-a-b-c-and-d-in-an-array-such-that-ab-cd/
Write production ready code. Consider scenario for duplicates too.
Round 3:
1. Trapping Rain Water
https://www.geeksforgeeks.org/trapping-rain-water/
2. Next smallest palindrome
https://www.geeksforgeeks.org/given-a-number-find-next-smallest-palindrome-larger-than-this-number/
All Practice Problems for Amazon !
Next Smallest Palindrome
Sum equals to Sum

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-356-6-year-experienced/

876
Chapter 365

Set 357 (For 2.5 Years


Experienced)

Amazon Interview Experience | Set 357 (For 2.5 Years Experienced) - GeeksforGeeks
Some time back I went through an interview for Amazon.com for SDE-1 role, and here is
my experience to help other aspirants :
Written – Pen & Paper Rounds
Had to write production level code in any programming language of my choice, covering all
the edge cases, and clearly mentioning the complexity of my code.
�Q1. https://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/�
Q2. https://www.geeksforgeeks.org/remove-minimum-number-characters-two-strings-become-anagram/
Q3. Given an array, print the Next Just Greater Element for every element. The Next just
greater Element for an element x is the just greater element on the right side of x in array.
Return the same element if there is no greater element present on right side, or if same
element is present again on right side (in case of duplicates)
For e.g. given input array : 3,5,8,4,2,6,3
output should be : 3,6,8,6,3,6,6
Solved it using Binary search tree
Face to Face Rounds�
Interviewers were very very helpful, and were focused on approach, they will ask basic brute
force solution first, then an optimum solution, after that they may increase the complexity
of problem a little bit, and if you are able to explain your approach satisfactorily, then will
ask you to write production level code in any programming language of your choice, covering
all edge cases using pen and paper :
�Q1. Find an element in an unsorted array such that all left elements are smaller and all
right elements are greater. O(n) time complexity solution is required.�
Q2. Find kth smallest element in row wise column wise sorted matrix. Discussed both min
heap and max heap approach with complexity of both.
What if there are duplicate elements in matrix, and we have to consider all duplicate element

877
Chapter 365. Set 357 (For 2.5 Years Experienced)

as one position, i.e. if matrix contains elements like 3,6,4,3,5,4,7 then


1st smallest element is 3
2nd smallest element is 4
3rd smallest element is 5
4th smallest element is 6, irrespective of there occurrence
I asked if I can use hashing, but he was looking something with less space complexity, was
not able to answer this particular thing further.
Q3. https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
Q4. Find the maximum difference between any combination of child and parent node in a
given binary tree. Here child node can be any level below parent node, but should be in
the same sub tree starting from parent node. solved using recursion, bottom up approach,
returning the maximum difference and minimum node value till current node, to upper node
at every level.
Q5. Detailed discussion about project, something new which I have designed, why this, why
not this etc, how my team work, complete process, my individual role, responsibility and
contribution. Do you have bugs in code, how you correct. Have any bug from your code
reached production. What you do outside of work, do you have any open source contribution,
etc.
Q6. Given any two nodes in a binary tree, find the path from 1st node to another, and tell
if the path is a straight line, or there are turns on the line, find number of turns.
Q7. Detailed discussion about java hashmap, hashset, its internal working and its complex-
ity.
Q6. Lots of behavioural questions like, most complex thing done, how you did it, what
challenges you faced, negative feedback you received, how you improved, and many more
cross questions.
Advice to fellow members preparing for something like Amazon :
1. first get good understanding of basic data structure concepts, can refer geeksforgeeks.org
section wise or any book like Narasimha Karamunchi (I referred this book), don’t just read,
but implement things.
2. Read book like Cracking The Coding Interview to learn how to answer behavioural
questions. These questions are very limited, but are must for amazon.
3. Practice and solve last 40 amazon interview experience from geeksforgeeks.org
I hope this information will be helpful to all of you, wish you all the very very best.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-357-1-5-years-experienced/

878
Chapter 366

Set 358 (Off-Campus)

Amazon Interview Experience | Set 358 (Off-Campus) - GeeksforGeeks


Amazon conducted interview in their Bangalore office. There were many candidates lined
up for interview.
Round 1
1. Create a class which is collection of integers. Create methods to add an element, retrieve
an element and addToAll method in O(1) time.
2. Given 52 cards of deck, write a method to shuffle them and produce a permutation of
cards such that every call to this method will produce a distinct permutation. Ex- on call
52! times it should print all distinct 52! permutations.
3. Find median of BST without using extra memory.
The interviewer was always going in some other direction from the solution/things suggested
to him. He was not ready to understand the things and it got difficult for me to make him
understand the things. Got rejected after this round. Felt very bad, a girl candidate was
asked very easy questions one of them was reversing a list.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-358-off-campus/

879
Chapter 367

Set 359 (On-Campus)

Amazon Interview Experience | Set 359 (On-Campus) - GeeksforGeeks


20 MCQs mixed with simple Quants, logical, other Technical CS concepts (TOC, DS, DBMS,
NETWORKS)
2 Programming questions (I solved both)

1. Maximum Non-Adjacent Subsequence

Use max (previous element’s exclusive + arr[i]) idea. See Geeks For Geeks or Tushar Roy
video if needed.

2. Profit sort (Find no. of elements in the given range)

(Did it in
o(n) for each query, by normal for loop traversal
o(log(n)) for each query, by sorting and using Binary Search we can pass TLE (Time Limit
Error) then finally, I solved it using Hashing and then do like counting sort algorithm so
o(1) for each query (Because question had maximum space complexity as 256MB so it
won’t be a problem) MOST OPTIMAL ONE.
FACE TO FACE INTERVIEWS:
4 Totally = 3 technical, 1 technical + Bar raiser rounds
First Round: (1 hr.)

• Tell me about yourself?


• How was your placement preparation?
• How were your previous company interviews?
• Which DS you are comfortable? (Tricky for some panels asked other DS rather)

880
Chapter 367. Set 359 (On-Campus)

• Merge 2 sorted linked list into sorted one (Optimize code further)
• Write code for the same by covering All Edge cases (Avoid wild pointers)
• A modified DFS with recursion question
• You want to ask any questions?

Second Round: (40 min)

• What’s your passion in technologies?


• Write code to connect Binary Tree leaves nodes like a Doubly linked list (Use Post
Order or any Traversal and keep track of previous nodes and check if it’s leaf node.
Note: Avoid Dangling or wild pointers while writing code, initialize variables to NULL)
• You want to ask any questions?

Third Round: (1:20 hrs.)


(PROBLEM SOLVING + kind of like STRESS INTERVIEW)

• U have 2n players, they compete with each other, each player has a rank, what can
you tell about the winner?

(Question was same as this, I asked many clarifications (received stress then answers) and
tried Graphs, Sorting players based on Ranking he said it’s not required, demanded efficient
one then I solved using Tournament Trees (2n is the clue to use tournament tree) He was
very satisfied.

• Write a code to convert a palindrome number to next immediate higher number and
it’s a palindrome too e.g. 1221=> 1331 (Think about edge cases like 99, 191 before
coding, that will reduce no. of strikes on paper, in case of 9, u have to propagate carry
to next elements)

COMMENT about your codes nearby too for better understanding.

• What is Scheduling algorithm? What is used in ur PC? (Multiple feedback queue) he


didn’t accept Round robin.

Rapid Fire Round:


(these were challenging as he expected to answer faster!)

• Why should I hire you?


• What’s the book you read recently?
• What is your biggest mistake?
• What is your strength?
• What is your weakness? How you overcame it?
• What do you want to change in Amazon?
• Why your ICICI project was rejected for next level?

881
Chapter 367. Set 359 (On-Campus)

Final Round (1hr) test BASIC CS concepts more

• First received a compliment from interviewer for my fast coding skill on paper (previous
panels review).
• Do you like android or iOS? Me: Android! Then take your phone write a code to
simulate Android pattern locking, took my phone and understood what patterns
are possible then

(I solved and coded it using recursion and backtracking)


Matrix can be N x N Pattern Box.
2 sub-problems:
1. Check if given pattern is possible or not (Use ANGLE 90 or 180)
2. Print all possible patterns you can make with given length and starting point
Edges cases should be covered properly!

• Tell about projects?


• Is your forum (project) hosted in your college?
• Why you have used NoSQL in your project?
• Why you can’t use MySQL? Where it is used?

(Explained ACID properties using BookMyShow app exactly)

• What and all will happen when you boot up your PC? (Tell from BIOS stage)
• What is kernel?

I explained everything I knew, finally I explained Android Phone Kernel too. He was very
impressed and was like stopping further simple questions.

• How PC is executing things? Program counter. Explained more.


• How variables are stored? Depends, Register or Main Memory. Explained more.
• Why main memory or register when you have secondary memory?
• How program is made to run (steps). Explained like C program to Assembly language
to binary codes.
• Program vs Process (I tried to explain threads, he stopped me then below one)
• Design a DS question

U have a dictionary of words (Not necessarily in order given in our English dictionary)
How will u search for word (Used topological sort and explained why and how it works he
was convinced)

• Difference between Abstraction and Encapsulation?


• Why we should use ER diagram? (I gave a lead to Normalization thus next questions)
• Then again why Normalization?

882
Chapter 367. Set 359 (On-Campus)

• Give examples of anomalies if we don’t normalize, I explained with an example


database.
• How threads can communicate? Files, Pipes etc.
• Have you attended any coding contests?
• U want to ask Any questions?

It was all done in one day. I thank Geeks for Geeks so much for helping me for my placement
preparations. It was and is very helpful!!

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-359-on-campus/

883
Chapter 368

Set 360 (On-Campus)

Amazon Interview Experience | Set 360 (On-Campus) - GeeksforGeeks


Round 1: (Online Test)
Time: 1hr 30 mins on HackerEarth Platform
20 MCQ (Gen Apti, OS, TOC, Networks and DS)
Coding:
1. Maximum non adjacent subsequence
2. Profit sort (Find no. of elements in the given range)
Round 2: (Problem Solving Round)
1. Vertical Sum of Binary Tree.
Discussion about various data structures that can be used. Finally came up with hash map.
2. Width of Binary Tree
3. How map is internally stored in C++?
4. If N students in a class play a game against each other where each student plays against
all other students in the class, find the total number of matches to be conducted.
Also, if the class leader has to arrange the students in a line where each student would have
lost the match with the student in front of him (Remember: student may or may not have
won the match with the student front of front of him). Design a suitable data structure for
maintaining such an order.

Round 3: (Data Structures and Algorithms Round)


1. Project Discussion
2. There are various libraries that a Kindle app may use. All these libraries must be linked
appropriately to be included in Kindle. There will be dependencies between the libraries.
Apply a suitable data structure such that a library cannot be added before its dependencies.
I discussed a topological sort approach. Finally wrote code and tested the same.
3. Discussion about second coding question asked in the online test. I was asked to bring
up a better solution, given, that I can use extra space. I proposed an approach based on
hashing and counting sort.
4. Threads vs Process. They were impressed because I explained with a real-time example
5. How the Program is stored in memory? Stack frame for Program?

884
Chapter 368. Set 360 (On-Campus)

6. When two threads access a code at the same time, what happens. How is it prevented?
7. Difference between mutex and semaphore.
8. Priority Inheritance and Priority Inversion.

Round 4: (CS Fundamentals)


1. Tell me about yourself
2. Design a music player application
I was asked to first list out all possible features to be added within 2mins time. I came up
with around 30 features. The interviewer selected a few of those features and asked to draw
a class diagram for the same.
3. I have a DB of some size as of now. In future new DB with additional space will be
added. How will the DB be modified? What to modify? How to scale it?
4. Distributed computing concepts
5. Multiple partitions in OS
6. MVC design pattern
7. My costliest mistake in life
8. Asked something interesting about myself that others don’t have.
9. Whether I like back-end or front end. Reason out.

Round 5: (Bar Raiser Round)


1. Project Discussion
2. There are k stars in the space and an origin star, find the nearest 100 stars from the
origin star.
I came up with brute force approach first.
Later devised a max heap solution and coded the same
3. Virtual Machine
4. About AWS, S3
5. Design Patterns. Asked to implement Singleton Design Pattern in Java
6. Scheduling Algorithms. Which scheduling algorithm does modern operating systems use?
7. Strength and weakness
8. Latest technical knowledge that I gained. Recent technical article that I read.
9. Maximum amount of code that I had ever written in college.
10. Any Questions from my side?
I was one among the three to be selected from my college for Full Time SDE at Amazon
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-360-campus/

885
Chapter 369

Set 361

Amazon Interview Experience | Set 361 - GeeksforGeeks

Round 1 :
1. Given 2 array of size m , n , find the pair from diff array with minimum difference
2. given the dialer of a feature phone and a dictionary of words , find the string suggestions
after dialing n numbers .
3. Verify if the Tree validates the definition
parent_node.data = left_node.data + right_node.data

Round 2 :
1 . how to handle server scaling up to sudden increased of request
2 . how to handle scaling the data
3. Design BookMyShow tables .

Round 3 :
1 . given an array of Strings , not necessarily in any order , find out if the string create a
chain , such that first last char of a string is the first character of another and thus making
a chain including at least all string
2 . Given a party with n people , a given function Knows() , such that
A knows B : true if a knows B
A Celebrity would be a person who knows no one but is known by all
Find out the celebrity if he exists in the party. I would like the mail id to be kept confidential.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-361/

886
Chapter 370

Set 362

Amazon Interview Experience | Set 362 - GeeksforGeeks


1st round( written)
They asked to write 3 code in 1 hour.
1. write code to find the diameter of tree.https://www.geeksforgeeks.org/diameter-of-a-binary-tree/
2.Search an element in rotated sorted array in optimized wayhttps://www.geeksforgeeks.
org/search-an-element-in-a-sorted-and-pivoted-array/
3. Given an array of size n and an integer k, return the of count of distinct numbers in all win-
dows of size k.https://www.geeksforgeeks.org/count-distinct-elements-in-every-window-of-size-k/
I have written all 3 code in 1 hour and i asked to wait for 2nd round. they provide food
coupon for lunch and resume interview at 2 p.m.

2nd round only 2 questions he asked.


1. count minimum days to rotten orange.https://www.geeksforgeeks.org/minimum-time-required-so-that-all-oranges-
I have given this approach and write the code for it.. but there was some mistake in my
code so he rectify it.
They need proper code no pseudo is worked for them.
He had given me 15 minutes to write the code.
2. Merge K sorted arrays in optimized way.https://www.geeksforgeeks.org/merge-k-sorted-arrays/
I know the solution , but could not implement at that time. Min heap is the solution.
I have given the simple approach to put them in one large array and apply merge sort.
one more solution i have given i will make binary search tree of all the elements and print
the inorder of the tree ( i had written this proper working code )
This round went for about 1 hour. The concerned person told me HR will get back to you.
Geeksforgeeks very helpful for this experience. Do always share your interview experience
it will help other geeks.
Geeksforgeeks has given me confidence to crack the interview.

887
Chapter 370. Set 362

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-362/

888
Chapter 371

Set 363 (On-Campus for


Internship)

Amazon Interview Experience | Set 363 (On-Campus for Internship) - GeeksforGeeks


Round 1:online Test(90 min)
20 MCQs
-15 Technical(DS,OS,NETWORK,PCD)
-5 Aptitude
2 Coding Questions
-Finding duplicates in the given array,change that to 1,move all the 1’s to the right side and
the other elements are moved to right
-Pair sum count(to find the number of pairs present in the given array whose sum is also
present in the array)
Round 2:coding in paper
2 coding questions(60 min)
–To find the diameter of a binary tree
–Given a linked list, write a function to reverse every k nodes (where k is an input to the
function).
Round 3:Technical HR 1
-Project Explanation(Basic Details is enough)
-Data Structure questions
-Solving 2 Coding questions
–To construct a binary tree from inorder and post order traversals
–To find the Least Common Ancestor of a binary tree
Round 4:Technical HR 2
-Project Explanation(hardcore details)
-JVM,JRE
-Operating Systems
-Compiler Design
-To draw automata for given questions

889
Chapter 371. Set 363 (On-Campus for Internship)

-OOPS
-Basics in Network
-Testing Questions
-Design Patterns
-drawing design pattern for the project done
-Why Amazon?
-Any Questions from me(HR)?
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-363-campus-internship/

890
Chapter 372

Set 364 (On-Campus)

Amazon Interview Experience | Set 364 (On-Campus) - GeeksforGeeks


In my college, we 250 students have attended Amazon interview, and from that 16 among
us are selected for the internship.
1st round: Online test: 2 – coding questions
We were given 1.30 hrs to complete it
i) Merge two sorted arrays
ii) Find the element which is repeated more than twice in given array
20 MCQ questions based on data structures
2nd round : written test – 2 programs
we were given 1.15 hr to solve it. and it was correct and marks were given separately by
all judges. Among them nearly 30 are selected for next round.for the second problem they
have expected for dynamic programming solution.
i) Given an array, arrange it in such a way that odd elements occupy the odd positions and
even elements occupy the even positions.
ii) Convert the given string into palindrome by removing minimum number of characters.
3rd round: written test: 2 programs
Here we were given 1 hr and a HR will be present to whom we must explain our answer and
satisfy his expectations.
i) find the next largest number by using the same digits in the given number.
ii) given a matrix , sorted row wise , find the common element among all the rows.
4th round: Technical hr:
I was selected for next round for QAE and they asked me several questions. We must
answer all the questions by considering the practical scenarios and presence of mind is
important.Even if u doesnt know the correct answer, try to compromise them with ur
smartness.
i) Write testcases for frequently bought items in amazon.com
ii) write usecases for temperature sensing application
iii) write a linux command for deleting all the files contains the word “error” in its name
from a folder named XXX.

891
Chapter 372. Set 364 (On-Campus)

iv) Troubleshoot: in amazon.com a person X has ordered for 10 items.oly 2 among them
were delivered to X.but it is showing in amazon’s mobile app, as all 10 items are delivered.at
the same ti,e it shows the correct status in amazon’s website….find why??
5th round: Technical Hr with Hiring manager:
In this round he ll question u technically, but he ll check ur way of answering and attitude.He
ll just check whether u ll be suitable for that position.Ur knowledge doesnt matter here..Ur
attitude speaks.
i) Validate the cancel order option in amazon.com
ii) Draw the flow diagram of ur project and explain it briefly. How ll u provide security for
ur project.and many questions related to my project.
iii) troubleshoot : you are unable to see the latest details in ur mobile app.it still shows the
old details.What are all the reasons?
iv) troubleshoot: what all the things u ll do , if u couldn’t open ur mobile app?
All Practice Problems for Amazon !
Even and odd elements at even and odd positions

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-364-campus/

892
Chapter 373

Set 367 (On-Campus for


Internship)

Amazon Interview Experience | Set 367 (On-Campus for Internship) - GeeksforGeeks


1st ROUND(Online Round :90 min)
There were 20 aptitute questions based on C,DS,OS,OOPS and 2 coding questions.
Coding Questions:
1. https://www.geeksforgeeks.org/find-nth-magic-number/
2. https://www.geeksforgeeks.org/count-triplets-with-sum-smaller-that-a-given-value/
Since coding questions were easy those who completed both coding questions and some
aptitude questions were selected.
Total 19 students were selected from this round.
2nd ROUND (TECHNICAL INTERVIEW :Around 1 hour)
First he asked me a genuine question : “tell me about yourself”.
1.Find the intersection of two arrays .Initially i told him to use c++ map to hash, immedi-
ately he asked me to implement your own defined map,I was a little confused then he asked
me to use hashmap and finally i solved this one.Interviewer was very co-operative.
After this he asked me about various data structures then he asked:
2.Given a binary tree,print the nodes in spiral form.I solved this one immediately using two
stacks, he was much impressed and told me to wait for next round.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
Total 6 studens were selected for next round.
3rd ROUND (TECHNICAL INTERVIEW : Around 30 min)
The interviewer was very cool.He immediately asked me questions:
1. Find the rotation point in a rotated sorted array.It was a stright forward question on
binary search.
https://www.geeksforgeeks.org/find-rotation-count-rotated-sorted-array/

893
Chapter 373. Set 367 (On-Campus for Internship)

2. Given a linked list separate even and odd numbered nodes such that even numbered
nodes are at the front of the list and in order followed by odd numbered nodes.Since it was
also a straight forward question. I explained two approaches and he was satisfied and asked
me to code it.
https://www.geeksforgeeks.org/segregate-even-and-odd-elements-in-a-linked-list/
Count triplets with sum smaller than X

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-367-campus-internship/

894
Chapter 374

Set 368 (Phone and Onsite)

Amazon Interview Experience | Set 368 (Phone and Onsite) - GeeksforGeeks


1. Phone interview
Deep copy of linked list
Onsite interview
1. Question on map reduce, find if all words in a file are palindrome
2. Design Elevator with OOPS concept
3. Design Twitter
4. Problem related to amazon
5. Compare two expressions and check if they are similar. for example -(a+b+b) = -a-c-b
Similar expressions

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-368-phone-onsite/

895
Chapter 375

Set 369 (On-Campus)

Amazon Interview Experience | Set 369 (On-Campus) - GeeksforGeeks


Around 600 students gave the test.

1.Round 1 : 2 full coding questions+ 20 technical mcqs


This round was an hour long. The first 20 questions were related to data structures, sorting
algorithms, computer networks etc. There were no separate sections or times for the mcqs
and coding question. The first coding question was to count and print all the duplicate
elements in an array. The second question was to merge 2 arrays in ‘non-ascending orders’.
The original arrays had same size and were in ‘non-ascending orders’. (Non-ascending order
simply means descending order) I used simple brute force method for the first one and all
test cases passed.
2. Round 2 : Written Coding Test (3 questions)
140 students were selected for 2nd round. Students were divided into batches of 10 and
were given 1 question of full coding, 1 question to determine all possible test cases and
1 question to identify the given algorithm and debug the same. All batches were given
different questions. The following questions were given to me-
1. WAF to swap kth element from front and back in linked list. I used the most basic
method in which, I traversed through list and identified nodes to be swapped, then simply
swapped the nodes. The panel present during the test was very helpful and was providing
assistance in case any student had any doubts. I discussed my approach with them,they said
I can reduce the complexity further but the solution I gave was also acceptable. I decided
to come back to this question once I was done with the other questions.
2. Given are 2 linked list which store digits of two numbers, add the two numbers. Determine
test cases for this question.(cases having carry, no carry, negative number etc)
3. Identify the algorithm and rectify the error.
The code given was to check whether given binary tree is a binary search tree or not. The
conditions in if statements were incorrect, we had to identify and correct them.
I didn’t get time to optimize my first code. They took all our fair as well as rough sheets.

3. Round 3: Technical Interview(2 coding questions)

896
Chapter 375. Set 369 (On-Campus)

Around 50 students were shortlisted for technical interview. The interviewer asked for my
resume and asked me about one of my project works. Then he moved on to asking programs.
1. Determine the row index with minimum number of ones. The given 2D matrix has only
zeroes and ones and also the matrix is sorted row wise. I could come up with solution with
time complexity N square. He gave me hints to traverse in different manner(diagonally) and
asked me to keep a broad perspective while thinking for the solution.I tried for some more
time but failed, then he moved on to the next question.
2. Given a binary tree and 2 nodes. To find whether the 2 nodes are cousins or not. I came
up with a solution using recursion. He was satisfied with my approach.
My friends got questions like bottom view of tree, best technique to sort first 5 elements of
array with 1 million elements(brute force), mostly questions related to trees were asked.
After the 2 questions he asked if I had any questions for him. I asked him how I had
performed in this round. He gave a smirk and replied, “The HR will tell you”. � Then I
asked him if it was allowed to change domain in Amazon to which he replied, “Yes, but only
once you are permanently hired, not as an intern”. This round was 1.5 hours long.

4. Round 4: Last round – Trouble Shooting and Debugging Round


In this round the interviewer gave me a scenario where a user is using an application and the
application suddenly crashes, what would you do if you were a tester. She wanted to hear
terms like ‘test cases’, ‘testing’ etc in my answer. This was a tech cum HR round, where I
got to talk most of the time. This round was 45 minutes long.
After this we were asked to go home and wait for a text message from Amazon, in case we
get selected.
GEEKSFORGEEKS, indeed was a great help. Prepare all questions under Amazon tag
from geeksforgeeks, you stand a cent percent chance of getting hired.
Row with minimum number of 1’s

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-369-campus/

897
Chapter 376

Set 370 (On Campus for


Internship)

Amazon Interview Experience | Set 370 (On Campus for Internship) - GeeksforGeeks
Round 1: Online Round(90 minutes)
There were 20 MCQs and two coding questions. MCQs were mostly logical reasoning,
running time and DS/Algo. There were also 2-3 OS, 2-3 DBMS and 1 networking MCQ.
2 coding questions-
1- Magic numbers are defined as either powers of 5, or sum of unique powers of 5. Find nth
magic number. Eg: 5,25,30,125,130 etc.
https://www.geeksforgeeks.org/find-nth-magic-number/
2- Print matrix in diagonal form.https://www.geeksforgeeks.org/zigzag-or-diagonal-traversal-of-matrix/
Round 2: FTF Interview(Around 1 hr)
First the interviewer told me to introduce myself. After that he asked 2 coding questions.
1- Given a binary tree and a node of that tree, find all nodes at a distance d from the given
node. Pointer to root node is given.
I took a lot of time to solve this question. The interviewer found mistakes and told me, and
I corrected them or changed my approach slightly. After almost 45 minutes I was able to
write the correct code.
2- Given an array of integers, find the first non-repeating number in the array.
I gave him the hashmap based approach and he told me to write code. I did so. After
that, he told me to find the answer in a single linear traversal of the array. I discussed a
lot of approaches but none of them were satisfactory. I couldn’t come up with the correct
approach. (Later on when someone asked him the solution, he said that he himself doesn’t
know, but maybe a very complex solution exists. I’m still not sure on that. Maybe he just
wanted to check how much we can think. :p)
<Round 3: FTF Interview(Around 30 minutes)
The interviewer asked me what subjects I like. I told him ds algo but he didn’t want to hear
that. So he asked what else and I said DBMS. Then he asked me what is a transaction, how

898
Chapter 376. Set 370 (On Campus for Internship)

is it different from an sql query, what are its properties.


After that he moved on to coding questions. He asked me what data structures or algos I
like. I said arrays and graphs. Then he asked these questions.
1- Given a sorted dictionary(array of words) of an alien language, find order of characters
in that language.
https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
I told him I had seen this question before and told him the approach. He didn’t ask me to
write the code.
2- How will you find if a cycle exists in a directed graph?
I gave him my approach and wrote the code.
3- Find the longest palindromic subsequence in a given string.
I tried to solve and told him some approach, even though I knew it was wrong but was
hoping for some hint. After just one or two minutes he said let me change the question.
4- Given 3 characters a, b, c, find the number of strings of length n that can be formed from
these 3 characters given that; we can use ‘a’ as many times as we want, ‘b’ maximum once,
and ‘c’ maximum twice.
I told him the dynamic programming approach and he asked me to code it, so I wrote the
code.
After that he said that’s all, do you want to ask any questions. �
Total number of Strings

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-370-campus-internship/

899
Chapter 377

Set 371 (For SDE-2)

Amazon Interview Experience | Set 371 (For SDE-2) - GeeksforGeeks


Recently I had an interview at amazon for SDE 2 role and here is my experience:
Round 1:
1. Given a binary tree, print the nodes in zig-zag form.
https://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/
2. Given a binary tree, return the farthermost nodes.
Round 2:
1. Implement meeting booking system like outlook.
Round 3:
This was bar-raiser round.
1. Millions of words are coming in stream and there is a typo in some words.Assign each
words in some cluster which is most closer to the word. Example: iphone, ipone, abiphone,
iphoe should be in one cluster.
2. Design Data warehouse placement system.
Lots of behavioral questions: why amazon,what is most critical feedback you got from
manager, when did you get above and beyond feedback and why.
Round 4:
Detail discussion on project which I have worked on.At each point interviewer was asking
why you did this way, why not some other way.
Design producer/consumer live and offline video streaming system.
Design comment system.
Lots of behavioral questions
Round 5:
1. Return all the possible decoding of the given digit sequence where 1 denotes a, 2 -> b,
3->c so on. Example: input 121 output ‘aba’, ‘la’, ‘au’.
2. https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/

All Practice Problems for Amazon !

900
Chapter 377. Set 371 (For SDE-2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-371-sde-2/

901
Chapter 378

Set 372 (For SDE II)

Amazon Interview Experience | Set 372 (For SDE II) - GeeksforGeeks


Round 1 (45 Mins)
Brief description of the current project: Architecture, Technologies, Workflow etc.
A 2D array problem(cant remember exactly) but I have to sum up the values on given
constraints: He asked to start with basic approach so I gave O(n^4) time complexity solution
then he asked for improvisation, after some workout I came up O(n^2) time and O(n^2)
space complexity solution. He asked for more optimisation (avoid extra space) but in given
time I could not find solution without extra space.
Find the difference between sum of values in odd level and sum of values in even level in
given binary tree: I explained the approach then he asked me to write code with both
recursive and non-recursive approach.
Round 2 (50 Mins)
Tapping Rain Water problem: I didnt know the classic solution but I came up with my own
approach which worked fine. You can find problem here
A 2d array with all 1s and 0s where 1s are land and 0s are water, Matrix itself is surrounded
with water i.e 0. I gave him O(n^2) time and O(n^2) space complexity solution and he
accepted.
He asked questions like most challenging task you did in your past experience, I explained
him about middlewares I implemented earlier for tracking the exceptions in code.

Round 3 (written)
I was called in Amazon office after few days (very nice office)
Tree traversal with several ways.
Few linear array problem
I believe this round was just for warmup.
Round 4 (45 Mins)
Brief description of current project: this time he was more focused on technologies and tools.
He asked every technology I mentioned in deep.
Top view of given binary tree: you can find the problem here

902
Chapter 378. Set 372 (For SDE II)

An html format string was given where I have to find output of given queries.
Ex.

Pratik

Queries would be like: GET name, so output would be Pratik. (something like that)

Round 5 (Manager)
After some formal discussion he came up with his question “Design pattern for chess game”
for which I wrote few classes and explained approaches for the game like peer to peer and
client-server but he was not satisfied. This round didn’t go well.
I could not make it but it was very good experience, All interviewers were so friendly and
helpful.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-372-sde-ii/

903
Chapter 379

Set 373 (For SDE 2)

Amazon Interview Experience | Set 373 (For SDE 2) - GeeksforGeeks


Round 1

1. https://www.geeksforgeeks.org/trapping-rain-water/
2. https://www.geeksforgeeks.org/total-number-of-possible-binary-search-trees-with-n-keys/
, Just the formula and its derivation was discussed

Round 2

1. https://www.geeksforgeeks.org/majority-element/
2. https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/

Round 3

1. Discussion on my project, its design, challenges faced, what important decisions I took
that worked and other such behavioural questions.
2. After this discussion, I was given a problem to design Truecaller kind of system

Only these rounds happened on 1st day. Later I was called to complete the other 2 rounds
Round 4

1. Again discussion on my project and behavioural questions around the work


2. Then, a problem was given to design a performance management system (appraisal
workflow system) that can be used across companies

Round 5

1. Discussion on project and behavioural questions


2. Design a backend store system for managing inventory and orders with different pricing
structure of items across stores. Focus was on schema and API design along with which
parts of the system will be centralised and which will be at store level

904
Chapter 379. Set 373 (For SDE 2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-373-sde-2/

905
Chapter 380

Set 374 (On-Campus)

Amazon Interview Experience | Set 374 (On-Campus) - GeeksforGeeks


CODING AND APTITUDE ROUND
There were 20 aptitude questions and 2 coding questions.
Aptitude question – each of 1 mark (-0.25 mark for wrong answer)
Aptitude question are based on OS, DBMS, Output question on c/c++, and some questions
were on time complexity of the given code
Coding question – each of 10 mark
1. Given a string you have to partition the string in such a manner that each part of
the partitioned string is a palindrome in itself and you have to count the number of such
partition

For eg: given string NITIN


N ITI N
N I T I N
NITIN

So output will be 3.
2. You are given with a large paragraph and N words.
You have to find a min length subparagraph of the paragraph which contain all those N
words in any order. Here length of a paragraph is the count of words in the paragraph.

FIRST F TO F ROUND
1. Tell me about yourself (tell them about your projects and all).
Then he asked 2 coding questions:
1. Given an array in such a way that first the element stored in array is in increasing order
and then reach to a peak element after which elements stored in decreasing order.
Then he asked me to search a given element in this array gave some approach he was satisfied
and asked to code I did the same.

906
Chapter 380. Set 374 (On-Campus)

2. He asked me to design a snake and ladder game for 2 player and code it.
SECOND F TO F ROUND
First he asked me about my projects in detail. Then he asked 2 coding question
1. Print a month of a calendar such that starting day of the month, number of days in a
week and number of days in a month Is given you can consider it as an alien calendar which
can have more than 31 days in a month and more than 7 days in a week like this

2. Second question was same as above but print like this

He was satisfied with my approach and code.

THIRD F TO F ROUND
1. Given a string print all the permutations of the string
2. Stream of integer is given, each time when you get an integer you have to print the kth
largest integer I gave 2 approach first using insertion sort and a k length array and second
using binary min heap of k element he gave some hints also at last he asked me to code I
did the same.

FOURTH F TO F ROUND
1. He asked about projects and some question related to OS
2. Then he asked given an array of strings in sorted order in some alien language where we
don’t know the ordering of the alien alphabets form these given strings we have to deduce

907
Chapter 380. Set 374 (On-Campus)

and print the ordering of all the alphabets. I used graph and topological sort he was satisfied
and asked me to code I did the same.
3. Then he asked given an array of string count the number of anagrams I gave solution for
2 strings then he asked solution for the main problem I was struggling then he helped me
and we reached to solution.
SOME TIPS
1. Be confident amazon have amazing interviewers they won’t let you fell nervous
2. Try to communicate in English don’t worry about the fluency.
3. Try to improve your problem solving and coding skills
4. Don’t just mug up or read the solution try to get the concept behind any problem and
practice approach building.
5. During interview don’t jump to the solution direct try to start with brute force and keep
talking to interviewer while you are building an approach he will let you know what he
wants.
6. Listen carefully your interviewer and follow his instruction only and catch his hints also.
7. The only thing amazon wants in a candidate is analytical and problem solving skills
8. You can use any programming language I used java
9. For preparation I used hackerrank, geeks for geeks, and book karumanchi of ds and algo.
NOTE: Please excuse my English �
Find the Highest number
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-374-campus/

908
Chapter 381

Set 375 (On Campus for


Internship)

Amazon Interview Experience | Set 375 (On Campus for Internship) - GeeksforGeeks
Recently, Amazon visited our campus to recruit interns and FTEs. There were 3 rounds in
all – 1 Online Round followed by 2 F2F Interviews
Round 1: Online Round (90 minutes)
There were 2 coding questions and 20 MCQs mostly on Time Complexities (Master Theo-
rem), Logical Reasoning, Data Structures and Algorithms, around 2 from OS, DBMS and
Networking each.
The 2 coding questions were:
1) Find the sum of lengths of non-overlapping contiguous subarrays with k as the maximum
element.
Ex: Array: {2,1,4,9,2,3,8,3,4} and k = 4
Ans: 5
{2,1,4} => Length = 3
{3,4} => Length = 2
So, 3 + 2 = 5 is the answer
2) You are given an array A where A[i] (1-based indexing) denotes the number of chocolates
corresponding to each station. When we move from station i to station i+1 we get A[i]
– A[i+1] chocolates for free. Note that if this number is negative, we lose that many
chocolates. We can only move from station i to station i+1 and that too if and only if we
have non-negative number of chocolates with us. Given that cost of one chocolate is Rs. P
, our task is to find the minimum cost incurred in reaching station n from the first station
(station 1).
Ex: A: {1,2,3} and P = 10
Ans: 30
To reach station 1 from the starting station, we need to buy 1 chocolate
To reach station 2 form station 1, we get A[1] – A[2] = -1 chocolates i.e. we lose 1 chocolate.
Hence, we need to buy 1 chocolate.

909
Chapter 381. Set 375 (On Campus for Internship)

Similarly, we need to buy 1 chocolate to reach station 3 from station 2.


Hence, total cost incurred = (1+1+1)*10 = 30
Out of around 150 students, 26 were shortlisted for Round 2.
Round 2: FTF Interview (Around 30-40 minutes)
First, the interviewer told me to introduce myself and then asked 3 coding questions:
1. Search for an element in a row-wise and column-wise sorted 2D Matrix
https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/
I started with a O(R*C) solution, followed it up with an O(RlogC) solution and finally gave
the O(R+C) solution.
2. Given an array of n elements and a number, find a pair in the array with sum equal to
that number.
https://www.geeksforgeeks.org/write-a-c-program-that-given-a-set-a-of-n-numbers-and-another-number-x-determin
This question was followed up with finding a triplet with sum equal to Zero.
3. I was provided with a function int getval(int x) which basically takes the value of x
and returns f(x). Given that f(x) is a monotonically increasing function, my task was to
find the smallest value of x such that f(x) > 0.
Round 3: FTF Interview (Around 30 minutes)
The interviewer once again asked me to introduce myself and asked 3 questions:
1. What is Data Abstraction. Explain it with a real-life example.
2. What are infix and postfix expressions. He then asked me to write a pseudo-code for
converting infix expression to postfix expression.
https://www.geeksforgeeks.org/stack-set-2-infix-to-postfix/
3. Multiply 2 numbers without using Multiplication or Division operator, Bitwise operators
or any loop.
I gave him a recursive approach and he was pretty happy with it
Finally, he asked me if I had any questions for him.
Out of the 26 selected for the interviews, 13 were finally selected for internship.
During my preparation GEEKSFORGEEKS, indeed, was a great help. Preparing from
articles under DS and Algo section would give anybody a definite chance to clear all rounds.
A big thank you to other geeks as well for sharing their interview experiences as going
through past experiences was the perfect way to end my preparations.
Chocolate Station

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-375-campus-internship/

910
Chapter 382

Set 376 (On Campus for


Internship)

Amazon Interview Experience | Set 376 (On Campus for Internship) - GeeksforGeeks
Amazon visited our campus(Jadavpur University) to recruit interns and FTEs. I’m sharing
my internship interview experience.
There were 3 rounds in all – 1 Online Round followed by 2 F2F Interviews.
Online Round(90 min on Hackerearth):
There were 20 questions mostly based on C, C++, DS, Reasoning and a few from OS, OOPS,
DBMS etc and 2 coding questions.
The 2 coding questions were:
1) Find the maximum sum of lengths of non-overlapping contiguous subarrays with k as the
maximum element.
Ex: Array: {2,1,4,9,2,3,8,3,4} and k = 4
Ans: 5
{2,1,4} => Length = 3
{3,4} => Length = 2
So, 3 + 2 = 5 is the answer
2) You are given an array A where A[i] (1-based indexing) denotes the number of chocolates
corresponding to each station. When we move from station i to station i+1 we get A[i] –
A[i+1] chocolates for free. Note that if this number is negative, we lose that many chocolates.
We can only move from station i to station i+1 and that too if and only if we have non-
negative number of chocolates with us. Given that cost of one chocolate is Rs. P , our task
is to find the minimum cost incurred in reaching station n from the first station (station 1).
Ex: A: {1,2,3} and P = 10 Ans: 30
To reach station 1 from the starting station, we need to buy 1 chocolate.To reach station 2
form station 1, we get A[1] – A[2] = -1 chocolates i.e. we lose 1 chocolate. Hence, we need
to buy 1 chocolate.Similarly, we need to buy 1 chocolate to reach station 3 from station
2.Hence, total cost incurred = (1+1+1)*10 = 30.
Out of around 150 students, 26 were shortlisted for Round 2.

911
Chapter 382. Set 376 (On Campus for Internship)

-> In the 1st question those who used cin/cout instead of printf/scanf got TLE in 20% of
test cases.
->In the 2nd question not a single test case was passed on using int instead of long long int.
I wasted about 40 mins on this.
->Doing MCQ was important. Few students who solved both the coding question but didn’t
attempt the MCQs were not selected while some who could solve 80% of 1 question(8/10
test cases) and few MCQs were selected.
Round 2: FTF Interview (Around 30 mins):
First, the interviewer told me to introduce myself and then he asked me : Count
all nodes at distance k from a given node in a binary tree. It’s very similar to
https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/ . Suddenly
he went out of the room and came after about 20 mins.By that time I came up with the
O(n) solution, I explained it to him with a pseudo code. Then, he asked me if I had any
questions for him.
Round 3: FTF Interview (Around 45 minutes):
First, the interviewer told me to introduce myself and then asked me the question asked in
the 1st round. Then, she asked me about threading.I told her that I haven’t studied JAVA
well. Thereafter she didn’t ask anything related to JAVA.
1 .https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/ I
started with an O(RlogC) ssolution,she told me to optimize it , after some time I finally
gave the O(R+C) solution.She asked me to write the code.
2. A stream of integers are coming you need to keep the track of minimum at any
time, which DS would you use? I told her that I’ll simply store the numbers in a
vector and keep a variable min and update min whenever required. Then she told me
what if you need to find Kth minimum. I told her to explain the question again , then
she asked https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/. We
discussed various approach. She asked me to code the Max-heap approach(use of STL was
allowed).Then she asked me various questions about heap.
3. How to represent heap efficiently? I told her the array representation, then she asked
me to explain the one using pointers. After that, she asked me which one is better and
why? I listed various reasons one of which was that array is cache friendly, she asked me to
elaborate this.She also asked me few questions on cache.
4. She asked me to explain heap sort in detail. We discussed it for about 5 min covering
everything in detail. Code was not required.
5. https://www.geeksforgeeks.org/connect-n-ropes-minimum-cost/ . Initially my approach
was wrong, she showed a case where it failed . After some time i told her O(N*N) approach
which was correct, she asked me to optimize it and told me to think of some DS which i can
use.Finally, I came up with the solution using heap, she asked me to code it.
Finally, she asked if I had any questions for her. My experience of this round was very good,
the interviewer was very helpful and friendly.
Out of the 26 selected for the interviews, 13 were finally selected for internship.

912
Chapter 382. Set 376 (On Campus for Internship)

During my preparation geeksforgeeks, indeed, was a great help. Almost all questions asked
in the interview were from geeks. A big thank you to other geeks as well for sharing their
interview experiences as going through past experiences was the perfect way to end my
preparations.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-376-campus-internship/

913
Chapter 383

Set 377 (On-campus for Full


time)

Amazon Interview Experience | Set 377 (On-campus for Full time) - GeeksforGeeks
Amazon visited my Campus few days back .Here is my interview experience.
There was 1 online round and 3 FTF and a bar raiser.
Online Round (conducted on Hacker Earth)
20 MCQ questions and 2 Coding Questions
MCQ question-each 1 mark(-0.25 mark for wrong answer)
Coding Questions- each 10 mark
1. Given a string you have to partition the string in such a manner that each part of
the partitioned string is a palindrome in itself and you have to count the number of such
partition.
For eg: given string NITIN
N ITI N
NITIN
NITIN
Output-3
2. You are given with a large paragraph and N words.
You have to find a min length subparagraph of the paragraph which contain all those N
words in any order. Here length of a paragraph is the count of words in the paragraph.
First Technical

1. https://www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-characters-of-another-strin
2. https://www.geeksforgeeks.org/efficiently-implement-k-queues-single-array/

Second Technical
We have n machines in which n tasks can run, and we have common cooling time t(in cycles)
for all the machines.Certain conditions need to be followed –

914
Chapter 383. Set 377 (On-campus for Full time)

1. Task can run only on its assigned machine.Each task is assigned its own separate machine.
Eg.Task1 runs on Machine1. Task2 can run on machine2.Task3 on machine3.
2. Initially all machines are cool and tasks can run on them.
3. At a time,only 1 task can run on its assigned machine.No 2 tasks can run simultaneously
even on their assigned machines.
4. Machine needs to be cooled for the cooling time period t after its task’s run is over.
5.Each task takes 1 cycle to run and machine takes t cycles to cool.
We are given an array which contains the order in which tasks are going to run on the
machines. So we need to find out how much cycles in total it would take to run those tasks.
Eg.
n=3
int arr[] = {3 ,1, 2, 1, 2}
int t = 2(cooling time)
Output=6
Explanation-
In the start task 3 can run on third machine(T0)
Task 1 runs on first machine(T1)
Task2 on second machine(T2)
Now task 1 waits since cooling time is 2 (T3 gone in waiting)
Task 1 runs now(T4)
Task 2 runs on second machine as cooling time of second machine has passed (T5)
Total cycles consumed to run all tasks =6 cycles

. We are given two unsorted arrays, size can be different we need to swap two elements one
from first array and second from second array such that the sum of each individual array
becomes equal after swapping.
Eg
int a[] = {4, 3, 5}
int b[] = {9, 1, 6}
Output-{4, 6}
4 from array a and 6 from array b are swapped to get equal sum of each array as 14.
Third Technical
Few questions from my project.Then he asked me about structure of C program.
Page fault and swap space.

• What is Caching
• Implement LRU(Only logic was asked like which data structures you would use and
how) and then 2 coding questions
• Say you are given a tree and a target node, so we need to restructure the tree when
target node becomes the root.(node can have more than 2 child)Keep in mind all the
cases.
• Count Inversions in running stream of integers.(I gave answer using bst)

Bar Raiser-
Given initial capital W and n projects and the capital being used in each and the profit

915
Chapter 383. Set 377 (On-campus for Full time)

earned from each.You need to select k projects out of these n projects such that at the end
your capital is maximised.
Eg-
W=3
int capital[] = {9,2,3,1}
int profit[] = {13,5,2,7}
int k = 2
output- 13
Explanation- We choose project with capital 1 and new capital becomes(3+7-1=9)
now we choose project with capital 9 and gets profit of 13 so final capital becomes(9+13-
9=13)
I gave answer by initially sorting the array according to capital and then selecting those
projects which have capital required less than or equal to initial capital and insert them in
max heap, after extracting the top node decrease k and my capital would change and now
i can insert new projects from remaining in my max heap which have capital required less
than or equal to new capital and repeat this step till k becomes 0.
Verdict-SELECTED �
GEEKSFORGEEKS, indeed was a great help :D.
Tips-Don’t panic ..keep trying different approaches ..they will help you when you are
stuck..Try to do as many experiences from geeks.Do all the questions under Amazon tag
from geeksforgeeks.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-377-campus-full-time/

916
Chapter 384

Set 378 (On-Campus)

Amazon Interview Experience | Set 378 (On-Campus) - GeeksforGeeks


Round 1 : Screening
There were 20 questions on OS,DS, CN, Algorithm and 2 coding question
Aptitude question – each of 1 mark (0 mark for each wrong answer)
2 Coding question – one contained 100 marks and other contained 116.
1st:- you have give n people position in a row, 1 represents standing and 0 represents sitting,
after every hour, the persons whose neighbor was sitting in previous hour will sit in current
hour, and rest sitting people will stand., the same process will continue for given hour, For
eg, 6 people are there 1 0 1 1 0 0, and after 3 hours it will be
1 0 0 0 0 0.
2nd:- http://ideone.com/K5FZ9x
Out off 120 students 14 were selected for interviews.

Round 2: F2F
2 questions were given,
1st:- you have given an array of non-negative numbers and target sum, you to find minimum
length of subarray whose sum is larger than target
2nd:- you have given an array with repeating numbers, and a window k less than n, you
were suppose to find if there is any repeating element for and ith index, like { 1, 2, 3, 4, 5,
2, 5} and k=2, for i=4, it is true.

Round 3: F2F
4 questions were given,
1st:- find K random elements from N distinct elements such that probability of all remain
the same.
2nd:- HeapSort
3rd:- check whether two trees are mirror images of each other or not.
4th:- https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/

917
Chapter 384. Set 378 (On-Campus)

Round 4: F2F
1st:- what is pointer
2nd:- how recursion works and how its memory allocation happens.
3rd:- https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
4th:- https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/
5th:- https://www.geeksforgeeks.org/maximum-sum-nodes-binary-tree-no-two-adjacent/

Round 5: F2F
1st:- https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
2nd:- given an infinite binary stream, you are suppose to on every ith position that whether
the number formed till is divisible by 3 or not, for eg. 0 1 1 0 1 1…
outout :- yes, no, yes, yes, no, yes..
Tips:-
1) remain Honest with them.
2) tell your approach how you are solving the question.
3) tell them frankly if you do not know some subject, in my case i know only DS and
Algorithm and they did not mind it at all.
4) go through past interview experience on geeksforgeeks
Getting placed in amazon is like a dream come true!!
Thank you geeksforgeeks, for all this, it helped me alot, whatever i have done, i have done
it from geeksforgeeks only!!

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-378-campus/

918
Chapter 385

Set 379 (On-Campus for


Internship)

Amazon Interview Experience | 379 (On-Campus for Internship) - GeeksforGeeks


Round – 1:
The first round had 20 MCQs with +1 and -0.25 marking scheme. The MCQs covered topics
the included – DSA, Operating Systems, Networking, OOAD, Computer Architecture, C,
C++, Java basics. There were 2 coding questions each for 10 marks.
Question – 1: Given a set of 2 alphabets (A, B), find the number of strings of given length
that can be formed such that the string contains at least one set of three consecutive B’s.
Examples:

Input: 3
Output: 1

Input: 4
Output: 2

Question – 2: There are ‘n’ friends who bring gifts to a Halloween party and they exchange
their gifts and the array of the number of gifts each person receives is given to you. Check
if such an arrangement (array) is possible and if it’s possible then, given an arrangement of
the same.
Examples:

Input:
3
1 1 1
Output: 2 3 1

919
Chapter 385. Set 379 (On-Campus for Internship)

26 people were shortlisted for the face to face interview rounds.


Round – 2:
My interview lasted for about 1 hour, 45 minutes; more than expected, generally, it was 30
minutes. We were tested on our DSA in this round. My interviewer was very good, he made
me feel very comfortable before we got to the actual process of the interview. He introduced
himself, asked for my introduction, gave me a brief introduction on what Amazon actually
does, their AWS services, Prime services, Security and Alexa.
The candidates were asked the following questions:
(I was the second last person, so collected questions from friends :P)
Question – 1: Find the vertical sum of all nodes in a given binary tree.
Question – 2: Find the maximum area under a given histogram.
Question – 3: Find the zig-zag traversal of a given binary tree.
Question – 4: Find ‘k’th node’s value from the end in a given binary tree.
Question – 5: Add ‘1’ to a given number (in the form of a singly linked list) without reversing
the linked list.
Question – 6: Find a triplet among the given numbers that satisfies a + b = c.
Question – 7: Find the largest repeated sub-sequence in a given string.
Question – 8: Given an infinitely large array, find the given element.
Question – 9: Maximum rain water that can be trapped in the given set of buildings.
Question – 10: Given an infinitely large array and every element has tags associated with
them, and there are about 10,000 tags (say) then sort the given array to get all tag-0’s first,
tag-1’s next and so on in O(n).
I got the 10th question, I was asked to approach the problem in as many ways as possible,
starting from O(n*n) solution to O(n*log(n)) and finally to O(n). I was asked to code the
algorithm on paper for any approach the interviewer liked. Finally, after discussing with
my interviewer, we came to the conclusion that my algorithm would work. I was asked
to pseudo-code the O(n) algorithm. Then, I was asked to pick a comfortable language (C,
C++ or Java). I picked Java, I was asked to code the whole solution on the paper with the
proper implementation of all functions. My code’s modularity and loop control along with
the asymptotic complexity were tested.
I got only one question but the others were tested on 2 – 3 questions, one being hard and
the rest being simple.
After this round, 11 people were shortlisted for the next round.
Round – 3:
My interview lasted for about an 1 hour; more than expected, generally, it was 30 minutes.
This was the final round. My interviewer asked me to get comfortable. He asked me about
my projects, the languages I was comfortable with and about my club activities in the
college. Then, we discussed one of my projects for some time. We discussed on Loosely
coupled systems and Strongly coupled systems with respect my project. Then he had asked
me if I was comfortable with Dynamic Programming, I said that I wasn’t very comfortable,
so, he asked me if I was comfortable with trees. I said ‘yes’; he asked me 2 questions on
trees.
Question – 1: Given a binary search tree, find and print all leaf nodes.
Question – 2: Convert a given binary search tree into a doubly linked list without using any

920
Chapter 385. Set 379 (On-Campus for Internship)

additional space.
The same method as in the 2nd round was employed here. I was asked to Pseudo-code the
solution and code it in a language of my choice (C, C++, Java). Then, he asked me if I was
comfortable with Operating Systems; I said ‘yes’. He started with Paging, Fragmentation,
Security, Job Processing, Types of OS. He covered almost all concepts of OS. The questions
were application based rather than direct topic related.
Finally, 4 people were shortlisted and were given the opportunity to work with Amazon.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-379-campus-internship/

921
Chapter 386

Set 380 (On-Campus)

Amazon Interview Experience | 380 (On-Campus) - GeeksforGeeks


Amazon Interview experience
Online Round
Platform: HackerEarth
Format: 20 MCQs, 2 coding questions
Time: 90 minutes
MCQs: Data Structures, Networks, OS, etc.
Q1) Maximum j – i such that a[j] > a[i]
Expected Solution in O(n)
Q2) Maximum of minimums of every window size
PERSONAL INTERVIEW
40 candidates were selected for the PI. 20+ candidates were rejected after first PI. Only 8-9
went till final round. 5 were finally selected.
ROUND 1:(45 mins)
Ques 1) All permutations of a string
Ques 2) Permutations with duplicates
Ques 3) Connect nodes at each level in Zig-Zag pattern.
ROUND 2:(60 mins)
Ques 1) Given an array of size N, there exist a pattern such that, a[i]-M <= a[i+1] <=
a[i]+M . Suggest an algorithm to search for a number in the given array.
The solution should be better than O(n).
He gave hints like consider M to be much much less than N, etc. I gave him many approaches
but couldn’t give him a concrete algorithm. He said we will discuss this later and gave
another problem

922
Chapter 386. Set 380 (On-Campus)

Ques 2) Imagine a land in a form of grid. There are enemies to the North of the land. And
soldiers to the West of the land. Soldiers in the West want to know if there are enemies to
the North. So they decide to place mirrors at a 45-degree angle in the grid land. If they
place a mirror at (i,j) then they can see the enemies in the jth column. Similarly, they will
put mirrors in other places in the grid to view the enemies in other columns. Now it is given
that some of the cells of the grid are rocky area and a mirror cannot be placed in those cells.
Example:

|
Walls | Enemies
__________|
_ _ R _
Soldiers _ _ _ _
R _ _ _
_ _ _ R

Solution:
|
Walls | Enemies
__________|
_ _ R _
Soldiers / _ _ _
R _ _ /
_ / _ R

In the above solution, / represents a mirror.


Using the above configuration, the soldiers are able to look at the enemies in column 0, 1
and 3.
Note there is no way to see enemies in column 2 as the rocky area will block the vision.
There can be at most one mirror in one row and at most one mirror in each column.
You have to give any one solution that puts the maximum number of useful mirrors possible.
I solved this by first marking out the useless cells. and then placed mirrors in a greedy
manner.
Time complexity: O(n*m)
Ques 3) You have been given a regex and a string. Return true if the string matches the
regex and false if not.
The regex has only * ? and English alphabets.
* means any character occuring zero or more number of times.
? means any character occuring exactly once.
Example:

regex: *aab?c
string: dbvaabcc

923
Chapter 386. Set 380 (On-Campus)

output: True

regex: *c*
string: ca
output: True

regex: ?c?
string: ca
output: Fasle

I solved this using recursion. Explore all possible paths.


ROUND 3:(Bar Raiser) 90 mins
This round was taken by a senior guy. He was very experienced and extremely smart.
He started with my CV. Asked about my internship experience and the project that I did
during my internship. My project was on a NoSQL database so questions on them. He
asked me to explain why my project was important to the organisation. What all I learnt,
etc. He gave me very tricky scenarios and asked me how I would handle those cases in my
NoSQL database. How will I protect my database against hackers, etc? Few Distributed
System question on Consistency, Availability, etc. The project discussion went on for about
15-20 min.
Ques) He then told me to imagine a large chunk of files with lots of sentences in them. I
have to find out programmatically which are the important words in them. Which words
convey more meaning?
I gave him few approaches. I kept on saying something or the other. He was fairly satisfied
and move on to next question.
Ques) Stock span problem
He asked me all the possible variations of the above problem.
I kept on giving solutions and he kept on modifying it, putting constraints, etc. He grilled
my concepts with this problem.
Ques) You have a large string of 0’s and 1’s. Re-arrange the given string according to a
formula:
f(i) = f(i-1)*f(i-1) – f(i-2)*f(i-2)
f(1) = 1 and f(2) = 2 is given.
Therefore,
f(3) = 2*2 – 1*1 = 3
f(4) = 5
f(5) = 16

Arrange in a sequence such that you have f(1) 0’s and f(2) 1’s and again f(3) 0’s and so on.
Append the remaining 1’s or 0’s in the end.

Example:
string: 1011001010011 // 7 1's and 6 0's
output: 0110001111100

924
Chapter 386. Set 380 (On-Campus)

Do this in-place and in O(n).


He was very satisfied with my elegant code and told me I did well. I was immediately
informed that I will have my 4th round shortly.
ROUND 4: (50-60 mins)
This round focused mostly on Computer Fundamentals and CS concepts. He did not ask
me any DS or Algo question in this round.
He asked me to introduce myself and then asked about my favourite subjects.
He asked me a lot of questions on Exceptions.
1. What are exceptions? How do you use them?
2. What is a Runtime Exception? Give examples.
3. Should we catch a RuntimeException? When? Why? How?
4. The advantage of using exceptions, etc.
He then moved on Threads.
1. What are threads?
2. Threads Vs Process?
3. The advantages of threads?
4. How to synchronize threads?
5. Producer-Consumer design using threads.
6. Thread life cycle
7. How threads communicate?
Asked me to write an Object Oriented code for a Banking application using Threads. Only
Deposit, Withdraw and Check Amount feature should be implemented.
I told him I don’t have these concepts fresh in my mind but he still insisted me to do it.
I was struggling with the code so he told me to leave that and moved on to Computer
Networks.
Networks:
1. What is FTP? How is different from Secure FTP?
2. How TCP works? What is 3-way handshaking?
3. What happens when I make a URL request from my web browser?
4. What is a peer to peer network? How does it work?
5. What is scp command in Linux? What does it do?
Few other questions.
I did not perform good in Round 4 and was rejected.
GeeksForGeeks was a great help during my preparation. Thanks to other students for
sharing their interview experience. �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-380-campus/

925
Chapter 387

Set 381 (For SDE2)

Amazon Interview Experience | Set 381 (For SDE2) - GeeksforGeeks


Telephonic Round :
1. Given a set of packages or jars, with dependencies over each other. Write code to provide
ordering, in which these packages should be compiled.
2. Given a number n, write code to count number of palindromes till n. For eg : If n is 10,
number of possible palindromes are 11.
3. Design a data structure to support insert, delete, search in o(1) time complexity.

Round 1 :
1. Design doctor appointment System.
2. Given a piece of code in java, provide code review comments.

Round 2 :
1. Explain architecture of project in depth.
2. Given a fully connected graph with n nodes and corresponding values. One node can
interact with other node at a time, to replace/ignore/add its value to other node’s value.
Assuming this operation takes 1 unit of time, how much time would it take for all the nodes
to have value equal to sum of all the nodes.
Examples : Given a graph with values {1,2,3,4}, find total time it takes, such that all nodes
have value as 10.

Round 3 :
1. Given a sorted string, find number of occurrences of given character in string.
2. Given a chessboard, find minimum number of moves for a knight to reach from source
to destination.

Round 4 :
In depth discussion on all the projects mentioned in resume.

926
Chapter 387. Set 381 (For SDE2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-381-sde2/

927
Chapter 388

Set 382 (On-Campus for Full


Time)

Amazon Interview Experience | Set 382 (On-Campus for Full Time) - GeeksforGeeks
The Selection process started with an Online Coding round.
20 MCQ and 2 Coding Questions:
MCQs were from OOPs, OS, DBMS, Networking etc.
Coding Questions:
Q – Rotate the given Matrix by a factor k. Input is given as two integers n,m (row and
column of the matrix). Followed by n lines with m space separated integers as all the
elements of the matrix. Last line has an integer k.
Input:
3 3
1 23
4 56
7 89
2
Output:
741
852
963
Q – Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome)
Input:
NITIN
OUTPUT:
3

928
Chapter 388. Set 382 (On-Campus for Full Time)

NITIN
N ITI N
NITIN
Face2Face (Interview)
Round 1:
He asked coding questions straight away –
Q- Add two numbers without using +,- operator, recursion or loop.
Try to think in terms of half adder.
Q- Postfix to prefix without using recursion.
Q- Given an array of numbers. What is the largest no possible by concatenating all the
numbers together.
Input:
5
21 30 1 9 98
Output:
99830211
Q – Write the heapify code.
Round 2:
Q – Level order traversal of a tree. Further he asked to optimise the code.
Q – Given a matrix. ‘0’ means empty room, ‘1’ means door, ‘-1’ means a wall. For every
cell as an empty room find the distance to the nearest door (One cannot go through a wall).
Input:
55
0 0 1 -1 1
0 -1 0 0 -1
0 0 -1 0 -1
1 -1 1 0 0
00000
Output:
2 1 0 -1 0
2 -1 1 2 -1
1 2 -1 2 -1
0 -1 0 1 2
12123
** The door would be replaced with 0 as the distance to the nearest door would be 0.
I started by a backtracking solution. But the guy didn’t know what it was. I gave many
more solutions and concluded with an O(N) bfs solution.
Guys answer straight. Do not answer very complex algorithms, even though they are correct.
Try to provide as brute-force solution as possible.

929
Chapter 388. Set 382 (On-Campus for Full Time)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-382-campus-full-time/

930
Chapter 389

Set 383 (On-Campus for


Internship)

Amazon interview experience | Set 383 (On-Campus for Internship) - GeeksforGeeks


Amazon visited our campus for internship and placement.
The Selection Process starts with an online test comprises of 20 technical questions involving
data structures,operating system basic concepts,algorithms and aptitude questions and two
coding questions.
1. Given an array find all sets of size 3 having sum of elements less than a given number k.
2. Find n-th magic number.
27 out of 150 were selected for the second round.
Second round questions.
1. given a BST with additional information at each node howmany nodes in its left subtree
and right subtree. find the kth largest element in that tree.
2. merge two sorted linked list.
15 out of 27 got selected.
3rd round questions.
1. Given two rectangles diagonally opposite coordinates. find whether a rectangle is com-
pletely overlapping the other or not.
2. Given a binary tree create a new tree which is mirror image of that tree.
3. Given three consecutive even numbers. prove mathematically that atleast one of them is
divisible by 6.
Count triplets with sum smaller than X

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-383-campus-internship/

931
Chapter 390

Set 384 (On-Campus for FTE)

Amazon interview experience | Set 384 (On-Campus for FTE) - GeeksforGeeks


Online Coding Round:
Platform: Hackerearth
Time: 1.5 hr
Questions Format: 20 MCQs + 2 Coding Questions
MCQs were based on Data Structures,OS,Networking etc.
Coding Questions:
1)find maximum j-i such that arr[j]>arr[i]
Expected time complexity: O(n)
2)find maximum of minimum of every window size in the array
Only optimised solution(O(n)) using stack was able to pass all test cases.
Around 37 students were selected from the coding round and were called for further interview
rounds.
Round1(Face-to-face):
Time: 45 minutes
The interviewer was very cool.She asked me to introduce myself and a brief introduction of
the projects that i have done.Then she moved on to the data structures part.
One question was that given an array containing equal number of positive and negative
elements, arrange the array such that every positive element is followed by a negative ele-
ment.I told her the O(n) approach by firstly segregating positive and negative elements with
0 as pivot and then arranging alternatively.She asked me to write code for that covering all
corner cases.
Second question was simple to reverse linked list in groups of given k size.
She asked me to write code for that.
Round2(Face-to-face):
Time: 45 minutes
The interviewer was very cool and cooperative.He asked me how my previous round
went.Then he moved on to the questions.
One question was simple to find boundary traversal of binary tree.He asked me to write
code for that.

932
Chapter 390. Set 384 (On-Campus for FTE)

Second question was find min cost path in matrix.I told him the approach using bfs then
finally solved it using recursion with memoization.Then he asked to write my approach on
paper.He was very impressed with my performance in this round.
Round3(Bar-raiser):
Time: 60 minutes
The interviewer was the manager and head of the panelist.He asked me to introduce my-
self,what is my favourite subject.He asked me which question i had solved that i found to
be hard and what were the problems that came while approaching that question.Then he
moved on to the questions.
One question was given a n-ary tree,for every kth level of the tree,print the kth node present
at that level on counting form left and if kth node is not available, then print the last node
at that level.I told him the obvious approach using level order traversal.He asked me to
write code for that covering all corner cases.
Another question was buy and sell stock only once.Then he changed the question to buying
and selling multiple times to maximize final profit.He kept on confusing me by modifying
the problem constraints.Then he finally accepted my solution and asked me to dry run on
that code.
Round4(Face-to-face):
Time: 1.5 hr
This round was mainly based on problem solving and various CS subjects like
OS,DBMS,OOP etc.He started the round by asking me to introduce about my project
which was an android app.He asked me about the core idea of the app, its layout etc.He
asked me about what i had used for storing various information in database and i told
him that i used mysql with mysql statements called from PHP script using url encoding
mechanism in java.He asked me about the difficulties that i faced during my project and
how i had tackled those problems.Then he moved on to the questions.
The statement of one question was similar to the mobile-keypad problem.But there was
slight variation that a dictionary of words was also given along with a number and i had
to find all words which are present in dictionary that can be obtained by pressing this
number.I told him the usual approach using backtracking.He asked me to optimize my
approach.He gave me hint that it could be done by using some spaces.Finally i came to
the optimized solution by mapping individual letters with digits from which they can be
generated by pressing the digit like pressing 2 can generate letters a,b or c so map a,b and
c with 2.Then iterate over every word present in dictionary to find if it is the possible
solution or not.
Second question was to find next higher element in an array for every element.I told him
the brute-force one of O(n^2) time complexity.He asked me to optimize that.I tried it
using BST but it was not passing all test cases.Then after some hints, i finally came to the
solution using stack.
He asked me to design a class for tic-toe game where size of board given is variable n.I
was asked to implement the member function findWin() by checking all rows,columns and
diagonals for all 1s or all 0s for any matrix size n.
He asked me questions based on OOP like abstract class,interface,their differences etc. and
in OS, he asked me about mutex,semaphore,their differences etc and describe the software
life-cycle in detail.Finally the round ended.
9 students went in the 4th round of which 5 were selected.I was one of them. �

933
Chapter 390. Set 384 (On-Campus for FTE)

I thanks GeeksforGeeks for helping me in my preparations.


All Practice Problems for Amazon !
Maximum of minimum for every window size
Positive and negative elements

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-384-campus-fte/

934
Chapter 391

Set 385 (On Campus for


Internship)

Amazon Interview Experience | Set 385 (On Campus for Internship) - GeeksforGeeks
Round-1:
Platform: Hackerearth
Time: 1.5 hrs
The first round was an online coding round and 20 MCQs. MCQs were from general com-
puter science topics like: data structures, algorithms, dbms, puzzles and some questions
based on languages C, C++.
Two coding questions were of 100 marks each and mostly based on implementation skills
like forming cumulative arrays from both ends of the array, etc.
Suggestion: Have a good command over c++ STL or Collection in Java.
MCQs – +1 correct answer and -0.5 negative marking.
13 people were shortlisted for the interview rounds.
Round-2
There were 2 questions.
First was a puzzle i.e. You are having n weights in a line eg: 12 13 2 1 6, a man is coming
with a basket from behind the first weight. He can’t read which weight he is picking as he
is illiterate and he can only keep 1 weight in the basket. But he can compare the current
weight with the weight in the basket, if it is less or greater or equal and by making some
decision he can swap the positions of the two. Initially the basket is empty. Moving from
one weight to another adjacent weight takes 1 unit time. The man needs to arrange the
weights in descending order in minimum time. And derive the formula for this minimum
time taken.
HINT: try first placing the smallest weight to the rightmost while moving right and then
placing the largest weight to the leftmost while moving left. Idea: see every time we are
decreasing the path length by 2 (1 from both sides ) by placing the smallest and largest at
the start and end respectively.

935
Chapter 391. Set 385 (On Campus for Internship)

Second was an algorithmic question : Trapping Rain Water can be found on geeksforgeeks.
Link: https://www.geeksforgeeks.org/trapping-rain-water/
Round-3
3 questions were asked in this interview round.
Suggestion: Try to write clean code with all corner cases handled.
Question-1: Interviewer asked me which data structure i liked the most. I said Segment
trees. So, I was instructed to write the build function for range sum query in an array of
integers.
Question-2: Find the maximum length of the subarray with sum zero in an array of
integers.
Subarray with sum zero : is formed when elements repeat in cumulative sum array and
maximum length
subarray can be obtained by maintaining first occurence of the element.
Question-3: Find LCA (lowest common ancestor) of two nodes in a binary tree.
https://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/
I thanks GeeksforGeeks for helping me in my preparations.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-385-campus-internship/

936
Chapter 392

Set 386 (On Campus for


Internship)

Amazon Interview Experience | Set 386 (On Campus for Internship) - GeeksforGeeks
The first round was an online round. There were 2 coding questions and 20 MCQs. The
MCQs consisted of both aptitude questions as well as technical questions. The students who
did both the coding questions and half of the MCQs were chosen for the interview round.
25 students out of 200 students who gave the online round were selected.
The first round of interview was the elimination round. It was a technical round in which
the interviewer asked me 3 questions, I had to tell him my approach and code the solution
on paper. After all the students were done with the first round, 17 students were selected
for the second round of interview. This round was also a technical round, I was asked 3
questions and was told to code them on paper. The interviewer also went through my CV
and asked about my projects. He also asked me a few technical concepts based on OS and
C++ (after I told him I code in C++).
Finally, 11 students were selected for internship, including me �
The questions asked were of the following topics :
1. Bit manipulation (2 questions in interview and 1-2 mcqs in online test as well)
2. BST and Trees
3. OS, networking and output of C programs in online MCQs
4. The coding questions in the online test included a string question and a mathematical
question which used
concepts of permutations and combinations
A tip for interviews: If the interviewer asks a question which you don’t know, be frank with
him and tell him you don’t have knowledge about it. This is much better than blurting out
irrelevant answers.

Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-386-campus-internship/

937
Chapter 393

Set 387 (On -Campus for Full


Time)

Amazon Interview Experience | Set 387 (On -Campus for Full Time) - GeeksforGeeks
Round – 1:
The first round had 20 Aptitude MCQs (20 min) and 15 Technical MCQs (15 min) with
+1 and -0.25 marking schemes. The MCQs covered topics the included – DSA, Operating
Systems, C, C++, Java basics. After this, there were 2 coding questions (45 min). Minimum
cut off was set for each section. One question was of the Game Theory and other was of
Dynamic Programming.
Questions in The Coding Round: –
Q1) Given two players A and B and some positive numbers in an array, each player will play
game by choosing a positive difference of two numbers such that the number don’t exist in
the array and place that number in the array. If he is unable to find such difference then he
looses. Each player will play optimally so as the other player is not able to find two numbers
such that there difference doesn’t exist in the array.
Q2) Given a string containing only lowercase alphabets, you have to convert it into a string
such that it contains all vowels by doing minimum number of operations. In one operation,
you could select a substring always starting from index 0, and move that substring up or
down (any number of times). Following examples are treated as 1 operation.
For Ex:- input-axzf
Let index chosen be 0 to 3and move it up by 2
Output-czbh
For Ex:- input-axze
Let index chosen be 0 to 2 and move it down by 2
Output-yvxe
12 students were selected from this round out of about 125.

Round – 2:

938
Chapter 393. Set 387 (On -Campus for Full Time)

My interview lasted for about 20 minutes. I was tested on basic concepts of DSA and OS in
this round. My interviewer was very good, he made me feel very comfortable before we got
to the actual process of the interview. Firstly, he asked for my introduction and then asked
me to write a basic C program on a given series pattern (very easy) followed by questions
on Paging, Page Faults and Stacks.
Q1) Write a code to print the nth element of the given series
1 1 2 4 8 16 32
Q2) What is paging? Why is it done? What are page faults? What are the techniques to
resolve page faults?
Q3) Implementation of stacks using arrays.
7 students were selected from this round out.
Round – 3:
This interview lasted for about half an hour. Interviewer asked me to get comfortable. He
asked me about the languages I was comfortable with and then, he asked me questions on
bitwise operator and then asked some puzzles (these were really very tricky). Then he had
asked me questions on linked list and asked me to make my solution more and more efficient
(reducing complexity) followed by questions use of maps (STL in C++). Then he asked my
how a different site gets loaded into my web browser whenever I search for any of these sites.
Q1) Given a number you have to make it last 4 bits 0 in just a single line code.
Q2) Given array of integers you have to find 3 no’s such that sum of two makes the other
in minimum time complexity.
Q3) What is the difference between JAVA and C++?
Q4) What is PASS BY VALUE and PASS BY REFERENCE in JAVA and code for the
same on the paper.
You can practice some important questions on bitwise operators on https://www.
geeksforgeeks.org/bitwise-algorithms/
Also, while preparing for interviews you must also practice some puzzles on https:
//www.geeksforgeeks.org/puzzles/
3 students were selected from this round out.
Round – 4:
This interview lasted for about half an hour. As I had mentioned Java in one of my strong
subjects so he started form the basics of JAVA like what was the purpose and need for invent-
ing this language. Then he asked me to write a simple program just checking my practice on
implementing JAVA and some question of C too. Then he gave me some interesting puzzles
like https://sbjoshi.wordpress.com/2008/06/04/puzzle-burning-ropes/ was one of them.
Q1) What is the difference between malloc and calloc function in C?
Q2) What are static blocks in java?
Q3) Can main method be overloaded in JAVA? Why or Why Not?
Q4) How Is JAVA platform independent?
Q5) Is JVM platform dependent or independent? Why or Why Not?

939
Chapter 393. Set 387 (On -Campus for Full Time)

Only 1 student was selected from this round for internship at the Hyderabad Office.
The interview experience was quite good and they focused on all the core computer science
subjects. Geeks for geeks was a lot of help to me as it helped me in my placement preparation
and provided almost all content that was necessary for placement preparation.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-387-campus-internship/

940
Chapter 394

Set 388 (On -Campus for Full


Time)

Amazon Interview Experience | Set 388 (On -Campus for Full Time) - GeeksforGeeks
Round 1: Online coding test – 90 minutes (HackerEarth)
It had 2 coding questions and 20 MCQs.
Q1: Knapsack variation(you can choose an item any number of times)
Q2: Given a 2D array consisting of 0’s, 1’s and 2’s. 1 denotes a fresh apple, 2 denotes a
rotten apple and 0 denotes absence of an apple at that position.
Each rotten apple takes 1 day to make it’s neighbors(8, given a fresh apple is already there)
rotten as well. Calculate the number of days when all the apples will be rotten.
If not, then print the number of apples which will never get rotten.
MCQs included some output based questions in C (5), time complexity (2), data structues
(10), OS(2), Java based output question(1) etc.
Round 2 (F2F1)
The interviewer was very chilled and asked me to introduce myself, then he asked me to
explain any of my projects. He then asked me two questions:
Q1: Given a special binary tree, find the height of the tree.
Speciality: each leaf is connnected to the next leaf(left to right) in a circular doubly linkedlist
fashion.
fashion. Let’s say the 2 consequtive leaves are A and B, so, A->right = B and B->left = A.
The leftmost leaf’s left points to the right
most leaf and the right most leaf’s right points to the left most leaf.
Expected time complexity = O(n), space complexity = O(1).
Q2: Flip maximum k bits to find the maximize the number of consequtive 1’s in a binary
array.
Expected time complexity = O(n), space complexity = O(1).
Round 2 (F2F2)
He started with an description of my projects and then he asked me several questions,
majorly:

941
Chapter 394. Set 388 (On -Campus for Full Time)

Q1: Next permutation of a given string(can contain duplicates). (Write complete code
including swap, reverse etc).
Q2: Find the mirror the a tree in which each node can have any number of children. (Write
complete code)
Q3: Boundary order traversal.
Q4: Check if the given 2 nodes are cousins or not.
Q5: Check wheather a given tree is a summation tree or not. (Any node’s value = sum of
all it’s children’s value).
Round 3 (F2F3)
She started with an description of my projects and then he asked me several questions,
majorly:
Q1: Difference between recursion and iteration(slightly long discussion).
Q2: Difference between array, linkedlist and trees.
Q3: Discussion on all O(n logn) sorting algorithms.
Q4: Sort an array consisting of 0, 1, and 2’s only in one pass.
Q5: Given 2 arrays which denote the elements to be inserted in two separate binary search
trees. Find wheather the two binary search
trees will be same or not, without actually constructing the tree.

Eg: 2 3 1
2 1 3
Ans = Yes.
Eg. 1 2 3
3 2 1
Ans = No.

Q6: Normal forms in DBMS.


Q7: Difference between threads and processes. Also, between multi threading and multi
processing.
Q8: Return a random node from a given binary search tree and also find the k’th smallest
value in the tree(can change the structure)
Q9: Spiral order traversal in a square matrix.
Q10: Find an element in a sorted, rotated array. Expected time complexity = O(log n).
Round 4 (Telephonic + screen share)
He also started with an description of my projects. Then he just asked one question.
Q: Given an array, find the number of inversions in the array.
The call quality and the internet connection was poor. I wasn’t able to explain my solu-
tion(recurive) on the phone call.
Then I wrote the code on the shared sreen. He asked me to dry run it on a case. Just when
I was about to dry run I encountered
a 502 Bad Gateway error. Nevertheless, he could still see my code and asked me questions
on some of the things
in my code like the use of “and” instead of “&&” and declaration of array like int temp[n]
and not using malloc
(Specifically: why malloc, if you can declare any array like this?). Later, I could not hear

942
Chapter 394. Set 388 (On -Campus for Full Time)

him properly so he decided


to end the interview here itself.
Maximize Number of 1’s
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-388-campus-full-time/

943
Chapter 395

Set 389 (On -Campus for Full


Time)

Amazon Interview Experience | Set 389 (On -Campus for Full Time) - GeeksforGeeks
Online Coding Round:
Time: 1.5 hr
Questions Format: 20 MCQs + 2 Coding Questions
MCQs were based on Data Structures, Operating systems etc.

Coding Questions:
1)Minimum time required to rot all oranges
2)Unbounded Knapsack (Repetition of items allowed)
Around 25 students were selected from the coding round and were called for further interview
rounds.

Round 1(Face-to-face):
Time: 45 minutes
The interviewer was very cool.He asked me to introduce myself and a brief introduction of
the projects that I have done.Then she moved on to the data structures part.
1) Find height of a special binary tree whose leaf nodes are connected
2) Maximum sum such that no two elements are adjacent
I was supposed to write the functions in the language of my choosing which take all the
input as parameters and return the answer. After the round was done, he insisted on me
taking a cookie �

Round 2(Face-to-face):
Time: 1.5 hours
The interviewer was very cool and asked me about how my previous round went.After that,
we immediately moved onto data structures part.
1) Minimum number of bracket reversals needed to make an expression balanced

944
Chapter 395. Set 389 (On -Campus for Full Time)

2) He asked me a question in which I have a 2D array and at every index, either there is a
soldier or a mine, I was supposed to find the minimum distance of every soldier from any of
the mines, I told him that this type of qs was already asked in the online round, after that
he asked me another qs, it was – Dynamic Programming | (Matrix Chain Multiplication)
3) Given a binary tree, how do you remove all the half nodes?
4) He asked me to implement all the standard properties of the heap that are “insert”,
“removal”, “deletion” and “update” in an array.

Round 3(Face-to-Face):
Time: 60 minutes
The interviewer asked me to introduce myself, after that he asked me questions regarding
OS, DBMS, and CN. we moved onto questions after that. After that, I was asked to
explain one of my projects to explain in complete details and also about the problems I
faced during the project. Then we moved onto qs.
1) Convert a given tree to its Sum Tree.
2) Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
3) Reverse a Linked List in groups of given size
4) What is the time complexity of binary search, prove it mathematically.
All the students who qualified the round were taken for a semester long internship. Some
of us were given a chance to convert our semester long intern to a full-time job through
another round.

Round 4(Online round/telephonic):


Time: 60 minutes
This round mainly focused on my projects and my team work skills, we discussed my
projects for around 45 minutes, after that, we moved to some simple algorithmic question
which looked like a formality. I was supposed to code it on collab-edit (online interview
platform).
question was – Length of the longest substring without repeating characters.
verdict – selected �
A Tip – Don’t take CS fundamentals for granted, although coding is important, you should
also be thorough about OS, DBMS, OOP, and CN.
PS: I have attached the link of all the question in the article. If you don’t get anything, you
can always ping me. Happy coding and Godspeed.
All Practice Problems for Amazon !
Rotten Oranges
Knapsack with Duplicate Items
Stickler Thief
Length of the longest substring

945
Chapter 395. Set 389 (On -Campus for Full Time)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-389-campus-full-time/

946
Chapter 396

Set 390 (On-Campus)

Amazon Interview Experience | Set 390 (On-Campus) - GeeksforGeeks


Amazon visited our campus in August 2017. There were 5 rounds – Aptitude test and 4
Technical rounds.
The aptitude test was an online test hosted in HackerEarth platform. It consisted of 20
MCQ’s of 1 mark each and two coding questions of 100 marks each. Total time was 90
minutes. The MCQ’s were from subjects such as Data Structures, Networks, Operating
systems and a few shell command questions. The HR said that there was a separate cutoff
for the MCQ’s. The two coding questions were
1. Given a string, find the longest sub-string such that the sub-string has unique letters.
2. Given a matrix, find the sum of the sub-matrix between two given points.
The results were announced the next day. There were 4 technical rounds:
All rounds had similar questions such as “Tell me about yourself”, “What do you know about
Amazon”, “Why amazon”, “Do you have something you want to ask me” , “Strengths and
weaknesses” and few other HR questions. The main focus of each round were the problems.
First we have to solve the problem and explain out idea to the interviewer, and he may
suggest modifications and improvements. After that we have write the code for the same
(on parer). While writing the code take care to not to make too many corrections, start
writing the code only after getting a clear idea of what to write.

Round 1:
Problem 1: Given a binary search tree, find the k th smallest element.
Problem 2: Given a matrix which is sorted both row wise and column wise, search for an
element.
Round 2:
Problem 1: Given a linked list, find and remove all the loops.
Problem 2: Construct a minimum spanning tree from a given weighted graph. While
solving this I made use of certain “set” functions. As I didn’t know syntax of these
operations in C++, wherever I had to make use of set functions I wrote a “sudo” function
call. So after writing the code for the question, she asked me to implement the set functions

947
Chapter 396. Set 390 (On-Campus)

that I had used.

Round 3:
He didn’t give me any problems. The questions were mostly based on an SQL based project
that I had done, and on my internship.

Round 4:
Given a number, find the next higher number which is a palindrome. Example: if given
number is 99 next highest palindromic number is 101, if given number is 72 next highest
palindromic number is 77.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-390-campus/

948
Chapter 397

Set 392 (For SDE 2)

Amazon Interview Experience | Set 392 (For SDE 2) - GeeksforGeeks


Telephonic Round:
Q1: Question was a little tricky one but finally it was converted to Next greater Element
(https://www.geeksforgeeks.org/next-greater-element)
Q2: Given a Singly Linked list, Update the second half of the list such that n-th element
becomes sum(1st + nth) element, (n-1)st element becomes sum(2nd + n-1st) element and
so on. Eg: 2->3->4->5->6 => 2->3->(4+4)->(5+3)->(6+2)
Face to Face Interview:
Round 1:
Q1: Design the payment module of the Uber App.
Round 2:
Q1: Design Memory Management System and tell about all the data structures you will use
and why. How will you allocate and deallocate the memory using those data structure and
Time & Space complexity of the operations.
Q2: Given an array of words, print all anagrams together in the output array.
Round 3:
Discussion about the projects worked in previous company and how did you handle certain
situation occurred while working on the project.
Round 4:
Q1: You are provided with different Excel files and the data format those files contain. You
are also provided with low level parser. You have to design a system which takes the excel
file and its data type as the input and returns the list of Data objects in the file.
Round 5:
Discussion about project in previous company.
Q1: Design multiplayer generic board game (like chess or ludo)
Q2: You are provided with 2D char array. You have to provide the 2D char array as response
which contains the multiplication od the input array. For eg: input=> {{a,b},{c,d}}, output
=> {{a,c},{a,d},{b,c},{b,d}}
All Practice Problems for Amazon !

949
Chapter 397. Set 392 (For SDE 2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-392-sde-2/

950
Chapter 398

Set 392 (On Campus for


Internship)

Amazon Interview Experience | Set 392 (On Campus for Internship) - GeeksforGeeks
Online Coding Round:
The first round was an online round. There were 2 coding questions (no penalty for
wrong submission) and 20 Multiple Choice Questions(with negative marking). We
were given 90 minutes to solve them.
MCQs were based on Data Structures, OS, CN, C outputs, OOP etc.
The two coding questions were:
1. Given a string you have to partition it in such a way that each part of the partitioned
string is a palindrome in itself and you have to count the number of such partitions.
Input: NITIN
Output: 3
Explaination: The 3 possible partitions are N | ITI | N, N | I | T | I | N, NITIN
2. You are given a large paragraph and N words. You have to find a minimum length
subparagraph of the paragraph which contains all those N words in any order. Here, the
length of a paragraph is the count of words in the paragraph.

Round 1 (Face to Face):


The interviewer asked me to introduce myself and a brief introduction of the projects that
I have done. She first asked me questions related to my project. After that she moved on
to the data structures part. The questions were:
1. Merge Sort.
2. Given a BST containing distinct integers, and a number ‘X’, find all pairs of integers in
the BST whose sum is equal to ‘X’.
3. Merge overlapping Intervals.
The interviewer asked me to code all the problems on paper and dry run each of them for
some test cases.
Some questions asked to other candidates in this round were:
1. Find next greater number with same set of digits

951
Chapter 398. Set 392 (On Campus for Internship)

2. Given a binary tree, if parent is 0, then left child is 0 and right child is 1. if parent is 1,
then left child is 1 and right child is 0. Root of the tree is 0. Find the kth node value which
is present at Nth level.

Round 2 (Face to Face):


The interviewer asked me about how my previous round went. After that, he asked me to
introduce myself and a brief introduction of the projects that I have done. He first asked
me a few questions related to my project. Then he moved on to the data structures part.
The questions were:
1. He asked me about different types of hashing. He then asked me an alternative and a
better way for Linear Chaining.
2. Implement AVL Tree.
3. Minimum number of squares whose sum equals to given number n.
4. Insertion sort for a singly linked list.
For the second question, I told him that I don’t remember rotations in an AVL Tree so I
won’t be able to code it. Also, in this round the interviewer gave me strict time limit for
coding the solution on paper for each problem and as soon as I was done coding he gave me
2-3 minutes every time to find errors and debug my code.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-392-campus-internship/

952
Chapter 399

Set 393 (On Campus For


Internship)

Amazon Interview Experience | Set 393 (On Campus For Internship) - GeeksforGeeks
Online Coding Round:-
There were 2 coding questions and 20 MCQ’s.
1. Given an array find all the triplets having their sum of elements less than a given number
k.
2. Find The N-th Magic Number.
1st Interview Round(Face To Face) :-
The interviewer was very friendly. He went through my CV and asked me if I had any
project. To which I replied no and told him that I am currently on a project and later I
gave him a brief explanation of it. For those who didn’t do any project don’t worry much.
He asked me 2 questions
1) Generating All the Possible Subsets(Subset Iteration).
2) Slight Modification of BFS on a grid. I told him my approach and he was satisfied wth
that.
After I told my approach for the 2nd question he told me to write a Pseudo Code for BFS
in a graph.
He was the best interviewer I faced till now.
The interview lasted for around 45 mins.
Other people were given questions like
1) The middle element in a linked list.
2) Merge Sort in a Double Linked List.
3) Merge Two Sorted Arrays.
4) Given A Binary Tree, For every Leaf Node print sum of the values from the root node to
the leaf node.
5) Quick Sort
6) LCA in Binary Tree and Binary Search Tree.

953
Chapter 399. Set 393 (On Campus For Internship)

2nd Interview Round(Face To Face):-


This interviewer was also very friendly. He also had a good knowledge of Coding. He asked
me how was my previous round, I replied that it went well. And later he asked me what
questions I was asked in the previous round. I told him the questions which I was asked in
the previous round and also I explained their solutions.
He asked me 2 questions.
1) Print the Binary Tree in A Spiral Order.
2) lli stands for long long int in this question.
He gave me a question in the form of a function. And here goes the question.

// a1(size1) and a2(size2) are arrays and you


// have to append them.
lli* Append(lli* a1,lli* a2,lli size1,lli size2)
{
      
}

Simple But Wrong Solution

lli* Append(lli* a1,lli* a2,lli size1,lli size2)


{
    lli a[size1+size2],i;
      
    for(i=0;i<size1;i++)
    {
         a[i]=a1[i];
    }
 
    for(i=0;i<size2;i++)
    {
         a[i+size1]=a2[i];
    }
      
    return a;
}

I told him that the above code actually fails. He asked me why it fails. I answered him
this way.The array a is actually in the function Append and once you leave the function the
scope of this array ends. He asked me how to do it then. I had no idea. Later he told me
that we have to allocate memory for the array using malloc.Later on he explained me how
it works using heap memory.
For my friends, he asked the question in a different way(Merge Two Sorted Arrays).
Thanks to GeeksForGeeks For my interview preparation.
All Practice Problems for Amazon !

954
Chapter 399. Set 393 (On Campus For Internship)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-393-campus-internship/

955
Chapter 400

Set 394 (On-Campus Full Time)

Amazon Interview Experience | Set 394 (On-Campus Full Time) - GeeksforGeeks


Amazon visited my campus in August 2017. Apart from online screening round, there were
4 technical rounds – 3 F2F and 1 telephonic.
The online round was hosted in HackerEarth platform. It had 20 MCQ’s of 1 mark each
and 0.25 negative mark and 2 coding questions of 10 marks each. The MCQ’s was mostly
from Data Structures and Operating Systems, and few questions from networking, DBMS
and 1 Java question.
Round 1:
In this round, the interviewer didn’t look at my Resume and moved on to technical problems.
1. Given an array with integers first increasing then decreasing order, you have to search
an element in O(log n).
2. Given BST with 2 nodes being swapped with each other, find these 2 nodes.
3. Reverse singly linked list using both ways- iterative and recursive.
Round 2:
Interviewer asked me to introduce myself then to explain one specific project(pointed by
him) in detail. Then he asked me 4 questions.
1. Given integer matrix, have to find total connected components, connected in such a way
that adjacent numbers should have the absolute difference of 1.
2. Find next greater element of each element in array
3. Given a graph with edge weights of 1 or 2, have to find minimum distance between a
source and destination vertex.
4. Given array having integers showing the burst times of processes, I am given 3 threads to
complete all processes and a thread takes exact time to complete a process equal to its burst
time, I have to assign some contiguous processes to threads such that maximum among the
total time of all threads is minimum.
Example: 9 10 9 8 7 9 then 3 threads can be assigned as (9 10), (9 8), (7 9).
As I had to code the first 3, the interviewer probably noticed me being tired, he only asked
me the algorithm for 4th one.

956
Chapter 400. Set 394 (On-Campus Full Time)

Round 3:
Here, the interviewer first introduces herself and then asked about me, then told me to
explain any one of my projects. After that she asked me few basic computer science questions
followed be 2 DS/Algo problems.
1. How are recursion and iteration handled by the compiler.
2. How differently are a linked list and array stored in memory.
3. Difference between multiprocessing and multithreading.
4. All normal forms in DBMS.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-394-campus-full-time/

957
Chapter 401

Set 395 (On-campus for


Internship)

Amazon Interview Experience | Set 395 (On-campus for Internship) - GeeksforGeeks


Round 1: Total of 300 students participated in the notion of getting selected to do intern
at Amazon.
Round 1 had 20 MCQs and 2 questions.
Qs1: Given a range [L,R] find the count of numbers having prime number of set bits in
their binary representation. [This hint was included in O/P section. Only even numbers
should be checked within the L,R range]
Examples:

Input : 6 10
Output :2
6 -> 110 (2 set bits, 2 is prime)
10->1010 (2 set bits , 2 is prime)
so 6,10 are even numbers having prime number of set bits
(Use the optimized way to check prime by creating a array
of prime numbers and trying to divide the setbit count
to check if it is prime or not).

Qs2: Given n lines a land can be split into many areas of different measure(say b). You are
provided with a constant K . You have to find whether it is possible to use K areas from
the B areas

Input : 2 4
Output : True
Think of a circle whenever a circle is split by

958
Chapter 401. Set 395 (On-campus for Internship)

a n line the total number of areas is given by n*2


so the answer will be if(n*2>=k||n+1==k) return True.

Total of 30 students moved to the next round.

Round 2:
It was a group fly round . Me and my friend sat in the same room and were asked to code
the following:
QS 1: https://www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/
But I dint use a stack I used hashmap to find the occurrences of the characters. Created a
character array traversed the map with an iterator.Filled the character array with elements
in odd positions then after all odd positions are filled I filled in the even positions. Used a
validate function to check whether the newly generated string has no adjacent characters
repeating. If false print no string can be formed else return the string.
Qs 2: Given a tree and a element K . Find the root-leaf path with a sum equalling K and
delete the path.
Total of 10 were shortlisted.
Next was the final round. It was F2F round .

Round 3:
The interviewer asked me give a brief introduction about me.
Then he moved on to shoot coding questions at me.
QS1:
Find the intersection elements in 2 unsorted arrays.

Input: 5 4 1 3 2
12 3 15 1 7
Output: 3 1

Brute force : O(n^2)


so he asked me to code in optimized way.
Gave me three constraints
size of arr1,arr2 is m,n
what to do when m<<n(negligible),n<<m,m approx eq to n?
I said when m or n value is negligible we can sort the array of lesser size and make a binary
search
sort takes O(nlogn) and binary search takes O(logn) but as the array size is negligible
sorting won’t cost much.
when they are equal(or approx) then push all elements to a set then search(O(logn)) , Here
we dont use sorting since the array size is going to more or less same, we use more space
thereby decreasing the time complexity , anyway the searching time is be the same.

QS2: This was an interesting question . Given Air tickets to different cities in the
form of a pair of cities where one denotes the source and another tells the destination.Our
job is to return a linkedlist indicating the way the travelling should travel in order to cover
all the cities.(Linkedlist wasnt mentioned by the interviewer).

959
Chapter 401. Set 395 (On-campus for Internship)

Input: (Chennai,Bombay) (Bangalore,Goa) (Agra,Chennai) (Bombay,Bangalore)


Output Agra->Chennai->Bombay->Bangalore->Goa

Soln: Put them in a hashmap. Now find the occurrences of all cities. In this we can notice
that the source and destination occurs only once in the tickets.Cross check with the original
pair list to find which one is the source and which one is the destination. Then with the
help of a separate comparator function push the pairs into a new hashmap in such a way
that the source of one pair must have been the destination of the previous pair).Then
traverse the new hashmap to create a linked list then return it.

The interviewer will also help you if you ask for any approach (but don’t ask them
for more help.) But if the interviewer intentionally gives a clue then code as he wishes as
it is one of their way to test you whether you can adapt to anything approach and code.

Results were out and 8 people got internship.

Luckily I was one among them.

My personal advice: Be confident, Keep your communication skill high , use geeks-
forgeeks website to learn linked list ,Trees, STL and DP then solve all Company specific
questions.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-395-campus-internship/

960
Chapter 402

Set 396 (For SDE-2)

Amazon interview experience | Set 396 (For SDE-2) - GeeksforGeeks


Round 1:-
Design JProfiler. How will you design datastructure and why, function stacktrace.
HLD+LLD
Design Cricket Score Board HLD+LLD
Round 2:-
Design DataStructure Insert, Delete, Search, findMin, findMax, DeleteMin, DeleteMax with
minimal complexity. How will you tradeoff multiple operation to support mutiple operation.
Classes should be extensible , if you are using some data structure to support these operation.
Design Multiplayer Chess Board Game LLD only, without drawing HLD.
Round 3
Algo+Problem Solving
1) WildCard Matching, slight change * is replaced by +. Cover all corner cases. Write
Code.They checked line by line.
2) Copy linked list with random pointer with using O(1) space. Approach only
3) Calculate Top K frequent number from the running stream of data.
Round 4
Lots of behavioral question.
1) Design a Fresh Grocery System. Means Daily usable Items, you cannot store them in
inventory like bread, milk etc.
HLD+ DB Schema + Concurrency issues + Scalable architecture. How will you scale to
multiple countries
2) Design an Online tracking system, similar to how you can track your order on swiggy
after you place it on maps.
Round 5
Behavioral Questions
Full Project Discussion

961
Chapter 402. Set 396 (For SDE-2)

Design Recommendation system. How will you generate generate recommendations for
millions of users. DB Schema, How will you improve latency? if the user is searching a
item, when will you show next recommendations. How will you update, latency basically
and consistency.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-396-sde-2/

962
Chapter 403

Set 397 (On-Campus)

Amazon interview experience | Set 397 (On-Campus) - GeeksforGeeks


Online Round:
It consisted of 20 mcqs and 2 coding questions. The test was hosted on HackerEarth.

1. Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome)

Input: NITIN Output: 3

2. You are given with a large paragraph and N words.You have to find a min length
subparagraph of the paragraph which contain all those N words in any order.
Round 1 (35-mins):
The interviewer started with the most common questions “Tell me about yourself” , in which
I explained my projects , my achievements and my strengths. I was asked 2 questions from
ds and algo in this round.

1. Find all the hero and super hero in an array. Hero – Elements which are greater than
all the elements on its right side. Super Hero – Elements which are greater than all
the elements on its left and right side (Largest Element of the array which should only
occur once). Expected Complexity – O(1) space and O(n) time in single traversal.

Input: {1,6,5,4,7,8,4,3,2,1}
Output: Heroes : 8 4 3 2 1
Super Heroes : 8

2. https://www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-
characters-of-another-string/
Round 2 (60-mins):

963
Chapter 403. Set 397 (On-Campus)

I was asked to introduce myself asked about my strengths and my weakness. Like last round
I was asked 2 questions on data structures and algorithms.
Discussions on projects for 15-20 minutes.

1. Find Maximum number possible by doing at-most K adjacent swaps. Expected Time
Complexity – n*K and space complexity – O(1)
2. Find the closest pair to a given sum in an unsorted array. Approaches – Brute force,
Sorting , Ceil and floor using BST.
3. Memory Allocation in C++. How to allocate double memory in c++. Couldn’t
Explain this.

Was called for 3rd round after 5 mins.


Round 3 (90-mins):
This round was purely on algorithm design and data structures.

1. https://www.geeksforgeeks.org/design-a-stack-that-supports-getmin-in-o1-time-and-
o1-extra-space/

Couldn’t derive this for O(1) space.


2. https://www.geeksforgeeks.org/how-to-determine-if-a-binary-tree-is-balanced/
3. https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-
array/
Explained O(n^2) dp approach. Gave a segment tree approach of time complexity O(nlogn)
, space O(nlogn).
4. https://www.geeksforgeeks.org/find-first-non-repeating-character-stream-characters/
Implemented using Double Linked List and Hashmap.
Was called for the final round after 5 mins.
Round 4 (30-mins):
The round started with discussions on Operating Systems and Compiler Design.
Operating System Questions-

1. What is caching ?

2. Where does cache lie in operating system ?


3. Difference between associative mapping and direct mapping in cache.
4. What is spooling ?
5. Applications of spooling.

964
Chapter 403. Set 397 (On-Campus)

Compiler Design Questions –

1. What is lexical analysis ?


2. What is semantic analysis ?

3. What is a Deterministic Finite Automata (DFA) ?


4. Difference between DFA and NFA ?

Exhaustive discussion on my current projects.


Finally 3 questions were asked on data structures and algorithms.

1. https://www.geeksforgeeks.org/minimum-time-required-so-that-all-oranges-become-
rotten/
2. https://www.geeksforgeeks.org/fix-two-swapped-nodes-of-bst/
3. https://www.geeksforgeeks.org/bottom-view-binary-tree/

Verdict : Selected �

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-397-campus/

965
Chapter 404

Set 398 (On-Campus)

Amazon interview experience | Set 398 (On-Campus) - GeeksforGeeks


The online round was hosted in HackerEarth platform. It had 20 MCQ’s of 1 mark each
and 0.25 negative mark and 2 coding questions of 10 marks each. The MCQ’s was mostly
from Data Structures and Operating Systems, and few questions from networking, DBMS
and 1 Java question.
After clearing online round there were 3 technical round and 1 bar raiser round.
Resume was taken before interviews.
Round 1:
In this round, the interviewer asked about my coding and scholastic achievement.
1. Favorite subject and questions on that topics.
2. Basic question on space and time complexity
3. Write a program to print all permutations of given string and discuss its working as well
as space and time complexity in detail. https://www.geeksforgeeks.org/write-a-c-program-
to-print-all-permutations-of-a-given-string/.
4. Write a program to find number of shapes in Boolean matrix. https://www.geeksforgeeks.org/find-
number-of-islands/. He asked me about time complexity and space complexity. At the
beginning space complexity of my solution was O(mn). I presented 4 methods and reduced
its complexity to O(1). I solved it by both dfs and bfs.
Round 2:
In this round, the interviewer asked me to introduce myself and short discussion on my
resume project
1. Write a program for Lowest Common Ancestor in a Binary Tree. https://www.geeksforgeeks.org/lowest-
common-ancestor-binary-tree-set-1/.
2. Write programs for Fractional Knapsack and 0/1 knapsack code of recursive solution and
its optimization (concept of dynamic programming). https://www.geeksforgeeks.org/knapsack-
problem/.

966
Chapter 404. Set 398 (On-Campus)

3. Write a program and approach for Minimum no. of iterations to pass information to
all nodes in the tree. https://www.geeksforgeeks.org/minimum-iterations-pass-information-
nodes-tree/. I was very close to the solution and he was very impressed by my approach of
recursion. He interrupted me between the solution and asked further questions.
4. Approach for K smallest element in array. https://www.geeksforgeeks.org/k-largestor-
smallest-elements-in-an-array/. I presented 3 solutions and heap solution then he asked me
about heap and its time and space complexity.
5. Approach for Largest Rectangle in Histogram. https://www.geeksforgeeks.org/largest-
rectangular-area-in-a-histogram-set-1/. I presented two solutions naïve solution and stack
based solution.
Round 3:
In this round, the interviewer asked me about my resume project and deep discussion on
my projects.
1. Write a program to find position of an element in a sorted array of infinite numbers.
https://www.geeksforgeeks.org/find-position-element-sorted-array-infinite-numbers/. I pre-
sented 3 solutions in most optimized way.
2. Question on computer science fundamentals. Detailed explanation of virtual memory,
paging page faults etc.
3. Write a program for Minimum Number of Platforms Required for a Railway/Bus Station.
https://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/.
4. Write a program to count set bit of a number. https://www.geeksforgeeks.org/count-
set-bits-in-an-integer/. I presented 3 solutions and he was impressed by my last solution of
using concept of last bit set using formula x&-x.
5. Last question similar to the concept of this question sort numbers stored in different
machines. https://www.geeksforgeeks.org/sort-numbers-stored-on-different-machines/.
Round 4:
This round was based on designing problems.
Min Cash flow among friends. https://www.geeksforgeeks.org/minimize-cash-flow-among-
given-set-friends-borrowed-money/. I solved by n^2 and nlogn complexity. In nlogn I used
the concept of heap.

In each round interviewers were giving test cases to run on the programs and expecting very
neat and clean code.
So I would recommend to have experience of competitive coding for depth knowledge of
code and then follow geeksforgeeks. It has all the problems.
Before 2-3 of campus recruitment I would recommend to solve all problems of interviewbit
with the help of geeksforgeeks.
All Practice Problems for Amazon !

967
Chapter 404. Set 398 (On-Campus)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-398-campus/

968
Chapter 405

Set 399 (On Campus for full


time)

Amazon Interview Experience | 399 (On Campus for full time) - GeeksforGeeks
Amazon came to my campus in the last week of July, 2017.
The online round was hosted on HackerEarth platform.
It had 2 coding questions and 20 MCQs.
Q1. Given an unsorted array A, find the largest value of i-j such that A[i]>A[j].
Q2. Given an unsorted array A and a number k, find the maximum sum sub string in the
array such that its sum is divisible by k.
MCQs:
1 mark each and 0.25 negative mark.
Few MCQs were based on data Structures, algorithms, oops and operating Systems, 1 or 2
from logical reasoning, networking and DBMS each.
Every interview round started with the cliche “tell me about yourself” and ended with “do
you have any questions”.
Round 1:
Design Question : Given a log file with product id and corresponding customer id for the
products searched on amazon, you need to find the most viewed product at the end of the
day. If a product is viewed multiple times by a single customer its view count is increased
only by 1. Number of products are very large so sorting, heap or hashing of product Ids is
not feasible.
Solution- Use Trie data structure. After 10 minutes of discussion I could come up this.
Production level code for insert and search in a trie was required.
What if k max viewed products were required.
During my discussion he also asked me to write a hashing function.
Round 2:

969
Chapter 405. Set 399 (On Campus for full time)

1. Dfs of a graph.
Dfs of a n array tree. (Code was required)
2. Given a string s and a file with each word on a separate line, find all the words in the
file which are anagrams of the string s. The interviewer asked me tell all the possible
solutions irrespective of the complexity. This continued for 10 min.
3. Given a m*n matrix find number of paths from (0,0) to (m-1,n-1), at every block we
either move 1 step down or 1 step right.
4. Print all paths for the above questions. A dp solution was required.

Round 3

1. Given a n*n matrix with distinct elements from from 1 to n^2, find minimum number
of bombs required to destroy all cells of the matrix. If we bomb a cell with value i, a
cell with value i-1 if 4 adjacent to it will also be destroyed. (Code was required)
What if the the numbers were not unique.
2. Find majority element in an unsorted array.
Find majority element in sorted array. (logN solution was required)
3. Print the elements of a tree diagonally.
4. Find shortest distance between two nodes of a tree where every node also has a pointer
to its parent node and we can also directly jump from a node a to node b, where b is
the mirror image of a and a and b belong to the two sub trees rooted at the root of
the given tree. The mirror image may or may not exist.
5. Find the time required to pass information from root to all the nodes of the tree. Link

The interviewer then asked me which other non coding subject do I like. I said os.
So he asked me several basic questions on OS.
What is-

1. os
2. thrashing
3. bdady anamoly
4. page fault
5. threading
6. multi processing
7. difference between threading and multiprocessing
8. scheduling algorithms

Round 4
The famous Amazon’s Bar Raiser Round
My internship experiences.
Detail discussion about my summer internship project.
What is your favorite algorithm and why.
Toughest thing you did in college.
What are some leadership principles you learnt during your summer internship.
What was the non technical thing you learnt at your internship.
This was a telephonic round and went on for 34 minutes.

970
Chapter 405. Set 399 (On Campus for full time)

I recommend every one to prepare from InterviewBit, Hackerearth CodeMonk, Hack-


errank, http://blog.gainlo.co/index.php/category/system-design-interview-questions/,
https://ashayraut.wordpress.com/interview-preparation-best-100/ and geeksforgeeks.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-399-campus-full-time/

971
Chapter 406

Set 400 (For SDE 2)

Amazon Interview Experience | Set 400 (For SDE 2) - GeeksforGeeks


Round 1 : Telephonic
1) https://www.geeksforgeeks.org/serialize-deserialize-binary-tree/
2) Rotate a M*N matrix by k elements in place.
Round 2 : Hiring Manager ( F2F )
general introduction about team and work.
Discussion on my project.
Design a Music Player application [ many use cases were covered ] eg : support for SD card
All class diagrams were required on a whiteboard
Round 3 : DS Algo Round
1) https://www.geeksforgeeks.org/topological-sorting/
2) https://www.geeksforgeeks.org/rearrange-a-given-linked-list-in-place/
Round 4 : DS Algo Round
Detailed discussion on project
1) https://www.geeksforgeeks.org/gold-mine-problem/
2) https://www.geeksforgeeks.org/vertical-sum-in-binary-tree-set-space-optimized/
Round 5 : System Design Round
Detailed discussion of project
Design a Distributed LRU Cache
Design Gmail – consider scalability , redundancy, brief discussion on CAP Theorem, class
diagrams,
Database schema ( SQL vs NOSQL) , how to handle attachments

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-400-sde-2/

972
Chapter 407

Set 401 (3+Years Experience


for SDE II)

Amazon Interview Experience | 401 (3+Years Experience for SDE II) - GeeksforGeeks
Recently I was interviewed for Amazon SDE II for Amazon Pay Team. Below are the
Questions :
.
.
Round 1 : (Written : Pen & Paper) (3 Questions)
Q1) Given a 1D Array. Return True if there exists an element where a[i]+a[j] = 0 && i!=j.
Reference : https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/
Input : arr = {2,-3,4,1,-6,-4,1}
Output : True
Input : arr = {2,3,4,1,-6,4,1}
Output : False
Q2) Related to Buy and Sell of stock and gain maximum profit. Only 1 unit to buy or sell
at a time.
Reference : https://www.geeksforgeeks.org/stock-buy-sell/
Q3) Given a Tree (it was a BST), replace the data of all nodes which have data >= the
node’s data.
Exactly Same problem : https://www.geeksforgeeks.org/add-greater-values-every-node-given-bst/
(Even the example was same from above link ;))
.
.
Round 2 : DS and Algo (F2F) (3 Questions)
Q1) Program for n’th node from the end of a Linked List
Exactly Same problem : https://www.geeksforgeeks.org/nth-node-from-the-end-of-a-linked-list/
Q2) Print min & max (both) of all subarray of size k
Reference : https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/

973
Chapter 407. Set 401 (3+Years Experience for SDE II)

Note : The reference link is just for min or max. Here we need both min and max in one
program.
Q3) Find the k most frequent words from a file (or a stream of input)
Exactly Same problem : https://www.geeksforgeeks.org/find-the-k-most-frequent-words-from-a-file/
.
.
Result : I was eliminated due to some basic mistakes I did (in Q3), which I just realized
after leaving the Interview room. It was a nice experience.
.
.
I would also like to share few more Questions those were asked to other candidates over
there :
Q1) Design Debugger (Asked to almost everyone in 2nd Round)
Q2) Design Uber App
Q3) https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
Q4) https://www.geeksforgeeks.org/connect-nodes-at-same-level/
Q5) https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/
.
.
The Interviewers were very friendly and helpful. They will help you whenever you get stuck
(with Hints), but they will also check how much grab you have on basics.
.
.
Thank You!!!… Hope this will help the aspiring candidates.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-3years-experience-sde-ii/

974
Chapter 408

Set 402 (Experienced for SDE


2)

Amazon Interview Experience | 402 (Experienced for SDE 2) - GeeksforGeeks


Round 1
Q1) Write code for Sudoku Validator in most optimal time and space complexity ?
Q2) Write a code to verify BST Tree and print non-compliant node.
Round 2
Q3) Find duplicate character in a String O(1n) time with no extra space.
Q4) Write code to do three-way partitioning similar to quick-sort.
Round 3
Q5) Design App-Store.
Round 4
Q6) Design Netflix .
Q7) Why Amazon ?
Round 5
Q7) Question specific to Resume and Software Process.
Q8) Question for Leadership principles.
Offered !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-402-experienced-sde-2/

975
Chapter 409

Set 403 (On Campus for Full


Time)

Amazon Interview Experience | Set 403 (On Campus for Full Time) - GeeksforGeeks
Codding round (90 min):
20 objectives from DS, OS, DBMS, Networking and 2 coding questions:
i. https://www.hackerrank.com/contests/dakshonline/challenges/yule-ball
ii. https://www.hackerearth.com/practice/data-structures/arrays/1-d/practice-problems/
algorithm/i-demand-trial-by-combat-13/
ROUND I:
1. Given a binary string (e.g. 01, 101, 011), in each iteration 0 becomes 01 and 1 becomes
10, find kth character in the string after nth iteration
simple approach, time complexity, express time complexity in terms of n only
efficient approach, explanation, time complexity
2. Given n ropes of different lengths, connect them into one rope. cost to connect two ropes
is equal to sum of their lengths. connect the ropes in minimum cost :
https://practice.geeksforgeeks.org/problems/minimum-cost-of-ropes/0
3. When and why merge sort is preferred over quicksort – time/space complexity
ROUND II:
1. Project discussion
2. Make binary tree symmetric – which all cases are possible, which traversal is used and
why
3. Make half of the linked list reverse (iterative, recursive) and some questions from linked
list
4. Recursion, data structure that is used in recursion
5. C++ string, overloading of + operator in string class
ROUND III:
1. Design a data structure to show most frequently purchased item to a customer, show
items that are frequently purchased in a given time span
2. Priority_queue, map/unordered_map, sliding window concept

976
Chapter 409. Set 403 (On Campus for Full Time)

3. Search a given word in a dictionary (approach, time complexity, cost of insertion/deletion


of new word in different data structures)
4. Binary search tree, AVL tree (Rotation, Insertion, Deletion), Trie data structure
5. Search a pattern in given string (Simple approach & Using KMP algorithm), handle all
the cases
6. LRU Cache Implementation
ROUND IV:
1. Introduce Yourself
2. Project discussion
3. Convert a given Integer to its corresponding Roman numeral
4. Hamiltonian cycle & few graph questions (Cycle in directed/undirected graph)
In between they asked some questions from OS, DBMS, Networking:
– Belady’s Anomaly, Context Switching, Conflict Serializability, Functions of some OSI-
layers etc..
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-403-campus-full-time/

977
Chapter 410

Set 404 (On-Campus


Internship)

Amazon Interview Experience | Set 404 (On-Campus Internship) - GeeksforGeeks


Online Round
It consists of 20 mcqs and two coding questions where MCQS got the negative marking ,
One for the correct answer and -0.25 for each wrong answer.
1.Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome)( Case – Insensitive )
Examples:

Input : NITIN
Output : 3

Input : AAa
Output : 4

Link for the following question


2. You are given with a large paragraph and N words.You have to find a min length sub-
paragraph of the paragraph which contain all those N words in any order.(Case Insensitive)
Only 33 students got selected for the next round
Round 2( Technical Interview )
First the Interviewer introduced himself and then asked me to introduce yourself
He gave me only one question
Given a positive number and you have to find all the no. that holds the property of all the
digits with absolute difference equal to 1 to its adjacent digit below that given number.

978
Chapter 410. Set 404 (On-Campus Internship)

Input : 40
Output : 10 12 21 23 32 34

I gave a brute force solution first and then he asked me to optimize it. We had a long
discussion then he asked me to code the solution.
Only 6 students got selected for the next round.
Round 3( Technical Interview )
The interviewer started with the most common questions “Tell me about yourself” , in which
I explained my projects , my achievements and my strengths.
The round started with long discussions on following Questions of Operating Systems.
1. What is deadlock? and situation where you have faced deadlock.
2. Scheduling Algorithms.
3. Code LRU Cache
4. Banker’s Algorithm.
5. Paging , Segmentation etc.
6. How compiler compiles the interlinked libraries.( Using Topological Sort ) and asked me
to code for the same.
One Coding was asked in last
Trapping Rain Water
In Last interviewer winded up the interview with “Any questions for me?”
Verdict : Selected
Only 3 students were offered internship
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-404-campus-internship/

979
Chapter 411

Set 405 (SDE-II)

Amazon Interview Experience | Set 405 (SDE-II) - GeeksforGeeks


Round 1: Online Coding Test (Duration: 1 hour 30 minutes)
Question 1: Given a matrix of n*n size, the task is to print its elements in diagonally
pattern.
Question 2: Lazy Bartender
There are N number of possible drinks.(n1,n2..)
Has C number of fixed customers.
Every customer has fixed favorite set of drinks.
Bartender has to create least possible number of drinks to suffice need of all the customers
Example:
Cust1: n3,n7,n5,n2,n9
Cust2: n5
Cust3: n2,n3
Cust4: n4
Cust5: n3,n4,n3,n5,n7,n4
Output: 3(n3,n4,n5)
Discussions about Lazy Bartender on Career Cup
The online coding round was supposed to be taken from home. HR shared the link and gave
3 days of time to attempt once and submit.
I solved first problem and got selected for Interview Process.
Round 2: Technical Round (Duration: 1 hour)
Question 1:
Next Greater Element
I started with naive approach and finally we discussed the solution using stack.
We also discussed about complexity of each of the approaches.
Question 2:
Interviewer: Do you know HashMap?
Me: Answered all the information related to HashMap. Explained how singly linked list is
maintained internally for each bucket. Discussed about complexity of insertion and retrieval.

980
Chapter 411. Set 405 (SDE-II)

Interviewer: Order of insertion is not maintained in HashMap. Write code to maintain the
order of insertion.
Me: We can directly use LinkedHashMap in Java. This Data Structure suffices the require-
ment.
Interviewer: How does LinkedHashMap work internally?
Me: Explained the internals of LinkedHashMap. Elaborated how it maintains doubly linked
list to maintain the order of insertion on top of HashMap mechanism. This is helpful to
know internals of Java Data Structures
Question 3:
Have you ever faced conflict in your team? For example, if your team member is trying
to implement sub optimal solution and you don’t want him/her to do so. How have you
handled this situation?
Question 4:
Largest Sum Contiguous Subarray
Discussion included naive approach, solution using maintaining single variable and complex-
ity of each.
For questions 1 and 4, interviewer asked me to write production ready code on paper.
Expectation included to cover all the corner cases and input check and all.
Round 3: Technical Round (Duration: 1 hour)
Interviewer: Tell me Data Structure of your choice. I’ll ask questions on that.
Me: Can we have questions on Linked List?
Question 1:
This interviewer also started with Hashmap. Again we had all the discussion which I had
in Round 3 Question 2.
Design your own Data Structure for LinkedHashmap and write production ready code for
insertion of elements.
Question 2:
Why Amazon?
Question 3:
Imagine we have a big box open at top and some small boxes are put inside it. The one of
the side view of the box be like.

Now, as shown in the image, currently gravity is acting downwards.


Some environment change happens and now gravity starts acting rightwards of the shown
image.
Let us consider initial data in an array. For example, the array content from the figure
would be [3,2,3,2,1,4].

981
Chapter 411. Set 405 (SDE-II)

Think of final positions of the all boxes (Final elements in array) and design algorithm to
solve the problem. We can just discuss the algorithm. No need to write code.
We discussed about final positions of boxes on paper and finally I figured out that it is
nothing but a sorting of array. I answered to have to go with Merge sort. Interviewer asked
me why not Quick sort? We discussed about complexity of both the algorithms and issues
occurring due to selection of pivot in Quick sort.
Round 4: Design Round (Hiring Manager) (Duration: 1 hour)
Question 1:
Interviewer asked me to choose area from which he can ask design question.
1. Online Gaming
2. Inventory Management
3. Taxi services like Ola, Uber.
I chose second option.
Interviewer asked me to Design automated parking lot
We started with classes to be used. Discussed database structure. Many other aspects like
what if I own many parking lots. What if only one vehicle is coming at a time? What if I
have multiple lanes to enter parking. What if many vehicles are coming at a given time?
We discussed synchronization of thread, thread pooling, thread queuing.
Question 2:
Tell me about your current work.
Round 5: Behavioral Round, Bar raiser (Taken by two highly experienced peo-
ple) (Duration: 1 hour)
Question 1:
Introduce yourself.
Question 2:
Discussions about my previous project with previous employer.
Question 3:
1. Discussions about my current work with current employer. They asked me complete in
and out about my current project. I answered the question with inclusion of many design
patterns which are implemented in my project.
2. Tell us something which you have contributed to project. I had implemented some IPC
on the top of available framework. They asked me how IPC work internally? How will you
implement it if infrastructure is not provided. I explained the OS concepts behind IPC.
3. If trade off needs to be done on quality of product being released or to follow release date,
which one will you choose.
4. How do you handle conflict in your team?
Question 4:
Do you know furniture? If yes, design one. (Too vague question)
We discussed more about requirements as I was not clear about it at all. Came up with
some classes of furniture.
Write a SQL query to retrieve furniture from database whose dimensions(Width,Height,Length)
match with the given dimension. Initially, I wrote a strict SQL query to match exact
dimension. Then, interviewer asked me how Google search will work if you search for

982
Chapter 411. Set 405 (SDE-II)

furniture with above dimension. I answered that it gives other furniture with similar
dimension as well. I modified my earlier query to have something similar to Google result.
Result: I got selected.
Note:
1. Each interview started with brief introduction of the interviewer and mine.
2. Each interviewer was friendly and supportive. There was no pressure, tension at the
time interview. It was like a normal technical discussion. Interviewer gave hints to find the
answers whenever required.
3. We discussed about interviewer’s work at Amazon in each round.
4. After every round, I asked for area of improvement in me. Like it can be anything,
what should I read more, which skill should I develop. (It is not something about interview
feedback, as I know that it is always kept confidential from interviewee).
5. Don’t start solving problem as soon as interviewer gives you one. Ask questions if you
are not clear about the requirement.
6. Round 5 was meant for checking interviewee’s behavior in different situation.
7. Most of the times, interviewer is not expecting the correct answer but is evaluating your
thought process. Keep talking whatever is going on in your mind. Most important prepare
your resume very well.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-405sde-ii/

983
Chapter 412

Set 406 (Off-Campus


Internship)

Amazon Interview Experience | Set 406 (Off-Campus Internship) - GeeksforGeeks


Round 1:
The first round consists 20 mcqs and 2 coding questions. The MCQ’s are focused mainly
on Operating systems, data structures and algorithm analysis and DBMS.
each question consists +1 and -0.25 for the wrong answer
Round 2:(TECHNICAL ROUND 1)
It started with the self introduction and brief chat about Vizag(interview held in Vizag).
He is so friendly and encouraging
question 1: Rearrange nodes in the given linked list as follows

input : a -> b -> c -> d -> e


output: a -> e -> b -> d -> c

https://www.geeksforgeeks.org/rearrange-a-given-linked-list-in-place/
question 2: Given an array of integers, print pairs(positive value and negative value of
the number) that exists in the array

input : [1, -3, 2, 3, 6, -1]


output : [-1,1]
[-3,3]

this round happened for one hour


Round 3 (TECHNICAL ROUND 2):
This round started with discussion on projects and then questions on technical concepts like

984
Chapter 412. Set 406 (Off-Campus Internship)

1. deadlocks
2. mutex vs semaphores
3. ultithreading vs multiprocessing
4. TCP protocol
5. DNS
6. 3-way handshake in TCP
7. discussion on OSI layer
8. ACID properties
9. models in DBMS(ER, network….)
10. discussion on ER model

then he started coding part :

1. given row wise and column wise 2d matrix, find k minimum elements

https://www.geeksforgeeks.org/kth-smallest-element-in-a-row-wise-and-column-wise-sorted-2d-array-set-1/
2. given an array and a window size and window moves from left to right till the rightmost
side of window hits the other side of array, print max element in the window for
each step in the process
https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
this round happened for two hours

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-406-off-campus-internship/

985
Chapter 413

Set 407 (Internship)

Amazon Interview Experience | Set 407 (Internship) - GeeksforGeeks


this was a pool campus conducted by amazon for internship .based on the internship per-
formance students will be give pre-placement offers or pre-placement interview.
online round: online round was conducted at respective colleges in batches…there were
20 technical mcq’s on DBMS, OS, CN,C, OOPS,DS,input/output questions, mostly from
geeksquiz and 2 coding questions which were considerably easy.time given – 1 hr 30 minutes.
1. given a point (x,y) which is position of a friends house on a coordinate plane. and a
person starts from(0,0),and can move only on x-axis. each time he moves double the steps
from previous step and in opposite direction.he starts by taking 1 step in positive x axis.
each step he takes 1 second. given a time n. we have to find the distance between his friends
house and his position after n seconds.
2.given a string and an integer m that denotes number of changes that can be made on the
given string.we have to find maximum length of a sub string that can be formed by doing
m number of changes such that all alphabets in the substring are same.
Online was conducted on hackerearth platform. MCQs had negative marking +1 and -0.25.
there was no detection of points for wrong submission in coding questions.
From my college 13, students were selected for 2nd round, and in total 70 students from my
city.they did not reveal any cut off criteria but student who solved atleast 1 coding question
completely and atleast 8 to 10 (just an assumption) mcq’s correctly were selected for next
round.
Round 1: This was face to face technical interview coducted for all the colleges
together. they gave 2 questions and we were asked to write the entire working
code and to optimize the solution, the interviewers were friendly and helped
us if we got stuck anywhere.after this round 30 students were selected for next
round out of 70.

1. https://www.geeksforgeeks.org/write-an-efficient-c-function-to-convert-a-tree-into-its-mirror-tree/
2. https://www.geeksforgeeks.org/print-binary-tree-vertical-order

986
Chapter 413. Set 407 (Internship)

this round took around 1 hr 15 min.


Round 2: This round was also a face to face technical interview.the interviewer
asked me to introduce myself while he was entering some details in his lappy.then
he asked me who took my 1st round. i din knew the name of my 1st round
interviewer.he was smiling and said “relax, i was just casually asking”. i was
given 2 coding question. for the 1st question he just asked to explain the
approach and optimize it and for the 2nd question he asked to write the entire
working code and explain it.this round took around 45 min.
1.given an array we have to find the median of the array when it is sorted but we should
not sort it.
2.https://www.geeksforgeeks.org/find-maximum-possible-stolen-value-houses/

Round 3: This round was conducted only for those students for whom they were doubtful.
fortunately i was selected in 2nd round itself.

Interviewers were friendly. They helped us giving hints wherever we got stuck.
My advice is be confident. don’t give up, if you are stuck anywhere. Tell them atleast a
brute force approach and they will give you hints to optimize it. Don’t be scared, practice
questions from geeksforgeeks, almost all of them were asked from geeksforgeeks collection.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-407-internship/

987
Chapter 414

Set 408 (Internship)

Amazon Interview Experience | Set 408 (Internship) - GeeksforGeeks


Most importantly they look for
1. Problem solving skills i.e. algorithm
2. Coding skills
3. Knowledge of DS
Round 1:
The round 1 consisted of 20 MC Quizzes which are of GATE level and two coding questions.
As far as I remember the first coding question’s logic was to find GCD of an array of number
which I solved using recursive approach.
I cleared the round 1.
Round 2:
It was a F2F round where 3 members were assigned to a particular member. They gave us
2 questions and write the pseudo code for them in 1 hour during which we also can interact
with them.
I asked them where I had doubt and after I say logic to him he asked me that if I can
optimize it, explain the code so on.
As I gave him all the optimisations he asked algorithmically , I was not able to write a clean
code because of lack of time.
I selected as 8th candidate.
Round 3:
This was also a F2F round and it is one to one. Where his first question was that why did
I not write any code in previous round and then asked ” Tell me about yourself”
Then he shooted me with coding questions. His first question was a popular question(which
I came to know later) rainwater problem, and the next one was printing the nodes of a
binary tree in zig Zag manner.

988
Chapter 414. Set 408 (Internship)

Then he asked me some questions from OS i.e. internal fragmentation vs external fragmen-
tation to which I replied “I don’t remember the topic but please let me try” then I got
correct answer to one question and wrong to second one. Then he asked about process life
cycle.
Then he asked that if I have any questions and then he asked ” why Amazon?” That was
it.
We were said to wait and luckily I was selected.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-408-internship/

989
Chapter 415

Set 409 (For SDE-I)

Amazon interview Experience | Set 409 (For SDE-I) - GeeksforGeeks


Telephonic round:
https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-k-times/
Round 1:
You have two lane road and there are two sensors,

1. Sensor A only covers Right lane.


2. Sensor B covers both Left and Right lane.

Input of the function is two arrays filled with 24 hours of data and value/item of array is
tuple having direction and time. find following things,

1. Total no of cars on Right and Left lane.


2. Min and Max speed at sensor A.
3. Min and Max speed at sensor B.

Finding no 1 is easy.
Only issue is with 2,3 as we don’t have any unit of distance given anywhere. I asked him he
told that’s a problem ?
This what we can do without distance we can at-least find the minimum and maximum
time for sensor A and B just traversing an array but after that finding a distance that’s still
a mystery to me ? in last few minutes he told me take a guess and do it but no enough
time.
Round 2:
Build an UBER platform no code discussion about how will you do it,

1. How will handle locations (most updated) of the driver ?


2. How will update the location of the driver (architecture of app or service to update) ?

990
Chapter 415. Set 409 (For SDE-I)

3. Find nearest driver ? (We can filter all drivers based on location)
4. What if two cities are merged like Redmond and Bellevue then other car might be
close but in second city where city filter want work ?
5. How do you scale same app to other countries (like china) ?
6. One you find the nearest driver how do pick them ? (I said ratings)
7. What would do consider as good ratings ?
8. Once you have 10 driver with 4.8 ratings how will you send the request ?
9. What will you do if all 10 drivers receives and accepts 10 request simultaneously ?

Round 3:
Build Eclipse IDE. Told me to write down class diagram of all components.

1. How will you handle Character Set ?


2. How will you handle up key ?
3. How will you handle code pre compilations ? different highlighting rules ?
4. Where will be text render events in editor or page and why ?

Round 4:
https://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/
No offer by the way.
In SDE-I two designing questions. I didn’t expected that. Even though i have done some
designing over past 2 years but never attempted problem as big as an IDE.
Hope this helps and PEACE.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-409-sde/

991
Chapter 416

Set 410 (On-Campus


Internship)

Amazon Interview Experience | Set 410 (On-Campus Internship) - GeeksforGeeks


Online Round:
It consists of 20 MCQs and two coding questions and MCQs got the negative marking . One
for the correct answer and -0.25 for each wrong answer.
1.Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome) ( Case–Insensitive )
Examples:

Input : NITIN
Output : 3

Input : AAa
Output : 4
https://www.geeksforgeeks.org/given-a-string-print-all-possible-palindromic-partition/

2. You are given with a large paragraph and N words.You have to find a min length sub-
paragraph of the paragraph which contain all those N words in any order.(Case Insensitive)
Only 32 students got selected for Personal Interviews Rounds.

Round 2(Technical Interview I):


First the Interviewer introduced himself and then asked me to introduce yourself.
He asked me 3 questions related to Data Structures and Alorithms.
Question 1: Given a n-ary tree print all the possible paths of the tree.

992
Chapter 416. Set 410 (On-Campus Internship)

Firstly I gave him the approach using queues. Then he asked me to optimize the code
for space complexity of O(1). Then I gave him the approach using recursion and a long in
depth discussion followed on it. Then he asked me to write the code.
Question 2: Given the no. of stairs as the input and a person can step forward either 1 or
2 or 3 steps at a time. Find the total no of possible ways person can climb the stairs.
Input : 3
Output: 4
Question 3: Given a 1-D array having equal no even and odd numbers. Arrange the numbers
in such a way that all the even no get the even index and odd no get the odd index. Required
space complexity and time complexity was O(1).
Only six students were selected for the next round.
Round 3(Technical Interview II):
This round was similar to the previous rounds. Firstly the Interviewer introduced himself
and then asked me to introduce yourself.
He asked me 2 questions related to Data Structures.
Question 1: Print all the continuous sub-arrays where the sum of the sub-array becomes
zero. Required space complexity was O(n).
Question 2: Given a string containing parenthesis. Find the total no of reversal of parenthe-
sis to make the given output as balanced one. This question followed a detailed discussion
and interviewer gave me different no of inputs to test the code.
After the coding questions. he asked me some basic questions related to Operating Systems
like Deadlocks and Semaphores.
At last 3 students got the internship offer from Amazon.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-410-campus-internship/

993
Chapter 417

Set 411 (SDE-1)

Amazon interview Experience | 411 (SDE-1) - GeeksforGeeks


Round 1:
It was F2F round(DS and algorithms). They asked about me and my experiences in previous
company. I have created couple of open source projects. Mentioning about them really
impress the interviewer if it is really a good one. Then he continued with some data structure
questions. I had two questions.
Question 1:
Given a tree asked to print the path of the tree which has the highest number of bends.
Then he modified the question and asked me to code for both.
Question 2:
Given a tree with each node having numbers. Path from root to a leaf node forms a number
like (root(1)->left(2)->leftLeaf(3) = 123). He asked me to code to add all the number for
root to leaf.
This round went pretty well.
Round 2:
It was F2F round(Problem solving). There were two interviewers. They directly went for
the process after introducing them. This round had 5 questions and was bit hard.
Question 1:
Given 2D array for characters and a string, asked to find whether the string follows the
pattern of the dictionary. I will explain the pattern below.
2D array
|a|b|c|
|b|c|a|
|b|b|a|

994
Chapter 417. Set 411 (SDE-1)

String: bababbcac

The pattern is, the words in the dictionary should be present in the string in same order and
the letter taken by one word should not be the part of other dictionary word. We should
find whether all the dictionary words can be formed or not in the given string.
Answer:
Let me index the string bababbcac – (1,2,3,4,5,6,7,8,9)
1st word in dictionary – abc follows 457
2nd word in dictionary – bca follows 268
2nd word in dictionary – bba follows 134
Question 2:
It was from dynamic programming in string stuff

Source

https://www.geeksforgeeks.org/amazon-interview-experience-411-sde-1/

995
Chapter 418

Set 412 (SDE II)

Amazon interview Experience | Set 412 (SDE II) - GeeksforGeeks


Overall process time : 2 months(Sep’17 to Nov17)
Overall 60+ people
Total Rounds : 6
Overall Difficulty : 2.5 – 3
Round 1:
(3 codes on paper )

• Given a set of yesterday Amazon stock prices {2, -3, 5, 8, 1}


Write a code to buy and sell those stocks at maximum profit. Before sell, you must
buy it at minimum price. There should be one minute gap between buy and
sell. Gain maximum profit by buying and selling 1 unit (very simple need to find min
and max, I did it using thread join)

• Convert a BST to a sum tree


• Given a 1D Array. Return True if there exists an element where a[i]+a[j] = 0 && i!=j.
Reference : https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/

Input: arr=(2,-3,4,1,-6,-4,1}
Output: True
Input: arr={2,3,4,1,-6,4,1}
Output: False

Round 2:
Regular Expression parser like finite state automata
Example: a*, aab*, abcb*c, ba*.c*, a.b, a*b etc etc and edge cases
Design a ranking system. We have an infinite supply of words ending with ‘.’ We need to
implement a reader program that ranks words on the basis of certain criteria

996
Chapter 418. Set 412 (SDE II)

• Example: This is my cat.


• This house belongs to my uncle
• An amazing country with so many tourist places And so on..

Ranking System criteria : rank the words on the basis of occurrence, for example
Output : This:2, is:2, my:2… highest rank (sorted asc or desc based on provided flag)
Design it completely and scalable Ranking System.
Design a debugger
Round 3:

• Explain your greatest accomplished project and what big you achieved? – Details of
flow and architecture
• Find a longest palindrome String
• Design Amazon Cart System. (HLD and LLD ) Discussion on solution.

Round 4:

• Given a Binary Tree, Replace every node with its larger Same as sum tree
• Print min & max (both) of all sub array of size k
Reference : https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
• Given an integer array and find first k largest elements. Focus was on complexity of
the code
• Given an integer array and an integer value X, return three elements in that array
such that sum of them equals to X.

This was the last round for the day as team had to return to Bangalore. HR shortlisted me
along with other two candidates. Due to Diwali they were falling short of staff for managerial
rounds, So it look a month for other two rounds which happened in their Gurgaon office on
VC
Round 5:
Bar Raiser: (Duration : 1.15 hours)

• Tell me about yourself


• What were the important projects you have worked on
• What was your contribution
• Explain Architecture, Design and detailed discussion
• What were challenges you faced and how did you solve them
• Design a notification system “In Shorts”

Round 6:
Hiring Manager : (Duration : 1.15 hours)

• Introduction & very detailed project discussion

997
Chapter 418. Set 412 (SDE II)

Behavioral Questions –

• Did you encounter any conflicts with colleague or manager and how did you solve
them
• Have you ever delivered more than expectations
• Have you ever completed project before deadline
• Have you have handled a client/customer efficiently and what did you
• Did you ever design a system/process
• What were the most critical projects you have worked on
• How did you handle a critical situation or helped a colleague
• Tell me about a time when you had to work on a project with unclear responsibilities
• Have you mentored someone? What were challenges you faced and how did you resolve
• What important technical decisions did you take and how did it help your team?
• Why Amazon

I recommend GeeksForGeeks for technical coding rounds, educative.io for design and http:
//kraftshala.com/how-to-raise-the-bar-in-the-amazon-interview/ for behavioral.
Pretty much covers all the details. They announced result after a week and I was selected �
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-412-sde-ii/

998
Chapter 419

Set 413 (SDET-1 On-Campus


Internship)

Amazon interview Experience | Set 413 (SDET-1 On-Campus Internship) - GeeksforGeeks


This was a pool campus conducted by amazon for internship.
Online Round: There were 20 mcq(+1 for each) and 2 coding questions(+30 for each).
MCQ had more networking and DS problems.
1. Given three linked list, add them.
Input will be of this format
1->0->1
8->9->9
5
Output: 1->0->0->5
Solving above problem in python is easier than C++. I solved it in C++ using deque(30/30
points).
2. Given an array of size n consisting of positive integers, choose three integers(not nec-
essarily contiguous) such that they are in ascending order and their product is maximum.
Input was given in this format.
array = {5, 3, 6, 8, 9, 10}
Output: array = {8, 9, 10}
Many people(including me) ignored the ascending order part and got 20/30 points. Later
during interview, interviewer asked me to explain my code and told me the corner case.
Note: Input was given exactly like I said in both problems. It was a bit different from usual
problems. You first have to break strings to integers then solve the problem.

999
Chapter 419. Set 413 (SDET-1 On-Campus Internship)

Round 2:
https://www.geeksforgeeks.org/validity-of-a-given-tic-tac-toe-board-configuration/
This was on paper round. I have heard there is another easier solution using magic square.
8 were selected from this round.
Round 3:
Technical Interview Round 1
The interview started with the most common questions “Tell me about yourself” and
“Projects/Internship”. Then there were few theory questions like what is binary tree? What
is binary search tree? Then 2 coding questions.
1. https://www.geeksforgeeks.org/level-order-tree-traversal/
2. https://www.geeksforgeeks.org/find-next-greater-number-set-digits/
Instead of digits, it was string of alphabets. There was a bug in my code. Interviewer gave
me a test case and asked me to test it. Changed the approach and solved it by sorting. He
asked which sorting and why? First I said merge sort because of nlogn complexity. Then I
said since range is small(1-26), we can use count sort. He asked if we really need sorting?
Then I said that reversing the second part was sufficient because it was in descending order.
Round 4:

Technical Interview Round 2


Again discussion on “Tell me about yourself” and “Projects/Internship”.
1. https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
He first asked how will you solve this problem. Gave 3 different approaches. Then finally
asked to write code for deque approach.
I was asked few more theory questions from DS and DAA. Like what are some algorithmic
paradigm? Difference between Greedy and DP? Questions on Dijkstra(Complexity, greedy
or dp). And finally I was given a problem based on graph and was asked which algorithmic
paradigm will be used to solve it? Answer was backtracking.
Interviewers were friendly. They helped us giving hints wherever we got stuck.
My advice is read past interview experiences from GeeksforGeeks and practice those prob-
lems on GeeksforGeeks judge. Brush up your CS fundamentals like Data structures, Algo-
rithms, Networking and Database.
Thank you GeeksforGeeks for helping me during my interview preparation. �
All Practice Problems for Amazon !
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.
Improved By : Dushyant Singh 1, GeeksGeeks

1000
Chapter 419. Set 413 (SDET-1 On-Campus Internship)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-413-sdet-1-campus-internship/

1001
Chapter 420

Set 414 (For SDET-1)

Amazon Interview Experience | Set 414 (For SDET-1) - GeeksforGeeks


I applied through an employee referral for SDET-1 position. I was interviewed at Amazon
Chennai(SP Infocity).I faced 5 face to face rounds.
On October 11th, I faced the first round which was mainly related to problem solving and
coding.
Round 1:Problem Solving and Coding Round(1 hr)
The interviewer just started with a formal question of introduce yourself.Then she asked me
about my final year project which I clearly explained and sketched it on the board.
Then she asked me two coding questions.

1. Simulate an android pattern lock.


2. Generate all words that can be formed with the given pattern. The keypad specifica-
tion is the mobile keyboard.I will explain it clearly

If the given input is 2 3 6.


2 corresponds to abc. 3 corresponds to def. 6 corresponds to mno.
Suppose if we have to generate all combinations of 2,3,6 the output should be a set of strings
adm,adn,ad0,bdm,bdn,bd0,…..
I gave a recursive and an iterative solution to print the combinations.
Then the interviewer modified the question slightly.She asked me to validate the generated
strings with a dictionary.
I gave two approaches for maintaining the dictionary. First I suggested a hash table approach
which takes O(1) average time complexity for insert delete and search operations.
Then since the generated strings have common prefixes I suggested a trie approach for the
dictionary.

1002
Chapter 420. Set 414 (For SDET-1)

The interviewer was pleased with my solution and asked me to code the solution completely.
After a few days I had 2 face to face rounds.
Round 2:Testing and Automation round(1 hr)
The interviewer just started out by asking whether I had previous knowledge about testing
and testing environments to which I replied no.Then we discussed about the types of testing
and the different phases and the testing procedures that are associated with it. Then she
asked me two simple test case generation questions.

1. Generate all possible test cases for an add function which takes two strings as input
and returns an integer which is the sum of the two numbers that are given as string
input.

I gave around 10 test cases for the question as it was pretty much straight forward. And I
coded a few by using JUnit testing which is really simple.
2. Given a open file module in an editor what are the possible scenarios in which the open
file module might give errors.
I gave a list of cases which we clearly discussed about the ins and outs of each one.
This round was quite easy since I prepared the testing part the previous day.
Round 3:Data Structures and Algorithms Round(1hr 15 mins)
Two guys interviewed me this round. We just started out with a formal introduction.Then
they asked me two questions.

1. Knight walk problem.

Given a n*n chessboard and a knight which is placed at any one corner, Generate all possible
paths following which the knight can cover all the squares.
I started with a approach using BFS. But there was a flaw in my approach which was that
the knight would not escape from a cell if all the possible points the knight can go from that
given point was explored previously.
Then I gave a solution using Backtracking.
Start with a corner.For each and every possible point the knight can reach make recursive
calls to those using a simple for loop.Once the count reaches n*n(Example in a 8*8 chess-
board,if the count is 64),Print out the traversed path that can be easily maintained in an
array. This solves the flaw in my previous approach as we are able to go back to the other
possibilty if a dead path is reached.
The interviewer was happy with my approach and asked me to code the solution. I coded
it and then we moved on to the next question.
2. Given a linked list find the intersection point of two linked lists which converge at a
common point.
I gave a brute force O(n^2) approach at first then optimised it to O(n) time and O(n)
Space approach.Then I finally gave a O(n) time O(1) space solution by finding the absolute

1003
Chapter 420. Set 414 (For SDET-1)

difference of the lengths of the two lists.Then they asked me to code the solution which was
pretty much straight forward.
After this I had the final two rounds on October 31st.
Round 4:Hiring Manager Round(1hr)
The interviewer asked me to brief about myself.We then settled down on my project for the
first few minutes and then the interviewer asked about the interviews that I had attended
earlier and how the process went through. Then he started asking about testing and the
use of testing corresponding to some given scenarios. After a few minutes of discussion he
asked two questions regarding data structures.

1. Given an array of integers print the pairs that add upto a given sum.

I gave a O(nlogn) approach at first to find the pairs and print them. The approach was to
sort the array and keep two indexes(at each end) left and right and find whether pairs that
add up to the given sum and print them until the left and right pointers cross.
Then he asked me if I can optimize it further. I gave a O(n) approach using hashing.I
maintained a hashset of integers. Put the first number in the hashset, start from the second
element and for each number in the array check whether (Given sum – Current element) is
present in the hashset. If so print the pair.
2. Given a binary tree print the bottom view of it.
After a few minutes of thinking I came up with an approach by using the horizontal distance
of the nodes from the root. We have to keep note of the last node at a particular horizontal
distance while traversing using level order traversal. I used a Hashtable to store the last
visited node at each horizontal distance.
This approach uses O(n) time and O(n) space.
He then asked a puzzle.
In a room of 30 people,find the unique number of handshakes given a condition that each
one in the room should have shaken hands with everyone.
I just used a simple logic. In a room of 2 people,there is only one unique hand shake(First
person has 1 unique handshake whereas the second one has none). If we consider three
people,n = 3 (A,B,C)
A has two unique handshakes B,C.(n-1 handshakes)
B has 1 unique handshake C.(n-2 handshakes)
C doesn’t have any unique handshake.
total number of handshakes = n-1 + n-2 = 2n-3 = 3.(which is the sum of first two natu-
ral numbers)
Similarly for n persons the unique handshakes would be the sum of first n-1 natural numbers.
For n = 30, Total number of unique handshakes is 29*30/2 = 29*15 = 435.
That’s a wrap. He was happy with the way I approached the solution.

1004
Chapter 420. Set 414 (For SDET-1)

He asked if I had any questions for him. I asked about the culture and working environment
at amazon.
Round 5:Bar Raiser Round(1hr)
Two members entered the room and introduced themselves and we just started out with my
introduction and my project.
They asked me how many rounds I had before the current one. They just asked a few
questions about testing at first.Then they asked two coding questions.

1. Given a binary tree print the Kth largest element in it.

I just instantly started with a brute force solution by finding the inorder traversal of the
tree.Then sort the array and find the kth largest in the sorted array which is the (n-k)th
element from the start index of the array,where n is the total number of nodes in the tree.This
uses O(nlogn) time and O(n) space.
They asked me to optimize it further.
I gave a O(nlogn) time and O(1) space solution by converting the binary tree into doubly
linked list and then finding the kth largest in a doubly linked list which can be done in
O(nlogn) time.
But there is a better solution for this which I couldn’t think of during the interview.Just
construct a minheap of k elements,Insert elements into the heap by traversing the tree using
any traversal.
If the heap root element is smaller than the current node in the tree remove the root element
from heap and insert the new element to the heap. At last after the complete traversal of
the tree the kth largest element will be at the root of the heap.This uses O(nlogk) time and
O(k) space.
But they were happy with my approach as they said me to optimise it either by space or
time. I gave a constant space approach so they were satisfied.
2.Given a directed graph, find whether there exists a cycle or not.If it does exist print it.
I gave a solution using BFS. I put a node in the queue and then added all possible nodes
that can be reached from the current node. While we traverse the nodes we just mark the
node as visited in the hashmap in order to avoid indefinite looping between nodes. They
were satisfied with my approach.
Finally they asked how HashMap is implemented and how it works(especially how hashcode
and index are computed). I designed my own hash function and explained the way get and
put functions work in a hashmap. They were happy with my explanation and then they
asked how would you modify your hash function in case of collision and discussed in brief
about collision handling techniques.
They asked if I had any questions for them. I just asked the same question I asked the
previous round.
P.S: For each question we have to write the code clearly. Don’t just dive straight into the
coding part, explain your approach clearly. Be confident and they don’t want the optimized

1005
Chapter 420. Set 414 (For SDET-1)

solution for the question,they see how the candidate approaches the question.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-414-sdet-1/

1006
Chapter 421

Set 415 (For SDE-2)

Amazon interview Experience | Set 415 (For SDE-2) - GeeksforGeeks


Written :
1. Given a string and pattern with (*, ?) Check if it can match the string.
2. Find an element in first increasing and decreasing array.
Round 1 :
1. Given an array of strings. Find all pairs which form palindrome. O(N)
2. Celebrity problem.
Round 2 :
1. Given a set of dependent tasks, find order for dependent tasks. Variation of topological
sort.
2. Count of paths from top left to right bottom in an array containing 0/1. Here 1 means
blocked shell. You are allowed to move right or down.
Round 3 :
1. Project discussion (Hint : Prepare your project well, with all ins and outs)
2. find maxsum in a binary tree. (node can have -ve numbers as well).
Round 4 :
1. Design Bookmyshow : HLD, LLD and different race conditions discussion. scalability
discussions
2. Given an integer array, find the number of merge operations required to make it a
palindrome
Round 5 :
1. Behavioral questions : conflicts, challenges, innovation
2. Project discussion
3. Design Restaurant booking application HLD and LLD. Write an algorithm to optimally
assign tables for bookings.
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

1007
Chapter 421. Set 415 (For SDE-2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-415-sde-2/

1008
Chapter 422

Set 416 (On Campus for


Internship)

Amazon interview Experience | Set 416 (On Campus for Internship) - GeeksforGeeks
Coding Round
There were 2 coding questions (10 marks each) and 20 MCQ’s from various core concepts (
OS,DS,Algorithms,DB,C language etc ).

• Question 1 : https://www.geeksforgeeks.org/given-a-string-print-all-possible-palindromic-partition/ Given


a string, find all possible palindromic partitions of given string.
• Question 2 : You are given with a large paragraph and N words.You have to find
a min length subparagraph of the paragraph which contain all those N words in any
order.(Case Insensitive)

22 students were shortlisted for the interviews.


Interview Round 1
The interviewer asked to introduce myself and then he asked to explain my projects, one of
them in detail. Then he gave me 2 coding questions
Question 1 : Given a sorted array of integers(might contain duplicates), you should write
a function which returns the first index of an element.
E.g. arr = [1,2,2,2,3,3,3,4] val=3 ; ans = 4
Answer : It is a basic binary search except for the condition that you will check not only
if the current element is mid, but also if its previous element is less than it(if a previous
element exists) and only then return mid.
Else recur on the left part till the above condition is met.
Question 2 : Given a binary tree check if its a binary search tree or not? https://www.geeksforgeeks.org/a-
program-to-check-if-a-binary-tree-is-bst-or-not/
It is very important to write neat code on paper. The interviewer dry runs a few examples
on the code.

1009
Chapter 422. Set 416 (On Campus for Internship)

Interview Round 2
The interviewer asked me about my previous interview and its questions.
Later he gave me 2 coding questions.
Question 1 : Given an array of integers with the property that arr[j] – arr[j-1] is either
1,0,-1 and a search value, provide an efficient search mechanism.
Answer : The naive approach is to perform linear search which is O(n). Then I thought
along lines of binary search but, as such we cannot divide and recur because of the array’s
property.
After some time, I came up with a method which starts with the first element and compares
each element with the search value and increment its location by absolute difference of the
current value and search key.
This is a worst case O(n) algorithm, but does far better than linear search in generic case.
Question 2 : Given an array of integers(duplicates allowed) return if it is a set of contiguous
integers or not?
Input: 5,2,3,6,4,4,6,6 Output: Yes (as it is from set of [2,3,4,5,6])
Answer : First, I gave him a hashing based approach. Initially, make a hash of all the
elements and then pick the first element and increment in 1’s till you find a value not
present in the hash. Similarly decrement in 1’s from the first value and get the count. If
the count equals hash size it is true else it is false.
It is O(n) time complexity and O(n) space-complexity.
He asked me to improve the space complexity to O(1).
I tried a lot but didn’t get to solution. Then, he simplified the problem by giving hints and
making it a duplication detection problem in a array without using any additional space
provided the numbers are in the range [ 0,length_of_array -1 ].
This can be done by accessing element at index j as arr[j]%n and as make arr[arr[i]] =
arr[arr[i]] + n*arr[i]. So if at any stage arr[j]/n is > 1 implies we have visited it earlier. He
was satisfied with this solution.
DS Questions

1. Give use cases when you will prefer Hash table instead of BST and vice-versa?
2. What happens in case of duplicate insertions in Hash table and BST. What is its effect
on the complexity of search?

I answered these and he was happy with the answers.


The interviewers are very comforting and give clues to direct us to solution.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-416-campus-internship/

1010
Chapter 423

Set 417 (For SDE- 2)

Amazon Interview Experience | Set 417 (For SDE- 2) - GeeksforGeeks


Round 1:

1. Distance between two given nodes in a binary tree. I was asked to write the optimal
approach for the this.
https://www.geeksforgeeks.org/find-distance-between-two-nodes-of-a-binary-tree/
2. A group of people are seated in a circular table. After a while , each members takes
a chit and writes his name along with the next person name (anticlock wise.) . If
such chits are given , re draw the the table. A optimal approach was expected. eg. A
– B – C- D – E – A
chits will be written as A-B
B-C
C-D etc
3. Same questions as above . if each member takes a chit and writes his neighbors name
. re draw the table.

Round 2:

1. Given a Binary tree with root(R) , a node(N) and distance (k). find all the nodes at
k distance from N. Optimal solution was expected.
https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
2. Given a linked with next pointer and random pointer. Clone the linked List.

Clone a linked list with next and random pointer | Set 1

O(1) space solution was expected.

Round 3:

1011
Chapter 423. Set 417 (For SDE- 2)

1. Given a string of arrays “cat,dog,god,act”. Print all the anagrams which comes first
in list.
eg. output is cat ,act,dog and god. Means all the similar anagrams should be printed
together and the next print should be the one which comes earlier in the list.
https://www.geeksforgeeks.org/given-a-sequence-of-words-print-all-anagrams-together/
hint : Trie approach was expected here.
2. Given a stream of input Integers, at any time get the median of those numbers.

Round 4:

1. Design Bookmyshow : HLD, LLD and different race conditions discussion and scala-
bility discussions.

Round 5:

1. Given a input String and a patterns string. return all the start index of the input
string whenever the anagrams of the pattern match with input string. eg.
in : abcbaabba
pat : ab
output : index 0
index 3
index 5
index 7
2. Design RedBus kind of app : HLD, LLD and different race conditions discussion and
scalability discussions.

Round 6(Hiring Manager):


1. Behavioral questions : conflicts, challenges, innovation
2. Project Discussions. Please make sure you know everything about your project.
3. Reverse a stack using recursion.
Round 7(Bar raiser)
1. Behavioral questions : conflicts, challenges, innovation
2. Project Discussions.
3. Next Greater element.
https://www.geeksforgeeks.org/next-greater-element/
All Practice Problems for Amazon !
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-417-sde-2/

1012
Chapter 424

Set 418 (For SDE 2)

Amazon Interview Experience | Set 418 (For SDE 2) - GeeksforGeeks


I applied through recruiter, i was having 4 year exp while appearing for this interview,
overall it was quite lengthy process.
I shared my resume to recruiter and later was scheduled a telephonic discussion
Telephonic Round 1:
Brief Intro from both the side then he asked the technical question,
Topological sort (there are lots of modules are given which are dependent on other modules,
find the build sequence).
Median in running stream of integers. (solved using min and max heap)
Then there was gap of almost 3 weeks with no clue on feedback then suddenly recruiter
contacted me stating the positive feedback from telephonic discussion and invite for In
House interview at Amazon Gurgaon office since i was in NCR region.
Round 2:
This was completely technical round, i was asked to three technical question, not much
tough
LCA of two nodes
Stock buy and sell problem
Finding if there exist a sum X of two elements from and array having positive and negative
numbers
Round 3:
This was kind of mix of technical and some behavioral questions
Initially interview asked some of the questions from resume then jumped to the technical
questions,
Maximum sum subarray from array having positive and negative numbers both.

1013
Chapter 424. Set 418 (For SDE 2)

LRU implementation
Round 4:
This round was completely design round (LLD and HLD)
Design Debugger then in between he moved to design Meeting scheduler
In last 10 minute he asked me to give HLD of Clock Room
Round 5:
This was taken by some senior developer,
He asked few question related to previous work, its challenges then moved to technical
question
Finding missing number in array, i gave XOR approach then he deep dived into how XOR
work
given a tree having unique nodes and given n and k value, find n node and then print all
nodes having distance of k from nth node in both the direction
Then again some behavioral question,
Why amazon?
Why leaving current org?
This type of questions.

These all rounds happen on the same day, then i was asked to leave for the day and wait
till next week for getting the feedback and next steps if any.
After 1 week, i got mail stating that, we would like to proceed further and scheduled my
bar raiser round.
Round 6 (BR):
It was telephonic discussion,
Interviewer judged me on Amazon leadership principles,
And i believe i just slips on one of the principle but overall he was satisfied with my responses.
And he asked me to explain HLD for Automatic Parking System.
This interview stretched for long since there was some network connectivity issue with my
cell network,
In last he asked me to explain just the approach of solving a technical problem,
Exact question i don’t remember but it was related to merging k sorted array.
Round 7 (HM):
Nearly next week this interview was scheduled since Hiring mangers were not available due
to their busy schedule,
Majority of the time this interview was around behavioral questions and Amazon leadership
principles.

1014
Chapter 424. Set 418 (For SDE 2)

In last he asked me to design Game Studio like amoeba game zone.

All Practice Problems for Amazon !


Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-418-sde-2/

1015
Chapter 425

Set 419

Amazon Interview Experience | Set 419 - GeeksforGeeks


Round 1: There were three questions in first round:-
a) How to find all boundary node of a tree.
b) How to reverse a string using without any other variable.
c) From an array, Need to find an index in which sum of left elements & sum of right
elements are same.

Round 2:
a) Sort an array arr = {1, 0, 0, 0, 1, 0, 1, 1, 1, 1} with o(n) complexity. It is also called
segregation of an array.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-419/

1016
Chapter 426

Set 420 (For QAE)

Amazon Interview Experience | Set 420 (For QAE) - GeeksforGeeks


I got a referral from an employee for the QAE position at Chennai and after applying I
got call from Amazon the very next day. They scheduled the phone call interview. The
interviewer didn’t show up on the scheduled date.
So we scheduled again to a new date.
Phone Interview:
1) Asked test cases for Amazon Shopping Cart.
2) You are hosting a web app in your server which is accessible only to a particular set of
people. But on an unusual day, all the people are able to access your web app. How would
you troubleshoot this issue?
3) Given an array, find the largest product of two consecutive elements.
Phone interview went well and I got a call from Amazon within a week for scheduling onsite
rounds. 4 onsite face to face interviews were scheduled.
Face to Face 1:
1) Test cases for analog alarm clock.
2) Test cases for lift.
3) You are hosting a game in your server. All the users are connected to the game. When
one user tries to connect to the multiplayer game he gets Error Occured message. How
would you troubleshoot this scenario?
Face to Face 2:
1) Asked about my current project in depth.
2) Given an integer, find the nearest palindrome to that number.
Eg1. I/P : 115 O/P : 111
Eg2. I/P : 117 O/P : 121
https://leetcode.com/problems/find-the-closest-palindrome/solution/
3) Given an array, find the first duplicate element.
Eg. I/P : [1, 2, 4, 4, 1, 3, 7, 5, 5, 2]
O/P : 4

1017
Chapter 426. Set 420 (For QAE)

4) Given a sentence, reverse all the words in that sentence.


Eg. I/P : This is sample text
O/P : sihT si elpmas txet
5) Asked all test data for the amazon login page.
Bar Raiser Round:
2) How would you test Whispersync feature in Kindle.
3) Given two sorted linked lists, merge the lists in a sorted manner with constant extra
space.

Merge two sorted linked lists

4) Asked all possible behavioral questions like


a) What is the most challenging/complex job that you did?
b) Any misunderstanding scenario with you manager and teammates?
c) Why are you interested in QAE?
d) How would you handle pressure?
Managerial Round:
1) Asked about my current project in depth.
2) Again asked all possible behavioral questions to test whether I can handle pressure situ-
ations and How do I handle prioritization of jobs and about my testing strategy.
3) Given an integer, find sum of digits of that number until sum becomes single digit
https://www.geeksforgeeks.org/finding-sum-of-digits-of-a-number-until-sum-beco
mes-single-digit/? and asked the test data for the same.
Programming questions were easy. They do stress much on test cases and troubleshooting.
All the Best!!!

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-420-qae/

1018
Chapter 427

Set 421 (For Internship)

Amazon Interview Experience | Set 421 (For Internship) - GeeksforGeeks


Recently Amazon visited our campus for Internship and Full time.
Coding Test: Was an online test which comprised of 2 coding questions and 20 MCQs.
MCQs were basically based on pointers, output related, OS etc. For pointers and output
related questions one should practice from www.geeksforgeeks.org/quiz-corner-gq/ which is
quite enough if one thorough through most of the questions. One of the coding question
was based on Dynamic Programming and other on String manipulation. The questions
were more on moderate to difficult level, even if you are not able to devise the most optimal
solutions go for the most naive solution as marks are allotted for each test case. (Some
people even used if else statements to run the most trivial test cases and it worked for
them).
Around 70 students sat for the test and 10 were selected for the next round. I attempted
around 17 MCQs and I think 13 or 14 of them were correct while I partially did the 2 coding
questions using the naive approach.
Round 1: In the first round, the interviewer asked me to introduce myself, and some
projects I wrote in my CV. (Just don’t blabber anything in your CV).
Question 1-: Zig Zag traveral in a binary tree. (https://www.geeksforgeeks.org/
zigzag-tree-traversal/)
Question 2-: Finding the next higher palindromic number using the same set of digits.
(https://www.geeksforgeeks.org/next-higher-palindromic-number-using-set-digits/)
Question 3-: There was one more question based on maps
Question 4-: Difference between map and unordered_map
Round 2: Asked to introduce, and what projects I have done till now
Question 1-: Finding compliment and 2s compliment of a binary number (Didnt have to
code it just find it for say 100011)
Question 2-: Some questions based on DBMS (basic queries)

1019
Chapter 427. Set 421 (For Internship)

Question 3-: A variant of Binary tree traversal. I was given a tree and the output was given
had to identify the type of traversal and then code it out.
It was right_subtree->left_subtree->root
Question 4-: Stock buy sell to maximize profit problem (https://www.geeksforgeeks.org/
stock-buy-sell/)
Followed by some random discussion about amazon and its products.
In general interviewers were friendly and ready to help whenever i got stuck.
Cheers!
All Practice Problems for Amazon !
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-421-internship/

1020
Chapter 428

Set 422 (For SDE II)

Amazon Interview Experience | Set 422 (For SDE II) - GeeksforGeeks


Round 1: Telephonic round.

1. Find max 1 in a row of a 2D array.https://www.geeksforgeeks.org/find-the-row-with-


maximum-number-1s/
2. Find the biggest square in a 2D array.https://www.geeksforgeeks.org/maximum-size-
sub-matrix-with-all-1s-in-a-binary-matrix/

Round 2:
On site Interview:

1. DEsign BookMyShow. Very interactive interview. Enjoyed it. Went well.


2. A challenging task you have done till now in your project.

Round 3:

1. Design VLC.

Round 3:

1. Design Tiny URL.


2. Architecture of your challenging work you have done so far.
3. He was writing down every thing i was saying.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

1021
Chapter 428. Set 422 (For SDE II)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-422-sde-ii/

1022
Chapter 429

Set 423 (For Cloud Support


Associate)

Amazon Interview Experience | Set 423 (For Cloud Support Associate) - GeeksforGeeks
Round 1: The first round was an elimination round, i.e.the online test.The test comprised
for 3 sections-the general aptitude and English(easy to moderate difficulty), then came the
technical section which mostly focused on OS and CN mcqs(can be solved well if one has
really good knowledge of both subjects), and the final section was of programming(2 ques,
around 30 min-but the questions weren’t difficult).
Round 2: The next round comprised of 2 technical interviews.Questions were asked from
OS, CN, troubleshooting of network etc(in-depth concepts). Also a few programming
questions were asked to some candidates.These 2 rounds and the managerial round were
more of elimination rounds.
Round 3: The final round comprised of 2 more interviews-managerial and HR.The manage-
rial interview questions were related to project work, various difficulties faced and various
scenario/situation-type questions.The HR interview was also about life experiences and sce-
narios.The trick is to be completely honest and have a solid justification for all the answers.
The interviewers were quite co-operative and understanding.It was really a great experience.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-423-cloud-support-associate/

1023
Chapter 430

Set 424 (For SDE 2)

Amazon Interview Experience | Set 424 (For SDE 2) - GeeksforGeeks


Round 0: Online Coding Test (90 Min – 4 Coding Questions)
1) Run length encoding
aaaaaabb -> a5b2
aaaaabccc -> a5bc3
2) Linked List pair sum count
0 -> 2 -> 5 -> 7 -> 4 -> 6 -> 10 -> 20 -> -10 -> Null
Given Sum: 10
Output : 3
Explanation: (4, 6) (0, 10) (20, -10)
3) Rotate Doubly Linked List by N time
NULL <= a =><= b =><= c =><= d =><= e =><= f =><= g =><= h => NULL
Given Num: 4
O/P:
NULL <= e =><= f =><= g =><= h =><= a =><= b =><= c =><= d => NULL
4) Given Binary Tree, find level of x node if x is present otherwise return 0.
After 1 month recruiter called for f2f rounds. There were 4 rounds on the same day.
Round 1: Hiring Manager Round (Behaviour + Design)(1.5 Hrs)
Intro, Project & Lot of Behaviour Questions
-> Project Biggest Challenge and how did you solve it ? (Choose recent & best)
-> Tell me a time when you mentor someone ?
-> Tell me a time when your manager was not there and you had to take up some important
decision ?
-> Tell me a time when you have to deep dive into something on your own ?
Lot of other behaviour questions. Finally gave a design problem to solve.
Design:
Do integration for Splitwise app with Amaonz Pay (or Paytm)

1024
Chapter 430. Set 424 (For SDE 2)

1) where a person can pay to another person and money directly gets deposited into other
person’s bank account.
2) A person can also send reminder to another person for owning money.
Round 2: Design Round (1.5 Hrs)
1) Detailed discussion on project and design of it, how will you scale your project to support
n number of users. Focus was on scalability & distributed design.
2) Design a job scheduler, scalability, fault tolerance, high availability, how scheduler picks
up job,
how will you take care where one job can run for 30 min and one for 30 hour, how will you
distribute jobs on servers.
Based on frequency & time how will you execute them ?
How will you notify back the user about start/stop or completion of a job ?
How will your system know if a job is killed / terminated due to unknown reasons ?
Round 3: Coding Round (1.5 Hrs)
Given array -> {5, 1, 3, 2, 8}
and a Linked List where elements will be from the array but can also be duplicated.
3 -> 2 -> 5 -> 8 -> 5 -> 2 -> 1 -> X
Sort the linked list in the order, elements are appearing in the array. O(n) complexity was
expected. Complete running code on paper was expected. All boundary condition checks
were expected.
Round 4: Coding Round (1.5 Hrs)
Given a n-ary tree, basically a graph but connected and doesn’t contain cycle.
every edge is given a weight, identify all paths from all vertex to all vertex & then sum of
all paths.
Give final result as sum of all paths.
Ex:
10 20
A——-B——–E
30/ \40 \ 50
/ \ \
C D F
Here all paths and their sum are as follows: Ans should be sum of all of them.
A-B = 10
A-E = (10+20)
A-F = (10+50)
A-C = 30
A-D = 40
B-E = 20
B-F = 50
B-C = (10+30)
B-D = (10+40)
C-D = (30+40)
C-E = (30+10+20)
C-F = (30+10+50)
D-E = (40+10+20)

1025
Chapter 430. Set 424 (For SDE 2)

D-F = (40+10+50)
E-F = (20+50)
First write the data structure to solve this problem, then efficient algorithm, then complete
working code on paper.

Overall it was a positive experience, recruiter kept me informed about the progress and
about next rounds. First four rounds went well but I wasn’t able to solve 5th round problem,
and was eliminated after then.
Thanks a lot to geeks for geeks for having such a great amount of collection to practice on.

Advise:

• Please do prepare for behaviour questions as well. Have one or two example ready
for all the questions. Most of them are available here : http://kraftshala.com/how-to-
raise-the-bar-in-the-amazon-interview/
• Prepare for design rounds seriously, they look for scalability, high availability & dis-
tributed system architecture in your design.
• For coding prepare your basics and have them thorough, practice using pen & paper
for writing code.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-424-sde-2/

1026
Chapter 431

Set 425

Amazon Interview Experience | Set 425 - GeeksforGeeks


Round 1: Technical Face 2 Face.

1. Write a program to find the range of majority elements in array(non-descending)?


2. Write program to print all the permutation of String? Example Input : AB, Output :
{$, “A”, “B”, “AB”};
3. Write program to transform a tree from give tree, such that each node will have the
sum of child nodes plus itself.(Write recursive funciton)

To best of me i have given answer to all the three programs(little doubtful with 2nd one).
No Selected. �
For first question my approach was:

public class MajorityRange {


  
    public static void main(String args[])
    {
        int number[] = { 1, 3, 3, 3, 3, 3, 4 };
        int size = number.length;
        int start = 0;
        int end = size - 1;
        int count = 1;
        for (int i = 1; i < size; i++) {
            if (number[i] != number[i - 1]) {
                if (count > size / 2) {
                    end = i - 1;
                }
                else {
                    start = i;

1027
Chapter 431. Set 425

                }
            }
            else {
                count++;
            }
        }
        System.out.println("Start = " + start + "End = " + end);
    }
}

Explanation: Solved in O(n) time complexity. In order to improve the complexity we can
use divide and conquer strategy(Modified version of Jump Search or interpolation Search)

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-425/

1028
Chapter 432

Set 426 (For SDE-1)

Amazon Interview Experience | Set 426 (For SDE-1) - GeeksforGeeks


Round 1:Written Round had 3 questions:-
1- Sum of two linked lists https://www.geeksforgeeks.org/sum-of-two-linked-lists/
Don’t remember the other 2.
Round 2: DS algo
1-Find pair with given sum in bst
2-Transpose of the matrix
Round 3: problem solving
1-Find top view of binary tree (Iterative approach)
2nd question was on matrix don’t remember exactly
Round 4: HR round
Question on Amazon leadership principle. Why leaving current company. Question on tasks
handled. Behavior based questions around amazon leadership principle
Round 5 : Designing round
1- Design a chess game. Form a structure of gamePlan.
2-There is a room with guard sitting there, he is noting the booking time. For eg:-
a) 0200 hrs to 0430 hrs
b)0315 hrs to 0545 hrs
c)0600 hrs to 0800 hrs
You have to check how many are valid bookings with no conflict.
(Invalid booking are those which are having conflict with any booking)
In above example a) & b) are having conflicts so no valid booking. c) is valid booking.

All Practice Problems for Amazon !


Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

1029
Chapter 432. Set 426 (For SDE-1)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-426-sde-1/

1030
Chapter 433

Set 427 (SDE-2)

Amazon Interview Experience | Set 427 (SDE-2) - GeeksforGeeks


It was a recruitment drive at Pune, for Kindle team (Chennai).
Round 1 (Screening):
Two common questions were given to all. We’re supposed to discuss the approach to the
problem with the interviewer first and then implement it after the interviewer is convinced
with your approach.

1. Postfix expression evaluation


• Expected to handle all exceptions like invalid expression, invalid symbol in the
expression, etc.
2. Sort an array of 0s. 1s & 2s
• I gave him the counting solution and another solution (both linear), but he wanted
me to solve it in single pass, was expecting Dutch National Flag Algorithm. (for-
tunately still got shortlisted :))

Round 2 (Problem Solving):

1. Convert Postfix expression to Infix


• And there should not be redundant/unnecessary parenthesis like (a*b), (a+b)+c,
(a*b)+c etc. are invalid. But (a+b)*c is valid.
2. All anagrams of a given string
• Later asked me to modify the program to return the list of all the strings rather
than printing them.
• Also asked me to dry run the code for a sample input.

Round 3 (Problem Solving):

1031
Chapter 433. Set 427 (SDE-2)

1. Rain water trapping problem


• I was stuck here, but finally able to get a solution.
2. Print right view of binary tree
• Can be done by level order traversal of tree.
3. Clone a linked list with Next and Random pointer
• Given the solution using O(n) extra space (using hashmap).
4. What’s your biggest achievement in last 6 months?

After clearing these rounds, I was invited for on-site interview to Chennai for
further rounds.
Round 4 (Design):

1. Asked me to explain the architecture of one of the project from my resume.


• Explained using class diagrams.
2. Design a Whatsapp like service.
• Given the high level design first, then dived deeper explaining load balancing,
splitting into microservies and communication between them, notification service,
message queuing, database sharding, etc.
• Asked me how to maintain the sequencing of messages, since client’s time-stamp
would be unreliable.
3. Class diagram for a standalone Chess board game.
• Discussion on the my design like, why this class/relationship is needed, why this
method is in this class rather than that, etc. Convinced him for few of them,
giving proper reasons, and made changes in the design for other few.
• Pseudo code for all the possible moves of any piece.

After this the HR informed me that the feedback of my design round was quite
good and also gave me suggestions to perform well in rest of the rounds.
Round 5 (Bar raiser):
Few questions to evaluate me on Amazon’s leadership principles. I can’t remember them
all �

• Have you ever mentored someone?


• Any change/improvement you introduced in your previous organisation.
• Reason for leaving the previous company
• Reason for joining Amazon.
• Are you aware of kind of projects being done at Amazon?
• One of your biggest technical mistake.

And one algorithmic problem at the end. Diameter of a binary tree

1032
Chapter 433. Set 427 (SDE-2)

• Asked me to return the 2 corresponding nodes (at the end of diameter) instead of the
diameter.

Round 6 (Hiring manager):

• Some discussions about my previous companies and projects.


• One algorithmic problem.
– Given a result of a competition among all the students of a class, write a program
to make students stand in a order such that every student must have lost to
the student in his/her immediate left and won against the student to his/her
immediate right.
• Some leadership questions. Again can’t remember them all.
– Most challenging technical task and how did you solve that.

Note: In problem solving rounds, you’re supposed to write a working code in any language
of your choice, handling all the corner cases.
Finally got an offer after 3 days!! � All the best!! (y)
All Practice Problems for Amazon !!
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-sde-2/

1033
Chapter 434

Set 428 (For SDE-2)

Amazon Interview Experience | Set 428 (For SDE-2) - GeeksforGeeks


I was interviewed for customer returns team for Hyderabad campus. I had 1 year and 9
month experience at the time of getting interviewed. Less experience was something which
was worrying me a lot. They generally ask for 3-5 years of experience, but come down to 2
years if you are good.
Round 1 : Telephonic

• A brief introduction
• Clone a Binary Tree with Random Pointers
• Write a program to calculate pow(x, n)

Round 2 : Technical Round

• A brief introduction
• Program for Best Fit algorithm in Memory Management
• Design a deck of card (only the model classes)
• NoSQL vs a SQL database (when to choose which)

Round 3 : Manager Round

• A brief introduction
• Almost 15 minute discussion about what Customer Returns Team in Amazon does
• A very detailed description of technical challenge faced (it includes HLD, LLD and
the solution offered)
• Design Promo Code API taking Amazon’s customer traffic into picture (HLD and
LLD was discussed – including in memory databases)
• Which areas of yours would you like to improve upon? (Both technical and non-
technical)

1034
Chapter 434. Set 428 (For SDE-2)

Round 4 : Technical Round

• A brief introduction
• Variation of Topological Sorting : You have been given a set of inter-dependent tasks
along with the time taken to execute them. We have more number of parallel processors
available than the number of tasks given. There could be multiple starting tasks. There
could also be cyclic dependencies. Calculate the minimum time required to complete
all the task. Complete end to end production ready code was expected.

Round 5 : Bar Raiser

• A brief introduction
• Responsibilities in the current company
• Why do you want to change your company
• Anything which makes me different from somebody else (technical and non-technical)
• Any project which I’m proud of. What’s so special about that particular project.
• Arrange given numbers to form the biggest number
• What difference does having a docker makes if compared to directly deploying appli-
cations on the VMs?
• When did you felt that you are not liking the status quo of a workflow? Any past
experiences.
• Discussions about a mongoDB cluster vs an elasticsearch cluster (from my projects)

Round 6 : Design Round


1. What is so special about typescript that both Angular and React included it in the recent
versions. Tsc compiler, final output, difference between java, JS and TS were discussed. Any
live project use case where TS helped more than JS (I come from a pure JS background
that’s why this question was asked)
2. Design a vending machine with following functionalities

• Three types of Users : User, Operator, Admin


• User can select and buy multiple items at a time. Money can be inputted multiple
times (you will get the item if there is a time gap > 30 secs). He can also do window
shopping (see only the prices of items and buy nothing)
• Operator can load the items and mark the items as expired if needed, gets notified if
a product goes out of stock.
• Admin can own multiple vending machines, he should have a analytics report of the
items purchased in a month. He can also change the prices directly and it should
reflect in all the vending machines which he owns.
• Exception handling in all the edge cases

Both HLD and LLD were expected.

Round 2 to 6 were done in Amazon Hyderabad campus. All interviews were back to back.
It started from 11 AM to 5:30 PM with just half an hour lunch break. Before I could even

1035
Chapter 434. Set 428 (For SDE-2)

step out after completing one round, other interviewers would already be waiting outside.
Interviewers were very helping, but only if your are thinking in the right direction. HR also
was very supportive. He was coming and motivating me after every round. Some advices
here

• If your couldn’t solve a problem, don’t carry forward negative thoughts into next
round. It will affect the next round as well.
• If your have prepared well, importance of keeping calm and cool should not be ignored.
Trust me, you won’t survive the stress of whole day otherwise.
• All the codes you would be asked to write down on paper and designs on the white
boards, so practise accordingly.
• Prepare for the design interviews well, they play a big role for SDE 2.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-428-experienced/

1036
Chapter 435

Set 429 (For SDE 2)

Amazon Interview Experience | Set 429 (For SDE 2) - GeeksforGeeks


Round 1: Telephonic Round

1. There is a university with certain sets of courses. You can take a course in any semester
but you need to finish its prereq course (if prereq is given for a course) before that.
Design the whole university structure and suggest the Algo. He then changed the
question bit, if you can take up a course and its pre req in the same semester how will
your code change. https://www.geeksforgeeks.org/topological-sorting/

Round 2: Face to Face interview

1. Convert a roman number into an integer number. He provided me with a set of rules.
2. Explain your Project
3. Most challenging thing in your project.
4. Do you review code. what all code changes you have suggested till now.
5. Any big enhancement suggested by you to make your code better.

Round 3: Face to Face interview

1. Explain your project


2. Few question related to my project and some behavioral questions.
3. A running stream of numbers is coming you need to keep track of top K elements

It was not a coding question only. He expected me to write a Heap interface and using
that implement min heap or max heap. And also write the heapify code

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

1037
Chapter 435. Set 429 (For SDE 2)

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-429-sde-2/

1038
Chapter 436

Set 430 (For SDE2)

Amazon Interview Experience | Set 430 (For SDE2) - GeeksforGeeks


Round 1:

1. Given an array and an operation -> foo(index, value), the value can be either 1 or -1,
if foo(index, value) is called, it will add ‘value’ to all elements from index till end of
the array, find minimum number of operation to make all array elements 0.
2. Don’t remember completely, but it was something like finding a deadlock in a BST.

Round 2:

1. https://www.geeksforgeeks.org/trapping-rain-water/
2. https://www.geeksforgeeks.org/longest-possible-chunked-palindrome/

Round 3:
Design round:

1. Design a scalable meeting room booking system.

Round 4:
Managerial round, lot of project and Amazon’s leadership principle related questions.
Round 5:
Bar Raiser: Lot of behavioral and leadership principle questions, then asked a design ques-
tion, design a load balancer’s algorithm so that it redirects the traffic between three services
s1, s2, s3 by 50%, 30% and 20%. further clause added to handle various clients calling to
specific services.

1039
Chapter 436. Set 430 (For SDE2)

Tips for the interview: Good hands on towards problem solving and algorithm, HLD
and LLD, prepare well for Amazon’s leadership principles.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-430-sde2/

1040
Chapter 437

Set 431 (For SDE2)

Amazon Interview Experience | Set 431 (For SDE2) - GeeksforGeeks


I was interviewed for SDE2 role at Amazon, Bangalore. I had 3 years of experience at the
time of getting interviewed.
Round 1 : Coding Test —————————————————————————————
——————–
– Explain design patterns used so far.
– How is code review done.
– How is design review done.
– Write a program to search a number in a sorted array having 1 maxima.
– Write a program to check parenthesis are matching.
Round 2 : Technical Round ———————————————————————————
———————-
– What type of cache do you use in your projects/SYstem.
– Design a LRU cache having methods
– get(K Key)
– put(K key, V Value)
– remove(K Key)
They wanted a Library such as Redis which takes generic input.(Using generics)
Round 3 : Hiring Manager Round —————————————————————————
———————–
– A brief introduction
– Almost 15 minute discussion about what App Store in Amazon does
– Explained my project in detail.
– A very detailed description of technical challenge faced (it includes HLD, LLD and the
solution offered)
– Design google’s Autocomplete feature.
– Which areas of yours would you like to improve upon? (Both technical and non-technical)
– Write a program for finding K largest elements in an array.
Round 4 : Technical Round ———————————————————————————
———————-

1041
Chapter 437. Set 431 (For SDE2)

– In a linked list find Kth elements from end in a single traversal.


– Given a 2-D matrix of 0s and 1s, find the number of groups of adjacent 1s given that
diagonal 1s are not included.
This was the famous Islands problem using connected components in Graph.
Round 5 : Design Round ————————————————————————————
———————-
– Design BookMyShow. All the microservices which are involved their APIs and HLL design
was expected.
How will you resolved the concurrency issue when 2 customers try to book same seat.
Round 6 : Bar Raiser Round
– A brief introduction
– Complete design of my project HLD, LLD, UI, DB etc.
– Responsibilities in the current company
– Why do you want to change your company
– Any task/project which was designed and implemented in less time but had a great impact
on the production/Business Side.
– Have you been appreciated for your task more than your expectations.
– Time when you did not agree with your manager.
– have you lead anyone ? how do you review code ?
– how do you review design?
– What are you weaknesses ?
– Any project which you feel proud for?
Overall the process was very smooth and HR was very supportive.
After a few days I got a call saying I was selected �

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-431-sde2/

1042
Chapter 438

Set 432 (For SDE-2)

Amazon Interview Experience | Set 432 (For SDE-2) - GeeksforGeeks


This interview was for the SDE-2 position for logistic management department of amazon.
I had applied for this job on naukari.com.
Round 1:

There was an online codding test on Hackerearth. Two questions were asked. I don’t
remember them now.
Round 2:
After two weeks they scheduled a telephonic round.
Question 1: Given a matrix of ‘0’ and ‘1’, find the largest Iceland (i.e area of ‘1’s)
https://leetcode.com/problems/max-area-of-island/description/
Question 2. Design a data structure with constant time for insert, delete, search and ge-
tRandom.
https://www.geeksforgeeks.org/design-a-data-structure-that-supports-insert-delete-search-and-getrandom-in-consta
I had given solutions for the both.
Round 3 :
This was onsite interview at Hyderabad.
First he asked about my past projects and challenges faced. He then asked if I had designed
anything on top of current a system.
Next a technical question was given;
Given an array of integers and a window size ‘k’, find first negative number for each possible
window in the array.
https://www.geeksforgeeks.org/first-negative-integer-every-window-size-k/

1043
Chapter 438. Set 432 (For SDE-2)

I first gave him a two queue approach(was not optimal), he told to code it on paper. After
I wrote the code, he asked to optimize it further. Finally after few iterations, I gave him an
optimal two pointer approach.
My suggestion here is; do not hurry to present your solution to interviewer, first try to
come-up with best optimal solution. For SDE-2 positions they expect optimal solution at
the very first place from you.
Round 4 :
This was all project and HLD related round.
There were two interviewers. The first introduced themselves and told about what their
group does at amazon.
He then asked about my role at previous company and past projects I did in brief. Then
asked if I have done something like adding new functionality or suggested some improvement
for the project that was not asked by customer or manager.
He then asked me to draw HLD for meeting calendar system. Then there was discussion on
various issues on it like scalability, what database should be used; SQL-NoSQL, concurrency
etc.

All the best guys!

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-432-sde-2/

1044
Chapter 439

Set 432 (SDET Off – Campus)

Amazon Interview Experience | Set 432 (SDET Off – Campus) - GeeksforGeeks


My friend in Amazon referred me for the job . I was approached by the HR and after lots
of delay (1 month), I was scheduled a Telephonic Interview.
Round 1: (Telephonic Interview ) – 1h
A screen was shared (Notepad) where I will be writing codes and doing other rough work.
I was doing conversation with him on phone.

1. Given n sized stairs and we can take 2 or 3 steps at a time. How many ways are
there to climb the stairs? Question was pretty straight forward. I was able to answer
quickly. https://www.geeksforgeeks.org/count-ways-reach-nth-stair/
2. Given an array with adjacent numbers differing by an absolute value of 1. A number
is given and we have to search it (They do not expect the trivial linear search O(n) ).
I was able to figure out the algorithm for it pretty quickly. https://www.geeksforgeeks.
org/search-an-element-in-an-array-where-difference-between-adjacent-elements-is-1/
3. Given a time hh:mm format. We have the find out the bigger angle between
the hour and minute hands. I took some time to figure out the formula for
it and had to show the derivation of the formula to the interviewer on the
screen. https://www.geeksforgeeks.org/calculate-angle-hour-hand-minute-hand/
4. This was a testing related question. The amazon site (some specific functionality) was
working very well one day before but because of something, that functionality is slow
and customers are complaining. I had to tell how will I debug this.

The interviewer was pretty impressed by my coding skills but not so much with my testing
skill (I guess :P). Anyways, I got the call for my next rounds. There were four of them at
Hyderabad itself. Amazon took care of all the travelling and stay (Awesome nah :D)
Round 2: (Software development Manager 1 ) : 45 mins
Asked questions like:

1. About myself and went through my CV

1045
Chapter 439. Set 432 (SDET Off – Campus)

2. Why I am ready for testing (because my CV displayed Developer kind of profile)


3. Biggest challenge faced in my one year of job and how I fixed it.
4. Testing question: Given a web page with a text box where we can write what html
component to display and it will display on the screen. I had to test this and also had
to write code for one of the test cases.
5. Some new tool/technology that I have learned in very less time and applied .

Round 3: (Software development Manager 2) : 1h


Asked questions like:

1. About myself and went through my CV


2. Why I am ready for testing (because my CV displayed Developer kind of profile)
3. About my project, my role in that. That interviewer was going very deep into the
tools/technologies used in it. Anyways I was able to explain well.
4. Testing question: Test an API (from one of my projects (test cases)).
5. Test whether maps are working right or not.

Round 3: (Software development Engineer) : 1h


Asked coding questions (Nailed it AF):

1. Convert a binary search tree to Greater sum tree. https://www.geeksforgeeks.org/transform-


bst-sum-tree/. Asked both recursive and iterative solutions.
2. Print a matrix in spiral order. https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
3. Given two arrays. One is for tasks (Processes) and each element depicts the amount
of cores required to run the task. 2nd array is an array of CPU where each element
depicts the no of cores in it.We have to tell how many maximum number of tasks can
be allocated. Example: Task: [3, 5, 7], Cores: [1, 3, 5] . Here only task 0 and 1 can
be allocated to CPU 1 and 2 . So, answer=2.

Round 4: (Quality Assurance Engineer) : 1h

1. Design a framework for the testing the Cart service of Amazon. We can Add, delete
and update the elements in the cart.
2. Write unit test cases to test an add Address page in Amazon.
3. What advice as an SDET will I give to a developer and what precautions will I take.

Well, Guess what, I was not selected for the role. They were quite impressed by my coding
skills and not so much with my testing skills. Fair enough !
Tips for Aspirants: Study geeks well (mostly the Data structures part and in
Algo mostly the DP part). Go through other interview experience of Amazon
. https://www.geeksforgeeks.org/amazon-interview-preparation/ For testing, I don’t
have much idea.

Source
https://www.geeksforgeeks.org/amazon-interview-experience-set-432-sdet-off-campus/

1046
Chapter 440

Set 433 (SDE 2 for


Experienced)

Amazon Interview Experience | Set 433 (SDE 2 for Experienced) - GeeksforGeeks


1. What is caching and how it is used. Types of cache eviction policies. Any cache you
might have used for your project. Explain.
2. Implement LRU cache.
We first had discussion over different ways for implementation and then wrote the code
using circular dll and map.
3. Any tradeoffs you have made in your past in any of your projects. Explain
Round 2
1. Design gaming platform. A number of games can be hosted on this platform. User can
login and select a particular game. Discussed both HLD and LLD.
Round 3
1.Discussed on last mile delivery challenge in case of peak seasons. LLD for third party
delivery vendor for registration and notification system .
2. Any good practice that you have introduced in your team.
Round 4
1. Search an element in a sorted rotated array in a single pass
2. Extension of rat in a maze problem. Maximum cheese the rat can eat in a maze.
3 . Discussed in detail project from all my previous company.
Round 5
1. Discussed the current project in detail.
Asked to redesign the current project to make it more scalable.
2. Redesigned the database of current project.
3. Design Swiggy.
4 . Discussion on a previous project where i used spark and discussion on alternatives i

1047
Chapter 440. Set 433 (SDE 2 for Experienced)

consider before using spark to solve that problem.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-433-sde-2-for-experienced/

1048
Chapter 441

Set 434 (For SDE-2)

Amazon Interview Experience | Set 434 (For SDE-2) - GeeksforGeeks


Round 1: Face to Face
Approach in the interview: Start with explaining the approach-> then improve solution if
interviewer asks to do so -> then finally you need to write working code on Paper.

1. Given a binary tree, print all the boundary nodes in an anti-clockwise direction starting
from the root.
Problem Link: https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
2. Deletion Operation on Doubly Linklist, Cover all the test Case.

Problem Link: https://www.geeksforgeeks.org/delete-a-node-in-a-doubly-linked-list/


Round 2: Face to Face

1. Stock buy and sell problem to maximize profit.


2. https://www.geeksforgeeks.org/-boolean-matrix-question/
3. Design auto-suggestion search box/engine, discuss on trie data structure.
4. How will you approach if a website is slow? (TPS/Load Balancer concept)

Round 3: Telephonic

1. There were two Data Structure & Algorithms problems, I only remember one question.
2. Merge Overlapping Intervals – Solved using a stack.

Problem Link:https://www.geeksforgeeks.org/merging-intervals/
Round 4: Face to Face

1. Minimum iteration required to root all oranges. Problem link:

1049
Chapter 441. Set 434 (For SDE-2)

Problem Link: https://www.geeksforgeeks.org/minimum-time-required-so-that-all-


oranges-become-rotten/
2. Count distinct elements in every window of size k, expected time complexity O(n).

Round 5: Hiring Manager(F2F)


Most of the questions asked were behavioral.

1. Tell me about yourself and current project discussion.


2. Have you ever had disagreed moment with your manager on any technical discus-
sion/project?
3. Have you mentored anyone?
4. Have you worked on a project where you interacted with other teams and worked with
them?
5. Have you done anything that improved customer experience?

In short hiring manager covered some Amazon Leadership principles such as customer ob-
session, disagree and commit, dive deep, develop and hire the best etc.

Round 6: Design Round(F2F)

1. Current Project discussion.


2. Design ESPN-Cricinfo website Backend, discussion on HLD and LLD and Load Bal-
ancer.

Round 7: Bar Raiser Round(F2F)

1. Design BookMyshow website backend and discussion on HLD, LLD and DB schema.
There were discussions on various issues like Scalability, What database should be
used; SQL-NoSQL, Concurrency etc.
2. Have you done something in the team that improved team productivity?
3. Have you delivered something in tight deadline?
4. Why are you looking for a change?

Overall the technical bar was good and if one practices DS/Algo questions along with
HLD/LLD and some concepts of System Designs, then he/she can easily crack the rounds.
Some tips/links.

1. Be confident and solve the problem honestly.

1050
Chapter 441. Set 434 (For SDE-2)

2. Some useful links I followed while preparing:


(a) System design section of https://www.interviewbit.com/
3. I used to attend at-least one mock interview at interviewbit which immensely helped
me in getting confidence and know how to approach different problems.

After this long amazing process, I got a call from HR after seven days stated that “Hi,
Congratulations you are selected and cleared all the rounds and we are happy to offer you
SDE-2 position”.

Tips for the interview: Good hands on towards problem-solving and algorithm, practice
from Geeksforgeek and https://www.interviewbit.com/, HLD and LLD, prepare well for
Amazon’s leadership principles.

All the Best Guys!

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-434-for-sde-2/

1051
Chapter 442

Set 435 (For SDE-2)

Amazon Interview Experience | Set 435 (For SDE-2) - GeeksforGeeks


This interview was for Alexa team in Bangalore. They were on a recruitment drive in Delhi.
Round 1: Written
This was a written round on paper. There were 9 questions in total (5 single choice + 4
subjective)
5 single choice questions were on Collections framework and Multi-threading in Java. These
were pretty simple.
4 subjective questions are as follows:-

1. How will you analyse Out of memory exceptions in your application?


2. How will you analyse Deadlock in your application?
3. Write a custom unchecked exception.
4. Write a program that will cause StackOverflowException.

Round 2: Face to Face (DS Algo)

1. https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
2. Given a list of transaction between friends who have to give or take some
amount of money from one another. Now, they have to settle up with mini-
mum number of transactions. Also, you have return a list of all the transac-
tions. For
example – If B owes A Rs. 200 : B->A = 200.
ilarly, if C owes B Rs. 200 : C->B= 200.
the minimum number of transactions is 1 and that should be : C->A = Rs. 200

Round 3:Face to Face (Hiring Manager)

1. He started with some behavioural questions.

1052
Chapter 442. Set 435 (For SDE-2)

2. Design question: There is a passport office with 3 desks (Desk A, Desk B, Desk C)
and 1 token machine. A person comes in and takes token from the token machine.
He has to visit every desk in sequence whenever his token number is displayed on the
particular desk. He just asked me to write the classes for the same.

Round 4: Face to Face (Design round)


Design a online chess game. HLD and LLD was required.
It supports 3 mode:

1. Player vs. AI
2. Player vs. player (Offline)
3. Player vs, player (Online)

Unfortunately, I was unable to clear this round.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-set-435-for-sde-2/

1053
Chapter 443

Amazon Campus Drive (For


Semester-Long-Internship)

Amazon Campus Drive (For Semester-Long-Internship) - GeeksforGeeks


Round 1: Online Test (Duration : 2 hours 30 minutes)

• It had around 20 Multiple Choice Questions related to fundamentals of Computer


Science and 2 Programming questions.
• The Programming questions were :
– 1) Find the length of the smallest substring consisting maximum number of dis-
tinct elements. (https://www.geeksforgeeks.org/length-smallest-sub-string-consisting-maximum-distinct-
– 2) Find number of ways to denominate a given amount using coins of 3, 5 and
10. Similar problem- (https://www.geeksforgeeks.org/count-number-ways-reach-
given-score-game/)
• Around 30 students were selected for the second round.

Round 2: 1st F2F Round (Duration : 50-55 minutes)

• Started off with the usual “Tell me something about yourself.” The Interviewer was
very friendly.
• He asked me about several types of Tree-based Data Structures and their properties.
(T’s, BT’s, BST’s, AVLT’s, etc.)
• He asked me to write a function that takes the Root Node of a Tree as an input,
returns 1 if the tree is a BST and 0 otherwise.
– I gave him a linear approach with O(n) time-complexity and O(log(n)) or
O(height of the tree) extra stack-space complexity. He was satisfied with it.
• He gave me an array consisting of only 0’s, 1’s and 2’s and asked me to sort it.

1054
Chapter 443. Amazon Campus Drive (For Semester-Long-Internship)

– I gave him the counting sort approach with O(n) time-complexity and O(1) extra
space. He asked me if I could do it in one pass.
– I tried for some time and with the help of few hints I was able to code-out
a segregative approach. Related Articles (http://users.monash.edu/~lloyd/
tildeAlgDS/Sort/Flag/)
• He gave me a weird array of size N where N-1 elements occur K times. The remaining
one element occurs only 1 time. Find that one element which occurs only 1 time.
– I gave him a hashing based solution with time and extra-space complexity of
O(n). He then asked me how std::unordered_map and std::map are implemented
underneath. I briefed him about them. He then asked me if I could do the
problem in O(n) time and O(1) extra-space.
– He told me to think in terms of bits. Then by taking some examples I was able
to arrive at the solution. An example where K = 3 (https://www.geeksforgeeks.
org/find-the-element-that-appears-once/)
• He then asked me some questions related to Gujarat (my native place). How good is
food, tourist places, traveling and all. This discussion went on for 10 minutes. Then
he asked me about some good places to eat in Jaipur (my college was in Jaipur). I
gave a few suggestions. He was very friendly and even told me that I’m sending you
for the second F2F round.

Round 3: 2nd F2F Round (Duration : 50-55 minutes)

• The usual “Tell me something about yourself.” I told him I was the best Counter-
Strike player of the Batch and he was intrigued. He asked if I knew how the game
worked. I was able to give him satisfactory information.
• He asked me to brief him about my previous round, what were my approaches to the
questions.
• He asked me about the basic idea of Dynamic Programming. He asked me about my
thoughts on “Where? and How? are Graphs useful in tackling real world problems.”
• He asked me whether I know about Segment Trees and Fenwick Trees or Binary-
Indexed Trees and about their implementations. He didn’t ask me to code them.
• He gave me an Graph in the form of Adjacency Matrix and a separate array A for
values of the nodes. He told me to transform the array A according to the following
transformation :
– The new node values should be equal to the sum of product of the sum of odd-
value nodes and the sum of even value-nodes in the sub-graph of that node
and the node-value itself. i.e. (new_node_val = old_node_val + PROD-
UCT(SUM(odd_node_value nodes in the subgraph), SUM(even_node_value
nodes in the subgraph) ) )
– A gave him a simple DFS approach. He told me that I was the first one who gave
me the solution and was satisfied.
• He told me that we want to answer Q queries (Q <= 1e4). In each query, we will be
given a number N (N <= 1e4) and we have to return 1 if N can be expressed as sum
of powers of numbers less than X (X <= N). Also anything power 1 is not allowed

1055
Chapter 443. Amazon Campus Drive (For Semester-Long-Internship)

(Otherwise there’s no point in solving as N can always be expressed as N^1). E.g for
N = 242 and X = 7 : return 1 (as 242 = 1^2 + 3^2 + 6^3 + 2^4).
– He gave me a hint to see how many numbers in total can you can use to express
N. Total Numbers = (2^2, 2^3, …… 2^(log2(N)), 3^2, 3^3, ……, 3^(log3(N)), ……,
X^2, X^3, ……, X^(logX(N))). This turned out to be very few.
– At this point I was able to reduce the problem to finding a subset with a given
sum (here N). I gave him DP solution and he was satisfied. Related Articles
(https://www.geeksforgeeks.org/subset-sum-problem-dp-25/)

• Around 7 people were selected and I was glad I could make it. It turned out to be
great experience from my side. The Interviewers were very friendly and helpful.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-campus-drive-for-semester-long-internship/

1056
Chapter 444

Amazon India SDE III


Interview Experience

Amazon India SDE III Interview Experience - GeeksforGeeks


Round 1:
This was on HLD, I was asked a question on how to design an online chess game. The
questions asked were how will you assign a player to another player who wants to play. You
need to think about how to divide your players into multiple groups of ratings, so that a
newbie is not playing a grand master, rather with someone who is of his level only. Then
the question was how will you design your system when a player comes in and say I want
to play, and the max wait time is 1 min, you need to find a player suitable for his level and
think about multiple race conditions.
Round 2:
This was DS round and I was asked two questions
Question1: https://www.geeksforgeeks.org/find-the-row-with-maximum-number-1s/
Question 2: You are given 2 words with equal number of characters. Find an algorithm to
go from first word to second word, changing one character at each step, in such a way that
each intermediate word exist in a given dictionary.
Example:
Words are pit, map. A possible solution:
pit, pot, pet, met, mat, map

Source

https://www.geeksforgeeks.org/amazon-india-sde-iii-interview-experience/

1057
Chapter 445

Amazon Internship Interview


Experience On-Campus

Amazon Internship Interview Experience On-Campus - GeeksforGeeks


Recently Amazon visited our college for hiring 2 months summer interns.
Round 1: It was Online round on HackerEarth consisting of 20 technical questions and 2
Coding questions.
The Coding Questions were as follows:

1. Shortest Path between two cells in a grid. https://www.geeksforgeeks.org/


shortest-distance-two-cells-matrix-grid/
2. Length of smallest substring consisting of maximum Distinct characters. https://www.
geeksforgeeks.org/length-smallest-sub-string-consisting-maximum-distinct-characters/

Technical Questions were also quite easy.


But there is Sectional cutoff in Amazon Shortlist.
Round 2:
After Online Round 40 students were selected for Interview. And there were only 2 technical
Interviews.
In my First Interview Round Interviewer asked me followings:

1. Tell Me about yourself.

2. Then he gave me coding questions.Given a Binary Search Tree (BST), modify it


so that all greater values in the given BST are added to every node. https://www.
geeksforgeeks.org/add-greater-values-every-node-given-bst/ .I asked the inter-
viewer that what about the Integer limits while adding. and this made a
quite good impression on him.

1058
Chapter 445. Amazon Internship Interview Experience On-Campus

3. Reverse words in Given String.Example: Let the input string be “i like this program
very much”. The function should change the string to “much very program this like i”.
But the string is not stored in Normal Character Array. Here each character is a node
in Linked List (including space too).
4. Then he asked me about LRU Cache. and asked about How it is Implemented. i was
not able to answer quite correctly but somehow i came up with Linked List approach.
This round lasted about 45 minutes.I was asked to write code on Paper. The Inter-
viewer was quite helpful.
Round 3: Guys who did good in 1st interview were called for 2nd interview.
The interviewer asked me what questions i was asked in 1st round.

(a) Given a Binary Tree check whether it is sum tree or Not. https://www.
geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree/
(b) Then he asked to design a Data Structure for KeyBoard. Given the layout of
keyboard implement it. I initially gave him matrix based solution but he told me
to think better then i gave him graph based solution.
(c) Then He asked me about my project. Donot write any fake project only do write
your project on Resume if you have done it and you know the basics related to
project very well.

And this Interview also lasted about 40 Minutes. And Finally 15 students were Se-
lected and Luckily I was One of them �
last thing i would like to say is Be Confident.

Please Improve this article if you find anything incorrect by clicking on the ”Improve
Article” button below.

Source

https://www.geeksforgeeks.org/amazon-internship-interview-experience-on-campus/

1059
Chapter 446

Amazon Interview Experience 6


Months Intern for SDE-1

Amazon Interview Experience | ( 6 Months Intern for SDE-1 ) - GeeksforGeeks


Amazon had visited our campus in August for hiring 6 months intern for final year and
summer interns for pre final year (SDE-1). The drive comprised of one online round and
maximum two F2F interviews

Round 1 (online): The online round consisted of 2 coding problems and around 20 MCQ’s
Problem 1 : https://www.geeksforgeeks.org/count-number-ways-reach-given-score-game/
In the above mentioned link they have considered that order does matter but in the online
round they had specified that order does not matter .
Problem 2 : https://www.geeksforgeeks.org/length-smallest-sub-string-consisting-maximum-distinct-characters/
31 students were shortlisted for further rounds.
Advice : The problems that are asked in online round are not that tough, anyone
with little bit of practice can clear it with ease . So keep practicing �

Round 2 ( F2F-1….100 mins ) :The interviewer was cool and he made sure that I was
comfortable and then he started.
He just had a look on my Resume and then started giving me problems
Problem 1: Given M and N.Calculate the number of ways to form M digit number such
that value at any digit can be at most N and value at current digit is at least twice the value
at previous digit(The condition should be satisfied at every digit index, for example if M=3
and N=9 then 136 is a valid number and 135 is invalid)
He said that N can be anything and the final number can contain more than M digits if
you are thinking in decimal number system.Basically he wanted to say that don’t restrict

1060
Chapter 446. Amazon Interview Experience 6 Months Intern for SDE-1

yourself to decimal number system consider a ideal number system with maximum digit
value N.
Hint-Dynamic Programming.

Problem 2: Given a number N (1<=N<=10^5) . Find out if N can be expressed in terms


of a1^n1 + a2^n2 + a3^n3 + ……. +ak^nk ( a1, a2, a3…ak are bases and are >1 and n1,
n2, n3…..nk are exponents and are >0)
if yes count such sequences
Hint – precompute all the powers and then apply dynamic programming

Problem 3 : Given N points in 1-D plane (x -axis) with their co-ordinates and M
boxes.Place M boxes (every box should be placed on one of the N points ) in such a way
that the minimum distance out of distances of every pair of adjacent boxes get maximized
( i.e make minimum distance as large as possible )
Hint-Binary search on answer

I was able to solve all the above 3 problems but i found them very difficult . It took quite
a bit of time and scratching of head to solve them. Interviewer was always supporting and
he was motivating me to solve problem and he kept on giving me hints through out the
interview.
Advice- Be confident and take your time and keep on telling interviewer about what you
are thinking and what your thought process is .He is more keen to see your thought process
rather than your final solution.

Round 3(F2F-2 ….. 50-60 mins): The interviewer was very chill .He just told me to
assume as if I am giving an interview to one of my close friend.Then he started the interview

Problem 1 : https://www.geeksforgeeks.org/shuffle-a-given-array/
Problem 2 : https://www.geeksforgeeks.org/find-next-greater-number-set-digits/
Problem 3 : https://www.geeksforgeeks.org/wildcard-pattern-matching/

Then he shifted his focus towards computer science fundamentals . He asked me to explain
normalization in DBMS and all the normal forms also.
After this he asked me to explain how and why hashing is done ( a small discussion on it )
then he asked me about Map and some STL function on about how they are implemented
in c++ i.e internal working and a little code explanation of them

1061
Chapter 446. Amazon Interview Experience 6 Months Intern for SDE-1

In this round the interviewer was more sort of interested in my approach not the solution
and he didn’t expected me to solve all the problems just was motivating me to approach
nicely.
Round 3 over . Now comes the best part . I was given SLI ( 6 months intern )at Amazon
India and my happiness was sky high.
Final Advice – Practice makes a man perfect.Keep on practicing and your hard work will
always be rewarded.You just have to be patient and confident.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-6-months-intern-for-sde-1/

1062
Chapter 447

Amazon Interview Experience


(On Campus for 2 Month
Internship)

Amazon Interview Experience (On Campus for 2 Month Internship) - GeeksforGeeks


Online Round: An online screening test was organized on Hackerearth. This test con-
sisted of 20 MCQs (+1 -0.25) and 2 coding questions(+100). The MCQs were questions
about output, pointers, programming basics, data structures and DBMS. One of the coding
questions was:
Given a matrix with one source and multiple destinations, calculate the minimum and
maximum distance between source and a destination. Apart from source and destinations,
there were cells which you couldn’t go to.
There was partial marking in coding questions based on the number of test cases passed.
25 were shortlisted from 160+ candidates.
Round 2:
(1) Find the starting node of loop in a linked list.
(2) Rearrange characters in a string such that no two adjacent ones are same :
https://www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/

Source

https://www.geeksforgeeks.org/amazon-interview-experience-on-campus-for-2-month-internship/

1063
Chapter 448

Amazon Interview Experience


SDE2

Amazon Interview Experience SDE2 - GeeksforGeeks


Round 1:
a) Left View Of Binary Tree
b) https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
c) Find number in NxM matrix . Elements are sorted in Rows and columns.
Round 2:
a) https://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/
b) https://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
Round 3:
a) Find Triplets in BST . You are given one number X . You need to print all A, B, C (X
== A+B+C)
b) Print all palindrome strings (length > 1)
c) You have set of n integer numbers . You need to divide this in two parts (if n is even
then n/2, n/2 or if odd n/2, n/2+1) in such a manner that both sets element sum either
equal or have minimum difference (if equal is not possible) .
Round 4:
a) Discussion about project and challenges .
b) Conflicts that raise after your design proposal in your previous projects
c) Design BookMyShow
Round 5:
a) Discussion about project and challenges .

1064
Chapter 448. Amazon Interview Experience SDE2

b) Innovation that help current company .


c) Ability for code reviews .
d) Netflix and LRU caches design .
Round 6:

a) Discussion about project


b) Design Amazon Locker
Round 7:
a) Discussion about project
b) Amazon sell physical product, if amazon starts selling the services and user start buying
the services from different vendors (Airtel/Netflix/ ..).
Amazon should start auto renewal of such services at the time of service expiry .
Ex:- Customer buy service for car cleaning from any seller (register with amazon) for 300Rs
for 30 days . then at the time of its expiry this service should auto renew for next 30 days.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience-sde2/

1065
Chapter 449

Amazon Interview Experience

Amazon Interview Experience - GeeksforGeeks


Round: I
An Array arr={7, 7, 8, 8, 9, 1, 1, 4, 2, 2} has numbers appearing twice or once. Duplicates
appear side by side everytime. Might be few numbers can be occur one time and just assume
this is a right rotating array (just say an array can rotate k times towards right). Aim is to
identify numbers that occured once in array.

#include <stdio.h>
  
int main()
{
    int a[] = { 7, 7, 8, 8, 9, 1, 1, 4, 2, 2 }, i = 1, m = 10;
    // int a[]={7, 8, 8, 9, 1, 1, 4, 2, 2, 7}, i=1, m=10;
  
    if (a[0] == a[m - 1]) {
        i = 2;
        m = m - 1;
    }
  
    for (; i < m; i++)
        if (a[i] == a[i - 1])
            i++;
        else
            printf("%d\n", a[i - 1]);
  
    return 0;
}

Input:
7, 7, 8, 8, 9, 1, 1, 4, 2, 2
Output:

1066
Chapter 449. Amazon Interview Experience

9
4
Round II:
In second round a question asked was asked regarding BST. Sum of key elements in indi-
vidual path of BST (just say this sum as path_ weight) and threshold path weight is given
as input. If any of the pathweight is less than oversold path weight then that should be
deleted from the tree.
Example :
Input:
Consider the below tree as input and threshold path weight is 110.

Output:
Below are the no of paths the input tree can make
path 1 : 50 -> 30 -> 20, Sum = 100
path 1 : 50 -> 30 -> 40, Sum = 120
path 1 : 50 -> 70 -> 60, Sum = 180
path 1 : 50 -> 70 -> 80, Sum = 200
In the current scenario path is less than the threshold path weight (100 < 110), So we have
to destroy the path 1.

1067
Chapter 449. Amazon Interview Experience

Tree after destroying the path 1.

Program for above task:

#include <stdio.h>
#include <stdlib.h>
  
struct node {
    int key;
    struct node *left, *right;
};
  
struct node* newnode(int element)
{
    struct node* temp = (struct node*)malloc(sizeof(struct node));
    temp->key = element;

1068
Chapter 449. Amazon Interview Experience

    temp->left = temp->right = NULL;


    return temp;
}
  
struct node* insert(struct node* root, int element)
{
    if (root == NULL)
        return newnode(element);
  
    if (element < root->key)
        root->left = insert(root->left, element);
    else if (element > root->key)
        root->right = insert(root->right, element);
  
    return root;
}
  
void inorder(struct node* mynode)
{
    if (mynode != NULL) {
        inorder(mynode->left);
        printf("%d\t", mynode->key);
        inorder(mynode->right);
    }
}
  
struct node* minValueNode(struct node* node)
{
    struct node* current = node;
  
    /* loop down to find the leftmost leaf */
    while (current->left != NULL)
        current = current->left;
  
    return current;
}
  
struct node* deleteNode(struct node* root, int key)
{
    // base case
    if (root == NULL)
        return root;
  
    // If the key to be deleted is smaller than the root's key,
    // then it lies in left subtree
    if (key < root->key)
        root->left = deleteNode(root->left, key);
  

1069
Chapter 449. Amazon Interview Experience

    // If the key to be deleted is greater than the root's key,


    // then it lies in right subtree
    else if (key > root->key)
        root->right = deleteNode(root->right, key);
  
    // if key is same as root's key, then This is the node
    // to be deleted
    else {
  
        // node with only one child or no child
        if (root->left == NULL) {
            struct node* temp = root->right;
            free(root);
            return temp;
        }
        else if (root->right == NULL) {
            struct node* temp = root->left;
            free(root);
            return temp;
        }
  
        // node with two children: Get the inorder successor (smallest
        // in the right subtree)
        struct node* temp = minValueNode(root->right);
  
        // Copy the inorder successor's content to this node
        root->key = temp->key;
  
        // Delete the inorder successor
        root->right = deleteNode(root->right, temp->key);
    }
    return root;
}
  
/** Function : checkpathCost(int pathweight, int thresoldPathWeight, 
                         struct node *currentNode, struct node *root)
    This function will sum the all individual elements in a every 
    path and lets say it as pathweight and if the sum less than 
    key then the path will be deleted.
      
    Arguments: 
    pathweight         : Sum of all elements in a path. As we are
                         traversing in recursive mode we the sum of 
                         previews elements.
    thresoldPathWeight : Threshold value to compare the path weight
    currentNode        : CUrrent node in the tree.
    root               : root of the tree, used while deleting the node.  
  

1070
Chapter 449. Amazon Interview Experience

    Output : will delete paths which not satisfy the condition 


             (pathweight<thresoldPathWeight).   
**/
checkpathCost(int pathweight, int thresoldPathWeight,
              struct node* currentNode, struct node* root)
{
    // Add the current key to ath weight.
    pathweight = pathweight + currentNode->key;
  
    // Check the conditionh if current node is a leaf node.
    if ((currentNode->left == NULL) && (currentNode->right == NULL)) {
  
        // If pathweight is less that thresoldPathWeight delete the path
        if (pathweight < thresoldPathWeight) {
  
            // we need to delete the node, so there is no necessity
            // in maintaining the current->key in pathweight.
            pathweight = pathweight - currentNode->key;
            printf("need to Delete %d.\n", currentNode->key);
            deleteNode(root, currentNode->key);
            checkpathCost(0, thresoldPathWeight, root, root);
        }
        else
  
            // If currentNode->key satisfies the condition
            // (pathweight > thresoldPathWeight), need to backtrack
            // back to check with other paths and no necessity in
            // maintaining the current->key in pathweight.
            pathweight = pathweight - currentNode->key;
    }
  
    // If currentNode is not a leaf traverse all the
    // possible paths.
    if (currentNode->left != NULL) {
        checkpathCost(pathweight, thresoldPathWeight,
                      currentNode->left, root);
    }
    if (currentNode->right != NULL) {
        checkpathCost(pathweight, thresoldPathWeight,
                      currentNode->right, root);
    }
}
  
int main()
{
  
    int thresoldPathWeight = 110;
  

1071
Chapter 449. Amazon Interview Experience

    /* Let us create following BST


              50
           /     \
          30      70
         /  \    /  \
       20   40  60   80 */
  
    struct node* root = NULL;
    root = insert(root, 50);
    root = insert(root, 30);
    root = insert(root, 20);
    root = insert(root, 40);
    root = insert(root, 70);
    root = insert(root, 60);
    root = insert(root, 80);
  
    printf("Inorder traversal of the given tree \n");
    inorder(root);
    printf("\n");
  
    checkpathCost(0, thresoldPathWeight, root, root);
  
    printf("Inorder traversal of the given tree \n");
    inorder(root);
    printf("\n");
  
    return 0;
}

In addition to the existing code for BST in geeksforgeeks and below function will implement
the above task.
https://www.geeksforgeeks.org/binary-search-tree-set-2-delete/

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-interview-experience/

1072
Chapter 450

Amazon On-Campus – 6
months Internship (SDE)

Amazon On-Campus - 6 months Internship (SDE) - GeeksforGeeks


Round 1: Coding round + MCQs

There were 2 coding questions and 20 mcqs of variable marks such as 4, 6 and 2 and no
negative marking.
Question 1- Stock span problem
https://www.geeksforgeeks.org/the-stock-span-problem/
Question 2- Zig-Zag traversal. The only catch was the tree was given in the form of array
like 3, 2, 4, 5, null, null, 1, 1, 2, 12. All internal nodes would have either a value or null.
Leaves could be empty. It was more of implementation tester.
24 students were shortlisted. (Mostly based on MCQs because the coding was done by many
).
Round 2: Tech Round (Purely based on GeeksForGeeks DSA)

I was asked about the test and how I solved the questions. Then I was asked
https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-
twice/ . First I was asked my algorithm and then I was asked to code it all on paper.
Then he asked about my hobbies.
13 Students made it to Round 3.
Round 3: Tech Round ( GeeksForGeeks and Problem solving skills tester )

Given a graph create a tree with minimum depth. I was not asked to write the code but
the discussion went on for about 5 to 10 mins.

1073
Chapter 450. Amazon On-Campus – 6 months Internship (SDE)

Then I was asked https://www.geeksforgeeks.org/median-of-stream-of-integers-running-


integers/ .
Next question was LCA in a Binary Tree.
Then using that solution find Distance between two nodes A and B.
Then swap alternate elements in the Linkedlist.

Finally after a whole day of Process 9 Students were selected for Internship and
I was One of Them.
PS- GeeksForGeeks is the go to site for Amazon Interviews !!!!
Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-on-campus-6-months-internship-sde/

1074
Chapter 451

Amazon QA role & Support


Engineer Intern interview
experience

Amazon QA role & Support Engineer Intern interview experience - GeeksforGeeks


Round 1:
First we took an online test(20 mcq’s and 2 programming questions) in our college.
After 3 days Amazon recruiters came to our college.
On that day they asked us to write 2 programs.
1. String contains alphanumeric characters.find the sum of the numbers in that string.
A)Input:- aa123bb4
Output:- 127
B)Input:- bbb5cc5dd12
Output:-22
2. Array contains 1’s and 0’s. Sort the array without using sort function.
A) Input:- 1 0 0 1 0
Output:- 0 0 0 1 1
B) Input:- 0 0 1 0 1 1
Output:- 0 0 0 1 1 1
We have to write the solutions on paper for the above two programs.
The shortlisted candidates are called to round 2.
Round 2:
This is a face to face round.
In this round you are intervied for almost 1 hour.
In this round they will give you some programs and you have to write codes for them.
Some of the programs they asked me in the interview are:-
1) given two binary strings. Perform addition for that
Input:- 1010
1111

1075
Chapter 451. Amazon QA role & Support Engineer Intern interview experience

Output:11001
2) Given a binary tree. Check whether it is a binary search tree or not?
3) perform binary search
4)find the peak elements(the value should be greater than the previous element and the next
element in the array) in the array.
Input:- 5 4 8 6 9 1 10
Output:-5 8 9 10
After qualifying in this round u will be shortlisted for round 3.
Round 3:
In round 3, depending upon the panel they will ask you about your project.
Basic and advanced linux commands that are used for testing.
If you had done a project they will ask you like ” how do you test your project”.
Basic concepts in OS and DBMS.
What is cache memory.
What is IPV4 and IPV6.
How will gmail authenticate your passwords?
In which memory your laptop password is being saved?
Deadlocks.

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-qa-role-support-engineer-intern-interview-experience/

1076
Chapter 452

Amazon Recruitment Process

Amazon Recruitment Process - GeeksforGeeks


About Company:
Amazon is an American electronic commerce and cloud computing company based in Seat-
tle, Washington that was founded by Jeff Bezos on July 5, 1994. The tech giant is the
largest Internet retailer in the world as measured by revenue and market capitalization, and
second largest after Alibaba Group in terms of total sales. The amazon.com website started
as an online bookstore and later diversified to sell video downloads/streaming, audiobook
downloads/streaming, software, video games, electronics, food, toys, and jewelry. The com-
pany also produces consumer electronics—Kindle e-readers and Echo — and is the world’s
largest provider of cloud infrastructure services (IaaS and PaaS). Amazon also sells certain
low-end products under its in-house brand AmazonBasics.
In 2015, Amazon surpassed Walmart as the most valuable retailer in the United States by
market capitalization. Amazon is the fourth most valuable public company in the world
(behind only Apple, Alphabet, and Microsoft), the largest Internet company by revenue in
the world, and after Walmart, the second largest employer in the United States.
Know more about Amazon >>

Recruitment Process:
Amazon conducts 5-6 rounds to select freshers as SDE (SDE-1) in their organization. The
following rounds are conducted:

• Written Round
• Online Coding Round

1077
Chapter 452. Amazon Recruitment Process

• Multiple Technical Rounds


• Hiring Manager Round
• HR Round

Written Round:
The Written round majorly consists of two sections namely Aptitude / Logical Test and
technical test. The technical test contains questions mainly from C, C++, Operating System,
Data Structure, inheritance, functions. Generally in MCQ format with a given time frame
of about 30 minutes.
Online Coding Round:
This round is hosted online and the candidates are presented with 3-4 coding questions, the
questions are of intermediate difficulty, mainly from Arrays, strings, and matrices.
To clear this round, one should have a strong understanding of these data structures.
Telephonic Round:
This round is purely algorithmic based with around 2-4 questions ranging from arrays, trees,
to dynamic programming problems. You are to present algorithm and in some questions,
the code also if necessary. Apt candidates are selected for further rounds.
Technical Round 1:
Technical rounds are face-to-face algorithmic rounds in which candidates are presented with
2-4 questions, all from data structures. The most commonly asked DSs are the matrix,
binary tree, BST, Linked list.
Technical Round 2:
Same as previous round, however the difficulty is increased and more questions from Trees,
BST, and Tries are asked. One should have a clear knowledge of tree-based recursion, and
the standard questions based on it are a must.
Hiring Manager Round:
This is generally the most technical-intensive round, with questions ranging from the projects
you have done, the technology used in them, design problems and DS/Algo problems and
tricky puzzle-like questions.
HR Round:
You can expect HR questions like :
1. Tell me about Yourself, your family
2. How do you see yourself five years from now?
3. What are your strengths and weaknesses?
4. Some technical questions can also be asked from topics like OOPs.
Questions asked in Amazon:

1. Kadane’s Algorithm
2. Angle b/w hour and minute hand
3. Inversion of array
4. Paranthesis Checker
5. 0-1 Knapsack
6. k Largest elements
7. Longest Palindromic

1078
Chapter 452. Amazon Recruitment Process

8. Array to BST

Interview Experiences:
Amazon interview experience | SDE 1
Amazon interview experience | SDE 1
Amazon interview experience | SDE 1
Read all Amazon Interview experiences
Where to apply?
Amazon Careers

Source

https://www.geeksforgeeks.org/amazon-recruitment-process/

1079
Chapter 453

Amazon SDE-2 Interview


Experience

Amazon SDE-2 Interview Experience - GeeksforGeeks


Round-1 (Telephonic)
The first round comprised of 3 questions:

1. There are n balls of different weights, we need to melt all the balls to make a new big
ball. The cost to melt two balls is equal to sum of their weights. We need to melt the
balls with minimum cost.
For example if we are given 4 balls of weights 4, 3, 2 and 6. We can melt the balls in
following ways.
1) First melt balls of weight 2 and 3. Now we have three balls of weight 4, 6 and 5.
2) Now melt balls of weight 4 and 5. Now we have two balls of weight 6 and 9.
3) Finally melt the two balls and all balls have melted to a big ball.
Total cost for melting all balls is 5 + 9 + 15 = 29
This is a variation of connecting ropes question on geeks: https://www.geeksforgeeks.org/connect-
n-ropes-minimum-cost/
2. Find k largest/smallest elements in an infinite stream of integers. Elements in the
stream can be in any order.
https://www.geeksforgeeks.org/kth-largest-element-in-a-stream/
https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/

Round-2 (F2F Round-1)

1. https://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/
Working code was expected on the paper. We discussed many approaches to solve the
questions. He picked one out of those and asked me to write a production ready code.
He was very happy with the code and left without asking another question �

1080
Chapter 453. Amazon SDE-2 Interview Experience

Tips :- Take your time and thought through the code you are about to write. THINK
ALOUD!! Write a rough pseudo code before the actual code so that you get an idea of all
the variables you will be needing and maintain modularity of the code. Do dry run the code
with the edge cases.
Round-3 (F2F Round-2)
1) LLD of a system in which players can play in a tournament of matches. A match is
played between 2 players. Assume you have sufficient 2^k registered players ready for a
tournament. Match Flow:
Player 1 and 2 rolls a dice one by one and a single chance is given to each player. There is
an umpire who also rolls dice after the two players and he calculates the absolute difference
between the number on the dice with the two players. The player having minimum diff with
the umpire score wins the game. If there is a tie, then umpire chooses to throw a coin and
the two players get to choose a face, and decides the winner.
2-3 behavioural questions.
I screwed up this interview. I created an average design. He didn’t seem happy about it.
Tips: Don’t get disheartened. You will get two more design rounds to ace the process.
Round-4 (F2F Round-3)
1) There were two interviews in this round. They asked me to design a movies reviews
aggregator system. Data should be fetched from movie rating providers like imdb, rotten
tomatoes, etc
We had a lot of discussions regarding the issues you might face if the reliability of the movie
rating providers goes down/up or you remove a provider or you add a new provider. eg
you consider imdb to be more reliable(some factor) than rotten tomatoes in your rating
calculations. How you will keep the data. How you will perform search. Is it a NRT data
or you will do the data processing offline. How do you rank your listing of movies. Lot of
factors were discussed and we end up with a good design. Both of the interviews seemed
happy.
Tips: Don’t lose your calm if any of the round goes average or even below average. They
will tell you very genuine drawbacks in your design and you need to evolve your design. This
is what they are looking for.
Round-5 (F2F Round-4) Hiring Manager
1) All together there were 10-15 behavioural questions to check the candidate’s alignment
towards the amazon leadership principles. It’s a must to enter into Amazon.
Use STAR( Situation, Task, Actions, and Results) approach to answer each of these ques-
tions.
eg. xxx was the situation. yyy are the tasks you identified. you executed the tasks. zzz was
the result.
2) There is a device like kindle where you can buy books and read them. You can read the
same content using kindle app on other devices as well like on your phone, tab etc. There
was a problem in that and he need a design to solve this. The problem is suppose I was
reading an xyz book and I was on a specific page let’s say at 60. Now I closed the app on
the device and I opened the same book on other device. The same page should open where
I left on the other device. How will you handle the actions user take when he is offline. Lot
of discussion around this.
He was very happy about the design. I solved it using operational transformation being

1081
Chapter 453. Amazon SDE-2 Interview Experience

used by the websites for online collaboration like google doc, collabedit etc.

Source

https://www.geeksforgeeks.org/amazon-sde-2-interview-experience/

1082
Chapter 454

Amazon SDE intern experience

Amazon SDE intern experience - GeeksforGeeks


Round 1: The first round was an online coding +aptitude + debugging test. There were
2 coding questions – is path possible in 2 D matrix and the other one was very similar to a
linear search in a 2D matrix. 70 minutes were provided for these questions. The debugging
questions were also fairly easy, simple replacement of || operator by && types. The aptitude
questions were also simple and ample time was provided for them. Candidates had to solve
both coding questions, all debugging questions and perform well in the aptitude section also
to qualify for the next round.
Round 2: The second round was an interview round. My interviewer asked me 4
questions and also asked me to code all of them after discussing the solution. The first
question was https://www.geeksforgeeks.org/next-greater-element/, optimized solution
was expected. The second question was to find the mirror tree of a given binary tree.
The third question was similar to the first question, the interviewer thought of the
question on the spot but if someone knew the answer to the first question then this
question would not be a problem. The last question was to find the min cost of joining
n rods, the solution to this question can be found on GfG. There were no more rounds
conducted for the candidates, amazon selected the candidates on the basis of these 2 rounds.

Source

https://www.geeksforgeeks.org/amazon-sde-intern-experience/

1083
Chapter 455

Amazon Web Services(AWS)


Interview Experience
(On-Campus)

Amazon Web Services(AWS) Interview Experience (On-Campus) - GeeksforGeeks


AWS hiring process has 5 rounds.
First Round:
First round is online test, which has four sections.section-1 has quantitative aptitude, logical
reasoning questions.sections-2 has technical questions related to c, c++, java, dbms, os
and networks.section-3 has 2 coding questions.section-4 has technical questions related to
bigdata, cloud computing and data science.time given is 2 hours.They shortlisted 41 students
out of 450.
Second Round:
Technical round:asked general questions about networking, os and troubleshooting.
1.What are the advantages of having virtual memory?
2.How to trouble shoot windows system which has booting problems?
3.gave one simple code to implement and some general questions
16 students shortlisted for the next round.
Third Round:
Technical round:asked all networking questions.
1.What are the softwares you have used?
2.How to prevent SYN DDoS attack?
3.How to indentify fake IPs?
4.What is the difference b/w private IP and Public IP?
5.questions related OSI and TCP layers
6.Port numbers of different protocols
7.What happens when you type on your browser?
8.questions related to DNS

1084
Chapter 455. Amazon Web Services(AWS) Interview Experience (On-Campus)

to clear this round you have to be master in networking.


12 students shortlisted for the next round.
Fourth Round:
Managerial Round
Fifth Round:
HR Round
They selected five members for FTE+Internship

Please Improve this article if you find anything incorrect by clicking on the ”Improve Article”
button below.

Source

https://www.geeksforgeeks.org/amazon-web-servicesaws-interview-experience-on-campus/

1085
Chapter 456

Amazon telephonic interview


questions for SDE 1

Amazon telephonic interview questions for SDE 1 - GeeksforGeeks


Ques1. Find top 10 selling product given the count of sales of each product.
Ques2. Design a valet parking lot with basic use-case of assigning ticket to customer and
retrieving the car later. Three sizes available. Use best fit and nearest distance.
All Practice Problems for Amazon !

Source

https://www.geeksforgeeks.org/amazon-telephonic-interview-questions-sde-1/

1086
Chapter 457

Amazon’s most asked interview


questions

Amazon’s most asked interview questions - GeeksforGeeks


1) K largest elements from a big file or array.
2) Find a triplet a, b, c such that a2 = b2 + c2 . Variations of this problem like find a triplet
with sum equal to 0. Find a pair with given sum. All such questions are efficiently solved
using hashing. – Practice here
3) Binary tree traversal questions like left view, right view, top view, bottom view, maximum
of a level, minimum of a level, children sum property, diameter etc.
4) Convert a Binary tree to DLL – Practice here
5) Lowest Common ancestor in a Bianry Search Tree and Binary Tree.
7) Implement a stack with push(), pop() and min() in O(1) time.
8) Reverse a linked list in groups of size k – Practice here
9) Given two numbers represented by two linked lists, write a function that returns sum list
– Practice here
10) Rotate a matrix by 90 degree.
11) Stock span problem
12) Next greater element
12) Some Dynamic Programming problems like:

• Maximum sum subarray such that no elements are consecutive – Practice here
• Edit distance
• Assembly line scheduling

1087
Chapter 457. Amazon’s most asked interview questions

13) Why Amazon?


14) Questions about projects done in previous company or final year.
Also see

• Amazon Interview Experiences


• Amazon Practice Questions
• Amazon’s most frequently asked Questions – Set 2

You may also like to see following Amazon Interview Video.


Please write comments if any common question is missed.

Source

https://www.geeksforgeeks.org/amazons-asked-interview-questions/

1088
Chapter 458

Amazon’s most frequently asked


interview questions | Set 2

Amazon’s most frequently asked interview questions | Set 2 - GeeksforGeeks


Amazon’s Most Frequently Asked Questions | Set 1
Level – Easy

1. Get minimum element from stack – Practice here


2. Serialize and deserialize a binary tree – Practice here
3. Print a binary tree in a vertical order – Practice here
4. Celebrity problem – Practice here
5. Level order traversal
6. Swap the kth element from starting and from the end position – Practice here
7. Binary tree to bst – Practice here
8. Max sum in the configuration – Practice here
9. Find the nth element of spiral matrix – Practice here
10. Count the number of occurrences in a sorted array
11. Find the smallest window in a string containing all characters of another string
12. Find the maximum of all subarrays of size k
13. Find the kth smallest element in row wise and column wise sorted matrix
14. Minimum swaps required to arrange pairs
15. There is an array of N numbers ranging from 1 to N. Only 1 number is missing, return
the index of that number
16. Find the second largest and second smallest in a given array in single traversal.
17. Find power(x,y) without using pow function.(divide and conquer approach required)
18. Count possible decoding sequence

Level – Medium

1. Given two string print them inter leaving strings characters

1089
Chapter 458. Amazon’s most frequently asked interview questions | Set 2

2. Minimum cost required to travel from top left to the bottom right in a matrix
3. Maximum difference between node and its ancestors – Practice here
4. Min distance between two given nodes of a binary tree – Practice here
5. Find the number of island – Practice here
6. Topological Sort – Practice here
7. Detect cycle in a directed graph – Practice here
8. Flattening a link list – Practice here
9. Detect a loop in a linked list – Practice here
10. Check if a binary tree is BST or not
11. Min Cost path
12. Count ways to reach nth stair
13. Maximum Subarray Problem
14. Palindrome Partitioning
15. Given a binary tree find the minimum root to leaf height.
16. Implement LRU cache

Level – Hard

1. Boolean paranthesis – Practice here


2. Maximum Index – Practice here
3. Largest Number formed in the array – Practice here
4. Find the length of maximum numbers of consecutive numbers jumped up in an array
5. Delete the elements in a linklist whose sum is equal to zero
6. Given a list of numbers of odd length design an algorithm to remove a number and
divide the rest numbers equaly so as it makes there sum same
7. Find diameter of a binary tree

Also see

• Amazon Interview Experiences


• Amazon Practice Questions
• Top topics for Interview Preparation

You may also like to see following Amazon Interview Video.

Source

https://www.geeksforgeeks.org/amazons-most-frequently-asked-interview-questions-set-2/

1090

You might also like