SDE1 Interview Questions
- 0of 0 votes
AnswersFind all palindromes in a given string. Single letters are also considered as palindromes.
- xyz_coder February 06, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Coding - 1of 1 vote
AnswersGiven a number A, find the smallest number which has only 1s and 0s as its digits which divisible by the number A. For example: if the given number A is 4, the smallest number with 1s and 0s is which is divisible by 4 is 100.
- xyz_coder February 06, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Arrays Coding - 2of 2 votes
Answers{{
- skc25pma February 02, 2015 in India
There are 3 machines M1, M2 and M3. Each machine is 90% full of its capacity with integers. Now you have to sort all the integers combined and then store the first 1/3rd in M1, second 1/3rd in M2 and last 1/3rd in M3.
Your objective is to minimize the number of sort operations and number of data transfer operations.
Each sort operation/data transfer operation is counted as 1 irrespective of the count of values that are being sorted/transferred.
}}| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Coding Sorting - 0of 0 votes
AnswersEntry in the log file is like this:
- openhealth2014 February 01, 2015 in United States
User 1 visited Page 4
User 3 visited Page 2
User 7 visited Page 9
.
.
.
Design an efficient data structure which supports queries like the following:
Which page was visited by exactly 2 users in day?
Which page was visited by only one user exactly 2 times in a day?
Which page was visited by ‘User 3? more than 5 times in a day?| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswerDesign a system for finding the costliest element always whenever we pick up an element from a box.(concept of Max Heap)
- openhealth2014 February 01, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswersEntry in the log file is like this:
- openhealth2014 February 01, 2015 in United States
User 1 visited Page 4
User 3 visited Page 2
User 7 visited Page 9
.
.
.
Design an efficient data structure which supports queries like the following:
Which page was visited by exactly 2 users in day?
Which page was visited by only one user exactly 2 times in a day?
Which page was visited by ‘User 3? more than 5 times in a day?| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 2of 2 votes
AnswersGiven N scientists and K black holes, each scientist can query on radius, size and temperature of a black hole, what data structure would you use?
- openhealth2014 February 01, 2015 in United States
Following queries are important.
Which scientist had queried on which black hole.
What were the queries made by that scientist.| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswersIn a tennis tournament of N players every player plays with every other player.
- openhealth2014 February 01, 2015 in United States
The following condition always hold-
If player P1 has won the match with P2 and player P2 has won from P3, then Player P1 has also defeated P3.
Find winner of tournament in O(N) time and O(1) space. Find rank of players in O(NlogN) time.| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 1of 1 vote
AnswersWrite code for scheduling algorithms for such a cab services provided you have a list of future bookings, and list of cabs in your fleet.
- openhealth2014 February 01, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswersIn an auctioning system, the bidder with the highest bid wins but charged at kth highest price. Develop a system for it. Solved it using a hashmap. Was asked to write a code for the same.
- openhealth2014 February 01, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswersDesign a system which would make a schedule for a user to complete a book in given number of days. A pre condition is that the schedule for every day should end at the end of some chapter.
- openhealth2014 February 01, 2015 in United States
Ex – 3 chapter with 10 pages each and user has to complete this book in 2 days, then the schedule should be either be 2 chapters on first day and 1 chapter on second or 1 chapter on first day and 2 chapters on second. (code)| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 1of 1 vote
AnswersImplement DFS
- Mumbaiya_Chori January 19, 2015 in India for Machine learning
After I implemented this, I was told to implement it without recursion. He told me to write pseudo code. I wrote it using stacks.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersGiven a matrix (0,0 is to the botto9m left like co-ordinate system)of 0s and 1s and two co-ordinates find if there is a path between them, Also you can only travel via 1s and you can only go up or right.
- Mumbaiya_Chori January 19, 2015 in India for Machine learning
Answer: Backtracking algorithm| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answersgiven K sorted arrays merge them
- Mumbaiya_Chori January 19, 2015 in India for Machine learning
Answer: Told him how to do using merge of merge sort. He wanted me to do another approach I googled later you can use min heap for it.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
AnswersGiven an array of integers find the element for which the sum of left = sum of right. example -1 100 1 98 1 should return index of 1 i.e 2
Answer: First told him about Brute Force approach and then told him if we can iterate once and get the total sum
- Mumbaiya_Chori January 19, 2015 in India for Machine learningint findIndex(A){ int sum =0; for(int i =0;i<A.lenght;i++) { sum+= A[i]; } int lSum=0; for(int i=0;i<A.length;i++) { int rsum = sum - lsum-A[i]; if(lsum==rsum) return i; lsum += A[i]; } return -1; }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a string having a number:
- sprateek1990 January 19, 2015 in United States
"625626628"
Here the substrings are in consecutive order except for 1 substring which is missing. Find the missing substring.
Test cases:
"1235678" -> 4 is missing
"9979981000" -> 999 is missing
"624625627" -> 626 is missing| Report Duplicate | Flag | PURGE
Amazon SDE1 - 3of 3 votes
AnswersHow can you design a data structure that can do the following operations in O(1) time:
- Masumbuet December 29, 2014 in United States for International expansion
Insert, Delete, Search, Max which returns the maximum number
I know delete, search and insert can be done O(1) time in a hashmap with a proper hash function. But not sure Max is even possible in O(1) with the presence of delete operation?| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 2 votes
AnswersYou have given a mathematical expression in string format.
- dgchanchal December 24, 2014 in India for DSV QA team
Example: "3+12*3-4/7"
You need to write function which will return final result of the given expression. Don't use Expression Tree and start scanning from left to write.
It should be bug free.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersA 2D matrix is given to you. Now user will give 2 positions (x1,y1) and (x2,y2),
- Ankit Tripathi December 23, 2014 in India
which is basically the upper left and lower right coordinate of a rectangle formed within the matrix.
You have to print sum of all the elements within the area of rectangle in O(1) running time.
Now you can do any pre computation with the matrix.
But when it is done you should answer all your queries in constant time.
Example : consider this 2D matrix
1 3 5 1 8
8 3 5 3 7
6 3 9 6 0
Now consider 2 points given by user (0, 2) and (2, 4).
Your solution should print: 44.
i.e., the enclosed area is
5 1 8
5 3 7
9 6 0| Report Duplicate | Flag | PURGE
Snapdeal SDE1 Matrix - 1of 1 vote
AnswersYou have a chess board of size NxN. You have a horse at a given starting position. You also have a function that gives you all the positions that the horse can reach from it's current position.
- Ray December 12, 2014
Given an ending position, find the path to it that uses the minimum number of moves.| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 5of 5 votes
AnswersGiven an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.
- rjrush December 06, 2014 in United States
If the array before adjustment is A, the array after adjustment is B, you should minimize the sum of |A[i]-B[i]|
You can assume each number in the array is a positive integer and not greater than 100
Given [1,4,2,3] and target=1, one of the solutions is [2,3,2,3], the adjustment cost is 2 and it's minimal. Return 2.| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 0of 0 votes
AnswersArray of size (n-m) with numbers from 1..n with m of them missing. Find one all of the missing numbers in O(log). Array is sorted.
- suu December 05, 2014 in United States
Example:
n = 8
arr = [1,2,4,5,6,8]
m=2
Result has to be a set {3, 7}.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersGive you a list of Modules of Dependencies,
- wyu277 December 04, 2014 in United States
A --> B,C
B --> D,E,F
D --> F
And please return back a correct build order of Module (input)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - -4of 4 votes
AnswersShorten a List of Strings.
- wyu277 December 04, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 2 votes
AnswersDesign a Black-Jack poker game
- wyu277 December 04, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 4of 4 votes
AnswersGive an 2d-characters Grid, char[][] A, and a dictionary, List<String> dict. Search all possible words in the 2d-Grid.
- wyu277 December 04, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
Answersfinds a domino pattern for a "double-N" domino set that forms a loop / a ring using all available tiles.
- czuu December 02, 2014 in United States
for example,In a double-two domino set, with six tiles, (0 , 0) (0 , 1) (1 , 1) (1 , 2) (2 , 2) (2 , 0). So if parameter is 2, the function should return true. if no loop found, should return false.
Dominoes are small rectangular game tiles divided into two squares and embossed with dots on the top surface of the tile. You can think of dots as integers. A double-N domino set consists of (N+1)(N+2)/2 tiles, e.g. a standard double-six domino set has 28 tiles (T): one for each possible pair of values from (0.0) to (6.6) - no pair of numbers occurs more than once.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersWe have a class as follows:
public class People{ String name; String position; String sex; ... ... public String getAttribute(String attrName){ /** * This is a generic getter method that will give you * any attribute value based on the passed attribute * Name; * for eg: getAttribute("name") => will return the * attriute(Name) value of the current object. */ } }
I now give you two List:
- Arya December 01, 2014 in United States
list1<People> friends;
list2<String> attributes;
Using the generic getter method, we have to group "friends" on "attributes". Think of this as an implementation of GROUP BY function to be implemented on objects in list1 and to be grouped on entries in list2.
eg: list2 = {sex, occupation}
So objects in list1 will be grouped such that all Male-doctors together, Female-cops together, male-cops together, etc.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven a array of positive integers, find all possible triangle triplets that can be formed from this array.
- Aspire November 25, 2014 in United States
eg: 9 8 10 7
ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10
Note : array not sorted, there is no limit on the array length| Report Duplicate | Flag | PURGE
Linkedin SDE1 Algorithm - 2of 2 votes
AnswersGiven a large array of unsigned ints, quickly find two who's sum is 10
- JSDUDE November 22, 2014 in United States for Software Developer, Infrastructure Planning, Analysis and Optimization
Then the interviewer asked me to write test cases.
Followed by how to implement this on a distributed system, where multiple systems can read/write simultaneously on a shared cache (HINT: It is ok if you do not return the first instance)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Arrays