Amazon Interview Questions
- 0of 0 votes
AnswersFind the first non repeating character in a string. For example if the input string "abcdeabc", non repeating character is "e"
- kag May 24, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven a number (200), compare it to four variables (E.G A,B,C,D) and return true if they are all equal to the given number.
- J@sper January 09, 2016 in United States
Do this in the most efficient way, and if possible without if statements.| Report Duplicate | Flag | PURGE
Amazon Computer Scientist C - 1of 1 vote
AnswersPrint all subset of a given set which sums up to ZERO
- apurohit.in January 09, 2015 in India
{8,3,5,1,-4,-8}
so ans will be : {8,-8}
{3,5,-8}
{3,1,-4}
size of set can be upto 50 but elemet of set can be as big as 18 digit number| Report Duplicate | Flag | PURGE
Amazon Dev Lead Dev Lead Algorithm - 0of 0 votes
AnswersGiven an array containing only stars '*' and hashes '#' . Find longest contiguous sub array that will contain equal no. of stars '*' and hashes '#'.
- Peter August 03, 2014 in India
Order (n) solution required| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
Answers(Bar Raiser Round)
- gdg June 26, 2014 in United States
Divide the array(+ve and -ve numbers) into two parts such that the average of both the parts is equal.
Input:
[1 7 15 29 11 9]
Output:
[15 9 1 7 11 29]
Explanation:
The average of first two elements is (15+9)/2 = 12, average of remaining elements is (1+7 +11 +29)/4 = 12| Report Duplicate | Flag | PURGE
Amazon Arrays - 2of 2 votes
AnswersYou are given an array with numbers - [11, 3, 11, 11, 3, 2, 0, -2, 2]
- KevinK February 27, 2014 in United States
You are supposed to write a function that returns the number that appears "odd" number of times.
The solution is obviously using HashMap. But that takes O(n) to create the HashMap and O(n) to lookup. How can one eliminate the second O(n) yet keeping the HashMap?
Hint: Do you really need to count frequency of occurrence of each digit?| Report Duplicate | Flag | PURGE
Amazon Principal Software Engineer Arrays - 2of 2 votes
AnswersGiven an array of integers . Write an algorithm to find all the Pythagorean triples.
- Raj August 31, 2013 in India
Eg : i/p : int arr[ ] = {1,3,4,5,6,7,8,10,11}
o/p: Print 3,4,5 and 6,8,10| Report Duplicate | Flag | PURGE
Amazon - 1of 1 vote
AnswersGiven a String "abcxrrxabcrr"
- vigneshselvakumar January 10, 2013 in United States
Find the first repeated string with minimum 3 character?
Answer is "abc" min 3 characters.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ - 0of 0 votes
AnswersDesign an algorithm to find the least common ancestor of two nodes in a Binary tree(Note: Its not a binary search Tree)
Node Structure is given as
- teja.sbt November 07, 2012 in United States for KindleClass Node{ int data; Node leftchild; Node Rightchild; }
| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Algorithm - 0of 0 votes
AnswersGiven two trees, how do you find one of the tree is a subtree of other?
- hari@hbiz.in August 26, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm Data Structures Trees and Graphs - 0of 0 votes
Answerssearch an element in sorted 3D Array .(Sorted in all the 3 directions) .
- Shobhit July 20, 2012 in United States
best time complexity (less than O(n^2))| Report Duplicate | Flag | PURGE
Amazon C - 0of 0 votes
AnswersGiven two integer unsorted arrays, your task is to compare the BST formed by both the arrays.
- shivi116 June 30, 2012 in India
any o(n) solution???| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 0of 0 votes
AnswersFind the(two) nodes which are at maximum distance in a binary tree?
- grave May 31, 2012 in India
This is not finding the distance but the nodes which are farthest.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Data Structures Trees and Graphs - 0of 0 votes
AnswersYou have an array like ar[]= {1,3,2,4,5,4,2}. You need to create another array ar_low[] such that ar_low[i] = number of elements lower than or equal to ar[i] in ar[i+1:n-1].
- abc July 09, 2010
So the output of above should be {0,2,1,2,2,1,0}
Time complexity : O(n)
use of extra space allowed.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersWrite second most repeating word in a string
- hello world June 28, 2017 in United States
eg aaa bbb ccc aaa bbb aaa
answer - bbb| Report Duplicate | Flag | PURGE
Amazon SDET - 0of 2 votes
AnswersGiven an array, find the first element that appears an even number of times.
- techinterviewsintesys December 14, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Applications Developer - 1of 3 votes
AnswersYou are given a 2D Array that contains only 0s and 1s in sorted order. i.e. First Os and then 1s.
- tihor January 24, 2015 in India
Array:
0 0 0 1
1 1 1 1
0 0 1 1
0 1 1 1
You have to figure out the row that contains maximum number of 1s.
e.g. in above case we have row 2 as the answer.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 3of 3 votes
AnswersThere are N floors and N persons each one is tagged with some random unique number between 1 to N(represents floor number).
- bharat May 31, 2013 in India
We have a lift which can accommodate one person at a time. Every person is in some random floor.
Initially lift is at floor 1 and all floors have single person. Problem here is.. we have to move the persons to their corresponding floor with minimum travelled distance of lift.
Restriction : Lift can have at most one person at a time.
One more thing we have to think of is .. At a time, we can keep more than one person in a floor.. means, we don't necessarily need to take the person out from the floor if we keep another person on the same floor.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersWrite a program that takes an array of numbers, and then prints out all the possible pairs of numbers that sum up to the value N.
- Anil December 23, 2012 in United States for AWS
E.g., if the array contains the numbers {0, 1, 2, 2, 3, 4, 5} and the target value N is 4, then the output would be (0, 4), (1, 3), (2, 2).| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Java - 0of 0 votes
AnswersGiven two arrays, A and B, both containing integers, find values that appear in both arrays and output them.
I knew the fastest answer to this, which is basically adding array A to a hashmap and then checking if that map contains each element of B, which is an O(n) operation, but uses memory in O(n) as well. The interviewer then asked if I could figure a way of doing this with a complexity of O(n) without using any extra memory, basically just O(1) for memory.
Is this possible? I could not think of a simple quick solution for this on the fly, but I imagine it is possible.
Here is the code I wrote during the interview.import java.util.*; public class ArrayFun { public static void main(String[] args) { int[] a = {1,2,3,4}; int[] b = {2,5,6,7,3,2}; ArrayList<Integer> matches = ArrayFun.findMatches(a,b); for (int i = 0;i<matches.size();++i) { System.out.println(matches.get(i)); } } public static ArrayList<Integer> findMatches(int[] a, int[] b) { HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); ArrayList<Integer> matches = new ArrayList<Integer>(); for (int i = 0;i<a.length;++i) { map.put(a[i],0); } for (int i = 0;i<b.length;++i) { if (map.get(b[i]) != null && map.get(b[i]) == 0) { map.put(b[i],1); matches.add(b[i]); } } return matches; } }
Also, another quick question, is it typical for a phone interviewer to only ask you one question? I think it would be kind of difficult to ask more than one technical question, including coding, in such a short amount of time, i.e. < 1 hour
- M.Zimmerman6 November 08, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
AnswersHow do you partition an array into 2 parts such that the two parts have equal average? Each partition may contain elements that are non-contiguous in the array..
- GillY January 17, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Algorithm - 0of 0 votes
AnswersPrint a linked list recursively in a reverse manner without changing the actual list
- fuckubloomberg July 26, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Amazon Financial Software Developer Software Engineer / Developer Linked Lists - 0of 0 votes
Answerslist1 -->aaa,bbb,ddd,xyxz,...
- codemarathon February 09, 2017 in United States
list2-->bbb,ccc,ccc,hkp,..
list3> ddd,eee,,ffff,lmn,..
Inside a list the words are sorted
I want to remove words which are repeated across the list and print in sorted order
If the words are repeated in same list its valid.
In the above case
it should print aaa-->ccc-->ccc-->eee--->fff-->glk-->hkp-->lmn-->xyxz| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 3of 5 votes
AnswersThere are many sorted arrays. Find a minimum range, so that in each array there's at least one integer within this range.
- edcent February 25, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer Intern Algorithm - 1of 1 vote
AnswersDetermine whether an interger is a multiple of 5 in O(logn) time complexity. You cannot use / and %.
- xuwithsurprise January 20, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 11of 13 votes
AnswersThere 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..
- Vin July 17, 2013 in India
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
2nd – 1/2 litre
3rd - 1/| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersCount the number of shapes in a given (1/0) matrix. A cluster of consecutive (not diagonal) 1's defines one shape.
- iwanna February 18, 2013 in United States
eg
1 1 0 0 1
1 0 0 1 0
1 1 0 1 0
0 0 1 0 0
No of shapes = 4| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm