Amazon Interview Questions
- 0of 0 votes
AnswersA co-ordinate plane was given. On each point (x, y) there are x+y number of apples on it. A person is standing on (0, 0) and he wants to buy a square plot having N number of apples inside it (including the periphery). Question was to return the value of perimeter of that square plot given N.
- 200MITTALGAUTAM August 26, 2019 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersIn a garden, there are several apples trees planted in a grid format. Each point (i,j) in the grid has |i| + |j| apples.
Allie can buy a square plot centred at (0,0). Find the minimum perimeter of the plot (1 unit having length = 1) such that she can collect at
least X apples. All plants on the perimeter of the plot are also included.
Sample:
- bertram_gilfoyle June 27, 2019 in IndiaInput = 1 Output = 8 input = 11 Output = 8 Input = 13 Output = 16
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 2 votes
AnswersGiven an array of integers A. calculate the sum of A[i] %A[j] for all possible i,j pair. return sum%(10^9+7) as an output solve this problem on o(n).
- Dhioyt June 19, 2019 in India
input :-
A=[1,2,3]
Output:-
5
Explanation:-
(1%1)+(1%2)+(1%3)+(2%1)+(2%2)+(2%3)+(3%1)+(3%2)+(3%3)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
Answers"Good Range"
- Mit25 May 29, 2019 in United States
There is a number space given from 1 to N. And there are M queries followed by that. In each query, we were given a number between 1 to N (both inclusive). We add these number one by one into a set.
Good range: A range in which there is exactly one element present from the set.
For each query, we need to find the good ranges. We need to return the sum of boundry of all good ranges.
Input:
First line will take two integer for input N and M.
Then following M lines would be numbers between 1 and N (both inclusive).
Output:
Following M lines contains sum of boudaries of good ranges.
Note:
Range can consist of single element and represented as (x-x) where boundary sum will be x+x.
Example:
Input:
10 4
2
5
7
9
Output:
11
18
30
46
Explaination:
step-1) set: 2
good range: (1-10)
sum: 1+10=11
step-2) set: 2 5
good range: (1-4), (3-10)
sum: 1+4+3+10=18
step-3) set: 2 5 7
good range: (1-4), (3-6), (6-10)
sum: 1+4+3+6+6+10=30
step-4) set: 2 5 7 9
good range: (1-4), (3-6), (6-8), (8-10)
sum: 1+4+3+6+6+8+8+10=46| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 0of 0 votes
AnswersGiven an array of edges between any two points in 2 dimensional space. A single edge is represented by the co-ordinates of two points it is connecting for example (2,3),(4,5) represents and edge connecting points (2,3) and (4,5).Find out the total number of squares possible if all edges are parallel to X or Y axis.
- jadonv January 26, 2019 in United States
NOTE : Include overlapping squares, squares having one side in common and squares contained within another square. Co-ordinates can have float values.
Example below -
I have considered a very simple input and output combination to keep it short.
Input
{
(0,0),(0,3)
(0,0),(3,0)
(0,3),(3,3)
(3,0),(3,3)
}
Output : 1
Possible Approach : Create a map as below -
Key(Slope of Edge in Degrees) - Value(Array of Edges)
0 - {(0,0),(3,0)},{(0,3),(3,3)}
90 - {(0,0),(0,3)},{(3,0),(3,3)}
While inserting edges in the map, make sure the edges are sorted by max(x1,x2) first and then max(y1,y2).
Pick 2 edges from one slope let's say slope 0, then pick 2 edges from slope 90 and see if square is formed or not. If square not formed, then look at next 2 edges of slope 90 and so on.
Sorting here is an expensive operation.
Please share any better solutions.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - -2of 4 votes
AnswersHow should I prepare for the interview with Alexa team at Amazon?
- ihsihs005 October 17, 2018 in United States for Alexa| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswerGiven two arrays. One is for tasks (Processes) and each element depicts the amount of cores required to run the task. 2nd array is an array of CPU where each element depicts the no of cores in it.We have to tell how many maximum number of tasks can be allocated. Example: Task: [3, 5, 7], Cores: [1, 3, 5] . Here only task 0 and 1 can be allocated to CPU 1 and 2 . So, answer=2.
- Anil Kumar July 23, 2018 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a BST of memory sizes. Find best fit for a memory block of size M.
- akisonlyforu June 11, 2018 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswerGiven an infinitely large array and every element has tags associated with them, and there are about 10,000 tags (say) then sort the given array to get all tag-0’s first, tag-1’s next and so on in O(n).
- Ankita June 10, 2018 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - -1of 3 votes
AnswersFor Amazon SDE-1 On Campus Interview, what are the topics I should study in Database Management ?
- akisonlyforu June 08, 2018 in India
Just don't name the topics. Please elaborate too.| Report Duplicate | Flag | PURGE
Amazon SDE1 Database - 1of 1 vote
AnswersGiven k, and a binary string, determine if this contains all permutations of length k.
- ajay.raj May 24, 2018 in United States
For example, 11001 contains all possible binary sequences with k=2 (00,01,10,11)| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersYou have been given a generator string ab from which any number of strings can be generated recursively by inserting ‘ab’ at any location. You have been given an input string to check if that given string is valid or not.(i.e. generated by given with given string.)
- akisonlyforu May 22, 2018 in India
eg.
Input: aabbab
Output: valid
Input: abbaab
Output: Invalid
I could not come up with a algorithm less than O(N*N)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswerGiven a multiple tree, and multiple nodes that need to be deleted,
- ajay.raj May 17, 2018 in United States
It is required to return a list of nodes so that the children of these nodes can be found after the nodes have been deleted.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersGives you an int m, and a set of char (0,1,2,3,4,5,6,7,8,9)
- ajay.raj May 17, 2018 in United States
Lets you implement a function that generates a id based on the characters in the set. Each time you return a string, it must be unique. satisfying the same character can not appear consecutively more than m times, such as m = 3, "1000" is valid,
"0000" is not valid.
The smaller the string, the better.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersLet’s say you have two input arrays with sorted elements. Find the union.
- prasad.hybris May 16, 2018 in United States
a[] = {2, 10, 14, 19, 51, 71}
b[] = {2, 9, 19, 40, 51}
Union = {2, 9, 10, 14, 19, 40, 51}| Report Duplicate | Flag | PURGE
Amazon SDE1 Java - 0of 0 votes
AnswersA group of friends are tracking the miles per gallon for each of their cars. Each time one of them fills up their gas tank, they record the following in a file: His or her name The type of car they drove How many miles driven since they last filled up How many gallons purchased at this fill up Date of the fill Their data is formatted as a comma separate value (csv) file with the following format for each row:(#person,carName,milesDriven,gallonsFilled,fillupDate) Miles are recorded as floating-point numbers and gallons as integers. Please create a program that allows members of this group to determine the miles per gallon (MPG) of each of their cars during a specific time range. Note: person may have more than one so a time range query might need to output data for one or more cars. A skeleton class will be provided; your job will be to complete the program. The principal function for querying MPG is of the form (the exact name, data types, etc., can be learned by inspecting the "solution" class in the skeleton code): GetRangeMPG(PersonName, StartDate, EndDate) Returns list of objects containing (CarName, MPG) MPG is calculated as (total miles traveled during time period)/ (total gallons filled during time period. The dates you receive in the query should be treated inclusively.
- pragramticProgrammer May 15, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 .Net/C# - 1of 1 vote
AnswerTo push dominoes, find out how many dominoes are standing in the end
- ajay.raj May 15, 2018 in United States
For example, the input is ".R...RL..R..L..", which means pushing the 2nd, 6th, and 12th dominoes to the right and pushing the 8th and 15th dominoes to the left. This example returns 4th. 1,7,16,17 blocks are standing| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersThe question is that there are a lot of vm, what is the total vm consumption max. For example, (2,4,8), (3,5,3) this input,
- ajay.raj May 15, 2018 in United States
This means that 2 to 4 seconds have a memory usage of 8 and 3 to 5 seconds of 3, so the answer is 11 at 3 seconds.
Return 11 to it. Note that (1,2,3) and (2,3,4) such that the middle 3+4=7 is good.
Follow up is usage is not constant, such as (1,2,1,2) the first second usage is 1,
The second second is 2, the linear increase, the highest is how much.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven as list of movies in a csv file, extract the movie name and genre and be able to return a query based on the years and the genre.
- pragramticProgrammer May 13, 2018 in United States
Basically, Parsing a CSV input file and build an indexed data storage to allow search the data in time manner.| Report Duplicate | Flag | PURGE
Amazon SDE1 .Net/C# - 0of 0 votes
AnswersGiven a list of tasks each with memory requirements and time, only one machine has K memory.
- ajay.raj May 12, 2018 in United States
Do not consider the context switch, page swap, virtual memory, (for example, the machine has only 20mb memory, a task that requires 25MB of the task can only wait until there is enough memory to run it.) The running task cannot be suspended.
Ask how long it takes to complete all these tasks. . .| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersHow many squares are inside a m*n rectangle where some grids in the rectangle were grey and the gray grid could not appear in the small squares.
- ajay.raj May 03, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersGiven an int array, check if all the numbers can be divided into 5 consecutive numbers.
- ajay.raj May 03, 2018 in United States
Eg: [1,2,2,3,3,4,4,5,5,6] Yes: (1,2,3,4,5) (2,3,4,5,6)
Followup: ask if you know that all the numbers are between 1 and 13,
what's a good optimization.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswerYou have two matrixs, how to move the first matrix
(move up, down, left, and right) so that the two matrix in the two matrixs match most.eg: matrix 1: matrix 2: 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0
Then, after taking matrix1 (1 left shift + 1 down),
- ajay.raj May 03, 2018 in United States
the number of 1 in the match with matrix2 is 3| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answershow to check if two graphs are structurally identical
- ajay.raj May 03, 2018 in United States
class UndirectedGraphNode {
List<UndirectedGraphNode> neighbors;
UndirectedGraphNode() {
neighbors = new ArrayList<>();
}
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
Answersconvert a Sorted array to complete BST
- ajay.raj May 02, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerGive a connected graph, no cycle,
- ajay.raj May 01, 2018 in United States
Find the node where the average distance from all other nodes is the smallest| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerInput: an int array without sorting, then do a binary search on it, and find the number of digits that cannot be found by binary search.
- ajay.raj May 01, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answers<key = "a"; val = "3"; depend_list = null;/>; <key = "b"; val = "a * a";
- ajay.raj May 01, 2018 in United States
Depend_list = {a};/>; <key = "c"; val = "a * b"; depend_list = {a,b};/>;
Lets output a map<key, value>,a -> 3, b -> 9, c -> 27
Follow-up questions: Make a statistic for all keys and corresponding map entries with the same value.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven an array, find an x such that all numbers less than x are equal to themselves. Numbers greater than it are equal to x, and all numbers add up to a target
- ajay.raj May 01, 2018 in United States
For example, [1 3 5 7 9] target=24, answer is8. Because when x=8, the array has only 9>8, so 1+3+5+7+8=24 is the closest to the target.| Report Duplicate | Flag | PURGE
Amazon SDE1