Amazon Interview Questions
- 0of 0 votes
AnswersGiven an array of integers. Remove minimum number of elements from the array such that the largest and the smallest number does not differ by more than two times.In other words if x is the minimum of the remaining elements in the array and y is the maximum than y<=2x.
- sunny.010203045 January 27, 2014 in United States
Find the minimum number of numbers that has to be removed from the array so that the largest and the smallest number differed in no more than two times.
Input:
First line contains n(2<=n<=10^5), the size of the array
Second line contains n integers, the elements of the array.
Output:
Single integer - the minimum number of elements to be removed from the array.
Sample Test Case:
Input: {4,5,3,8,3,7}
Output: 2
Note: In the above sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
You do not need to write full code. Just fill out the given function.| Report Duplicate | Flag | PURGE
Amazon SDE1 - -1of 1 vote
Answersyou have a array which says the order of alphabets say [abcdef....z]. now use this array to sort, constraint is 'a' can be swapped one time 'b' two times, and for sorting you can use only swap.
- sameer.careercup January 26, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 - -1of 1 vote
Answeryou have n different array, all are sorted. form one array of size n whose range is min. meaning in resultant array diff of a[0] to a[n-1] is min.
- sameer.careercup January 26, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 2 votes
AnswersSuppose there is array contains 100 unsorted elements ...say a[1] to a[100].
- Ruhan January 25, 2014 in India
find out the minimum and maximum value in the range of a[25] to a[75].| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersThere is a large file( 1TB) containinig braces. Question is to check for their balance. I said will use a counter, will increment on an open brace and decrement on an close brace. If counter goes negative or counter is non zero at the end of the file, braces are not balanced. Otherwise balanced. Followup question was to make this process parallel ( meaning to see if this problem can be solved through parallelism, like dividing the the problem into sub problem....) Remember the file is very large.
- gns January 23, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Problem Solving - 0of 0 votes
AnswersGiven a tree, generate all paths. Note : all paths..not just the ones starting from root
- anon123 January 22, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersImplement a function which returns list of all nodes in a binary tree having a given number of leaves, say k . Also mention complexity.
- batradiva January 22, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersOnline assessment:
- 2013renting2013 January 12, 2014 in United States
There are N points on a 2D plane, find the k closest points.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersYou are given an array of integers, sorted, but rotated. Find an better than O(n) algorithm to find an element in an array. Write code for this.
- GSheld January 11, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYou are given a long list of integers, so long that you can not fit the entire list into memory, implement an algorithm to get the max 100 elements in the list.
- GSheld January 11, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersSecond question is Implement a boolean method for returning whether an appointment with a doctor is possible or not. Given that we have a set of start and end time frames already scheduled with the doctor.
- lks January 10, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersFind the longest common substring between 2 string in O(n) complexity
- lks January 10, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersPrint a 2D array in spiral order.
- GSheld January 10, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYou are standing at 0 0 and you have to get to i, j. Find the number of ways. Did that with recursion then with DP. Then he extended the question saying some edges are not traversible. Then edges have weights, find min weight path.
- anonymous January 09, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYou are standing at 0 0 and you have to get to i, j. Find the number of ways.. Then he extended the question saying some edges are not traversible. Then edges have weights, find min weight path.
- anonymous January 09, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersAn array is given representing the colors of n jars, colors have values 0-99. When two jars are mixed the resulting volume is same as volume of one jar. Smoke is color1*color2… and resulting color is (color1+color2)% 100. Keep on mixing colors such that you end up with just one jar with minimum smoke.
- anonymous January 09, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersSecond Question is to Encode a String
- lks January 09, 2014 in United States
aaaabbccdd -> a4b2c2d2
In minimun space and time complexity| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersFirst question is You have two numbers represented by a linked list, where each node contains a single digit. Write a function that adds the two numbers and returns the sum as a linked list
- lks January 09, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersImplement stack with findMiddle and deleteMiddle() in constant time.
- lks January 09, 2014 in United States
Can you please explain and write code for it| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a binary search tree whose nodes are integers, find the frequency of occurrence of each digit in the tree.tr
- lks January 07, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 0of 0 votes
AnswersYou have a single string which contains all the positive numbers upto N concatenated together. If you are given an input number then how would you find the index position of the number in the string.
Eg:String str = "12345678910111213141516171819202122232425......upto 10000"; input = 20 should return the index of 20 in the string which is 29
The example string is upto 10000. The actual string can be upto any number N.
- anonymous January 06, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 String Manipulation - 0of 0 votes
AnswersHow would you represent a graph with million nodes ?
- lks January 06, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersThere are two questions that I want to ask.
- lks January 06, 2014 in United States
Q1) divide two numbers without “/”
Q2) judge if there are two numbers in an array add to a given number
For both the questions please consider minimum space and time complexity| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a collection of 3-set sequences, where a 3-set sequence is defined as a list of 3 different pages (for example: mouse-keyboard-printer is a 3-set sequence, while printer-mouse-keyboard is another) accessed sequentially on amazon.com, find the most common 3-set sequence with minimum space and time complexity
- lks January 06, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersWrite a function to remove all redundant characters in a given string with minimum space and time complexity
- lks January 06, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 2of 2 votes
Answersint sum = 0;
- nirupam.astro January 04, 2014 in India
for (int i = 0; i < m; i++)
for (int j = i + 1; j < n; j++)
for (int k = j + 1; k < l; k++)
sum++;
what will be the value of sum?| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven a linked list of integers, write a function to determine whether the given list has a loop or cycle anywhere in the list. The integer values may not be relied upon to be distinct.
- outside09 December 30, 2013 in United States
You may use the JDK or the standard template library. The solution will be evaluated on correctness, runtime complexity (big-O), and adherence to coding best practices. A complete answer will include the following:
Document your assumptions
Explain your approach and how you intend to solve the problem
Provide code comments where applicable
Explain the big-O run time complexity of your solution. Justify your answer.
Identify any additional data structures you used and justify why you used them.
Only provide your best answer to each part of the question.
Use one of the following skeletons for your solutions.
Java:
public class ListLoopQuestion {
public static class ListNode {
public int value;
public ListNode next;
}
public static boolean hasLoops( ListNode myList ) {
}
}
C++:
struct ListNode {
int value;
ListNode * next;
}
bool hasLoops( ListNode * myList ) {
}| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 2 votes
AnswersGiven a list of test results (each with a test date, Student ID, and the student’s Score), return the Final Score for each student. A student’s Final Score is calculated as the average of his/her 5 highest test scores. You can assume each student has at least 5 test scores.
- outside09 December 30, 2013 in United States
You may use the JDK or the standard template library. The solution will be evaluated on correctness, runtime complexity (big-O), and adherence to coding best practices. A complete answer will include the following:
Document your assumptions
Explain your approach and how you intend to solve the problem
Provide code comments where applicable
Explain the big-O run time complexity of your solution. Justify your answer.
Identify any additional data structures you used and justify why you used them.
class TestResult{
int studentId;
Date testDate;
int testScore;
}
public Map<Integer, Double> getFinalScores(List<TestResult> resultList){
return null;
}| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 0of 0 votes
AnswersGiven two sorted singly linked lists, implement a function to merge the two lists into a single sorted list and return its head. You may destroy the original lists if you want.
- outside09 December 30, 2013 in United States
You may use the JDK or the standard template library. The solution will be evaluated on correctness, runtime complexity (big-O), and adherence to coding best practices. A complete answer will include the following:
Document your assumptions
Explain your approach and how you intend to solve the problem
Provide code comments where applicable
Explain the big-O run time complexity of your solution. Justify your answer.
Identify any additional data structures you used and justify why you used them.
Only provide your best answer to each part of the question.
Example:
Input:
List 1: 1->2->3->4
List 2: 1->3->5->7
Output:
1->1->2->3->3->4->5->7
Use one of the following skeletons for your solutions.
Java:
public class Node {
public int value;
public Node next;
public Node() {
value = 0;
next = null;
}
public Node(int value, Node next) {
this.value = value;
this.next = next;
}
}
public class MergeListProblem {
public static Node mergeLists(Node head1, Node head2) {
// your code goes here
}
}
C++:
class Node {
public:
int value;
Node* next;
Node() {
value = 0;
next = NULL;
}
Node(int v, Node* n) {
value = v;
next = n;
}
};
Node* mergeLists(Node* head1, Node* head2) {
// your code goes here
}| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersAmazon has many visitors to its site. And it tracks what pages the customers visited, etc and other stuff.
- pulkit.mehra.001 December 26, 2013 in India
Make an efficient data structure for storing 3 days of information of all those customers who have visited site exactly two different days and searched more than 3 unique pages of the site in those 2 days.
So whoever visited site exactly two days out of these three days and visited more then 3 unique pages should be in the contact list.
What's the efficient approach to solve these kinds of problems??| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures