# Nikhil's Amazon Internship Interview

Recently, Amazon visited DTU campus for its recruitment drive. **Nikhil Kumar** who is also the creater of **AskMunna** - the Coding Blocks Chatbot and several other chatbots was selected. We congratulate for getting selected for Amazon Intern. Nikhil is also an ardent Python developer who loves to build stuff and automate things. For more insight into his projects, check his github repo Nikhil also takes Python workshops at Coding Blocks and has his own blog .We thank him for sharing his interview experiences with this student community.

**PRELIMINARY ROUND**

### Preliminary Round

**Q1** Given an array find the number of triplets whose sum is less than the given value

**Q2** Given a sequence of magic numbers, find the nth term of the sequence. A magic number is defined as the number that can be generated by the sum of distict powers of 5.

Eg 5 = 5

25 = 5^2

30 = 5^2 + 5^1

125

130

150

**ROUND 1**

**Q1** Given a circular linked list of N nodes, break it into 2 circular linked list of equal size. If n is odd, then either list can contain an extra element.

**Q2** Given a paranthesized expression, detect if contains any redunadant parantheses.

**ROUND 2**

**Q1** Given a numeric keypad, find the number of sequences of length N that can be generated under the following constraint.

a) All adjacent numbers can be used to generate the next element of the sequence

Eg N = 1

{0,1,2,3,4,5,6,7,8,9}

Output : 10

N = 2

{11,12,14, 21, 22, 23, 25 …}

Output : 36

**Q2** Given a list of stock prices, you have to detemine the maximum profit that can be generated by buying and selling. You can’t buy/sell without completing a transaction.

Eg {30, 50, 100, 60, 80, 20}

Output : 100 - 60 + 80 - 20 = 100

Nikhil suggested an `O(n*n)`

solution and interviewer was satisfied.