Open In App

Amazon Interview | Set 125 (On-Campus for Internship)

Improve
Improve
Like Article
Like
Save
Share
Report

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 https://www.geeksforgeeks.org/. 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.

Q2- Rotate the alternate levels of a binary tree.

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                             
                  /     \                    
                 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
7 6 5 4
3 2
1


Last Updated : 14 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads