Amazon Interview Questions
- 3of 3 votes
AnswersGiven a set of intervals like 5-10, 5-10, 8-12, 9-15
- blackfever April 03, 2014 in India
Find the ith smallest number in these intervals.
for eg:-
Suppose we have intervals like 5-10, 8-12.
Then total numbers in these two intervals would be: {5,6,7,8,8,9,9,10,10,11,12}
So, 1st smallest number: 5
4th smallest number: 8
5th smallest number: 8 (here is the
change since now we have duplicate elements also) and so on.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersSliding window problem where window size is 3 and we need to find the minimum from the window.
- Vaibhavs April 02, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a list with duplicate values find the first unique elements in it.
- Vaibhavs April 02, 2014 in United States
for eg: BH BH F AL HJ AL HJ PK
so answer is F| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersGiven a matrix and need to traverse through it last position from first position and the matrix has 0 and 1 if there is 1 we cant proceed ahead.
- Vaibhavs April 02, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersCompare two release version and tell me which is larger
- Vaibhavs April 02, 2014 in United States
eg: 1.0.10 and 1.0.2
1.0.2 is greater
1.2.0 and 2.1.0
2.1.0 is greater| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersThere is a file which contains N words. There may be M anagrams in that file, K words on each anagrams. K>=1, M>=1, N>=1. You need to write an algorithm which will create one list for each anagram with k words and group all M lists with one data structure
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersFind your own method to balance an unbalanced binary tree.(you must not use existing methods like AVL, red black or b trees)
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersConvert a sorted integer Array to balanced binary search tree. This is very simple one and I could do it in O(n) time and O(1)extra space
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersGiven 2 sorted linked list , merge them into single sorted list. Change the pointers, don't copy data
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersGiven a read only linked list with next and random pointer , clone the list
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersIt was a design question. You have to design a game. it has different types of monsters and different weapons. hero would shoot monster. each monster would have some initial health. Each weapon would do some predefined damage to monster. when its health gets 0, monster would die/disappear. and there would be multiple levels. based on level, monster and their behavior would change.
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswersGiven 2 rectangles , find whether they are overlapping or not.
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - -1of 1 vote
Answersdelete all the nodes from a binary tree that lie on a path whose sum from root to leaf is less than a given value K. Twist was that the node values can be any integer. It may be a negative number.
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersData structure to push, pop and find min element in O(1) time.
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersGiven a linked list like a1-a2-a3-a4-b1-b2-b3-b4. Convert it into a1-b1-a2-b2-a3-b3-a4-b4
- suresh March 05, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersThere is a dictionary of billion words and there is one method provided
- pavan February 27, 2014 in India
String getWord(int index); We can give it index and it will return the String on that index .
Now word is given to us we have to find out its index. O(logn) solution was required.| Report Duplicate | Flag | PURGE
Amazon SDE1 String Manipulation - 0of 2 votes
AnswersFrog can jump 1 or 2 steps write the code to find out number of ways to go up to n steps
- pavan February 27, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Dynamic Programming - 0of 0 votes
Answersprogram to pruning a binary tree
- pavan February 27, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersYou are given an unsorted array of integers that contain duplicate numbers.
- Muhammad Adel February 20, 2014 in Luxembourg
Only one number is duplicated odd number of duplications, other numbers are repeated even number of duplications.
Find this number.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersFind all nodes that are at a distance k from leaf nodes
- anon123 February 16, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a number N, find the smallest 3 digits number such that product of its digits is equal to N.For example for N=100 , 3 digits number is 455.
- sam February 14, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a function “f” in which 0 occurs with probability 0.4 and 1 occurs with probability 0.6. Using function “f” deduce a new function “f1” such that both 0 and 1 occurs with probability 0.5
- sam February 14, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Problem Solving - 1of 1 vote
AnswersYou are given a n-ary tree. print all the nodes bottom up except for the right most node at each level.
1 2 3 4 a b c d e
print all except 4 (right most at level 1) and e (right most at level 2)
- sukheshmg February 11, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYou are given an unsorted integer array consisting of 1's and 0's. You need to rearrange the array with alternating groups of 0's and 1's. The group length is determined by the function f(x)
- sukheshmg February 11, 2014 in India
f(0) = 1
f(1) = 2
f(n) = [square of f(n-1) - square of f(n-2)]
if you run out of either 1's or 0's, then fill the array with whatever is left.
input: 0,0,1,0,1,1,1,0,0,1,0,0,1,1,0,0
output: 0, 1,1, 0,0,0, 1,1,1,1,1, 0,0,0,0,0
f(1) = 1
f(2) = 2
f(3) = sqr(f(2)) - sqr(f(1)) = 3
f(4) = sqr(f(3)) - sqr(f(2)) = 5
f(5) = sqr(f(4)) - sqr(f(3)) = 16
here we don't have enough 0's left to fill the last group. So, we add the five 0's that were left.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - -1of 1 vote
AnswersHow to find the smallest number with just 0 and 7 which is divided by a given number?
- sunny.010203045 February 10, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 - 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 - 1of 1 vote
AnswersProblem Statement
- sunny.010203045 January 29, 2014 in India
There are three types of tickets and stations available in CodeCountry A, B and C. Tickets of type A can only be bought at stations of type A and end at a station of type B. Tickets of type B can only be bought at stations of type B and end at a station of type C. Similarly, tickets of type C can only be bought at stations of type C and end at a station of type A. Also, you can only travel from station i to station j if j > i, i.e. you can only move forward and if the ticket type bought at station i ends at station j.
The cost of a ticket is j x j if you travel a distance of j. For example if you start at Station 3 and end at station 5 the cost is 2 x 2=4.
Now, you want to travel from Station 1 to Station N using trains in CodeCountry. You are given the type of each station. Output the minimum cost of the journey.
Note that station N will also have a type and you must reach it using a ticket of compatible type. Output -1 if it is not possible to reach from station 1 to station N
Input Format
The first line contains the number of test cases T. This is followed by T lines one for each test case.
Each test case consists of a string representing the types of each station. The i-th character of the string represents the i-th station's type.
Output Format
Output the minimum cost of the journey, one line per test case.
Constraints
The number of test cases is atmost 50.
There will be atleast 2 stations and atmost 15 stations.
The first station (station 1) is always of type A.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 2 votes
AnswersYou are given an array A with elements 0 to n-1, numbers can be repeated in the array. Create n sets where
- sunny.010203045 January 27, 2014 in United States
S[i]={a[i],a[a[i]],a[a[a[i]]]…}. Set has all elements unique. Find the size of the largest set.
Input:
First line contains n, size of the array. n<1000
Next lines contains n numbers, each element of the array
Output
Prints one number: Size of the largest set.
Sample Test Case:
Input: {3,1,2,0}
Output: 2
Explanation:
Four possible sets are
{3,0},{1},{2}{0,3}| Report Duplicate | Flag | PURGE
Amazon SDE1