Amazon Interview Questions
- 2of 2 votes
AnswersWAP to create a mirror of a binary tree. Extend the code or write a new code if not possible to do mirroring at alternate levels . Here in the second part , if the two trees are placed in front of each other , then odd levels should be exact mirror as a whole and even levels should be exactly same . Then write the iterative version for the above codes.
- Kavish Dwivedi July 15, 2013 in India for Bangalore| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 2of 2 votes
AnswersWrite a program to swap kth node from first and kth node from last in a linked list .
- Coder April 18, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven an integer array, return the combinations of 4 array values whose sum is x
- Guest SVM April 12, 2013 in United States for AWS
Eg:
Input int array = {1,2,3,5,0,-2}
Return all possible combinations such that
a+b+c+d = 1
Like: -2 , 0 , -2 , 5
2 , -2 , 0 , 1, etc...| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm - 2of 2 votes
AnswersGiven 3 Arrays of integer sorted in ascending order, get the sum of minimum difference using one element from each array.
- anonymous August 11, 2013 in India
where a, b, c are the elements from each array.
diff = |a-b| + |b-c|+|c-a|
complexitiy: worst case O(n)| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
AnswersHow can we implement spell checker.
- rapirapp July 04, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Data Structures - 2of 2 votes
AnswersWhy Amazon?
- scorpionking September 18, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Behavioral - 2of 2 votes
AnswersGive the inorder,postorder& preorder forms of a tree in a single traversal
- Raady October 14, 2008| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Trees and Graphs - 2of 2 votes
AnswersVerify if the given strings is an anagram.
- hadeebataj May 10, 2019 in India
Ex: Str1: LISTEN, Srt2: SILENT.
Alter the program if there is more than one letter that repeats in any one of the strings.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer String Manipulation - 2of 2 votes
AnswersWrite a code to return a value 'True' if the number '1' throughout the array appears consecutively. Ex: S = {1,1,1,0,0,3,4}.
- hadeebataj May 10, 2019 in India
Else, return 'False' if the array does not have the given number (char = '1' in this case) in the consecutive order. Ex: S = {1,1,0,0,1,3,4}| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - 2of 2 votes
AnswersGiven a sorted array with "n" elements, distributed them into "k" nearly equally weighing buckets.
- reddy88 April 02, 2017 in United States
Space is not constraint.
Ex: [1,3,6,9,10]
bucket size: 3
output:[10],[9,1],[3,6]| Report Duplicate | Flag | PURGE
Amazon SDE-2 Dynamic Programming - 2of 2 votes
AnswersGiven a matrix of positive integers, you have to reach from the top left corner to the bottom right in minimum cost. You can only go one square right, down or diagonally right-down. Cost is the sum of squares you've covered. Return the minimum cost.
- mrityunjay21 July 26, 2016 in India for Payments
e.g.
4 5 6
1 2 3
0 1 2
Answer: 8 (4+1+0+1+2)| Report Duplicate | Flag | PURGE
Amazon SDE-2 Dynamic Programming - 2of 2 votes
AnswersWrite a function that accepts two character arrays each represents a floating point number and return their sum in character array.
- jaip42 May 10, 2015 in India for Kindle
For example function accepts "23.45" and "2.5" and return their sum "25.95".
Restriction: We cannot use predefined functions / methods or parsing. We have to go with basic operations.| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 2of 2 votes
AnswersGiven MxN matrix which contains 1s and 0s, find the largest sub matrix which contains most number of 1s. condition is that each row in the sub matrix must contain at-least one 1.
- Nascent May 04, 2014 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 2of 2 votes
AnswersYou 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?
- mail.kshitij.jain October 06, 2013 in India
Eg. [1,5,3,7,2] – then answer is 2 units between towers 5 and 7.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersA prefix of a string S is any leading contiguous part of S. A suffix of the string S is any trailing contiguous part of S. For example, "c" and "cod" are prefixes, and "ty" and "ity" are suffixes of the string "codility". For simplicity, we require prefixes and suffixes to be non-empty and shorter than the whole string S.
A border of a string S is any string that is both a prefix and a suffix. For example, "cut" is a border of a string "cutletcut", and a string "barbararhubarb" has two borders: "b" and "barb".
We are looking for such borders of S that have at least three non-overlapping occurrences; that is, for some string that occurs as a prefix, as a suffix and elsewhere in between. For example, for S = "barbararhubarb", the only such string is "b".
In this problem we consider only strings that consist of lower-case English letters (a−z).
Write a function:class Solution { public int solution(String S); }
that, given a string S consisting of N characters, returns the length of its longest border that has at least three non-overlapping occurrences in the given string. If there is no such border in S, the function should return 0.
- onecitizen.ca July 18, 2013 in United States
For example, given a string S as follows:
if S = "barbararhubarb" the function should return 1, as explained above;
if S = "ababab" the function should return 2, as "ab" and "abab" are both borders of S, but only "ab" has three non-overlapping occurrences;
if S = "baaab" the function should return 0, as its only border "b" occurs only twice.
Assume that:
N is an integer within the range [0..1,000,000];
string S consists only of lower-case letters (a−z).
Complexity:
expected worst-case time complexity is O(N);
expected worst-case space complexity is O(N) (not counting the storage required for input arguments).| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Algorithm - 2of 2 votes
AnswersHow to detect cycles in a graph?
- rodrigoreis22 February 09, 2013 in United States
Don't need to write code, just your idea and complexity.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersFind the length of maximum number of consecutive numbers jumbled up in an array.
- mrityunjay21 July 26, 2016 in India for Payments
e.g.: 1, 94, 93, 1000, 2, 92, 1001 should return 3 for 92, 93, 94| Report Duplicate | Flag | PURGE
Amazon SDE-2 Arrays - 2of 2 votes
AnswersGiven a string with only parenthesis. Check if the string is balanced.
- teli.vaibhav October 30, 2016 in United States
ex -
1) "<({()})[]> is balanced
2) "<({([)})[]> is not balanced| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
AnswersLucky numbers are those numbers which contain only "4" and/or "5". For example 4, 5, 44, 54,55,444 are lucky numbers while 457, 987 ,154 are not.
- sunny.010203045 January 29, 2014 in India
Lucky number sequence is one in which all lucky numbers exist in increasing order for example 4,5,44,45,54,55,444,445,454,455...
Now we concatenate all the lucky numbers (in ascending order) to make a lucky string "4544455455444445454455..."
Given n, your task is to find the nth digit of the lucky string. If the digit is 4 then you have to print "Hacker" else you have to print "Earth".
Input:
first line contain number of test cases T , next T line contain a single interger n.
Output:
For each test case print "Hacker"(without quotes) if nth digit of lucky string is "4" else print "Earth"(without quotes) if nth digit of lucky string is "5".
Constraints:
1<=t<=10^5
1<=n<=10^15| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
AnswersIs it possible to compare two Binary trees for equality in iterative manner without using extra space?
- Algorithmist June 17, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersCreate a function that will reverse the words in a sentence.
- Kevin.Pheasey April 10, 2013 in United States for AWS| Report Duplicate | Flag | PURGE
Amazon Web Developer JavaScript - 2of 2 votes
AnswersGiven a Binary tree and value X. Find X in the tree and return its parent
- neelabhsingh January 18, 2017 in India for Hyderabad
X:
10
4 3
5 7 9 8
If X = 7, return 4| Report Duplicate | Flag | PURGE
Amazon SDE-2 Trees and Graphs - 2of 2 votes
Answersfind the maximum depth in a binary tree.
- pooja January 31, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern - 2of 2 votes
AnswersGiven an array of type:-
- anupjunagadecat November 25, 2014 in India for 11
1. Increasing
2. Decreasing.
3. Increase-Decrease
4. Decrease-Increase
Find:- 1. Type of array in minimum steps ?
2. Maximum element from array in min steps?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a file containing a list of ip addresses that have lost their dots(.'s), write a program to find the ip addresses, assume ipv4. input: 11111 output. 1.1.1.11, 11.1.1.1, etc
- rk August 09, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
AnswersWrite a function to return string when passed integer . Note : do not use tostring() in built function.
- raghunath.e November 14, 2019 in United States
E.g 123 --> "123"| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test technical - 2of 2 votes
AnswersPassword Suggestor: Replace s with $ and a with @ and produce all password suggestions.
- Interviewee2017 May 03, 2017 in United States
For Example: Password : P@ssword, P@$$word,pas$word etc..| Report Duplicate | Flag | PURGE
Amazon Software Developer - 2of 2 votes
AnswersGiven a binary tree print it in inward spiral order i.e first print level 1, then level n, then level 2, then n-1 and so on.
- neer.1304 December 10, 2015 in United States
For Ex -
1
2 3
4 5 6 7
8 9 10 11 12 13 14 15
Print- 1 15 14 13 12 11 10 9 8 2 3 7 6 5 4
Follow up question - Extend the algorithm to n-ary tree.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 2of 2 votes
AnswersYou are given a function: List<TimeSlot> getTimeSlots (String friend)
- h3ssam March 15, 2015 in United States
Assume getTimeSlots() returns available times for a friend, sorted in order, with no overlap.
Assume TimeSlot has comparable function
You want to schedule a meeting among all of your friends, such that all can attend.
Implement a function to get the first 3 common TimeSlots among all your friends:
List<TimeSlot> get3CommonTimeSlots (List<String> friends)
user1 1-2pm, 3-4pm, 7-8pm
user2 1-2pm, 5-6pm| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm