Recently Amazon visited our college and details are as follows.
There were two questions.
1. N strings are given.Convert all string to corresponding decimal value typed in an Alphanumeric 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.
2. Write a code to print all possible combinations(order matters) of characters of string in lexicographical order.
Output: A, AB, ABC, AC, ACB, B, BA, BAC, BC, BCA, C, CA, CAB, CB, CBA
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 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-
/ \ / \
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 splittedstrings 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.
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!