Amazon Interview Questions
0of 0 votesDesign a chess game. Write all classes and methods.
1of 1 voteGiven a large file of (x,y) coordinates. Find the k farthest points from origin.
1of 1 voteGiven a network of printers and systems. Allocate the nearest printer to each system. How will you handle dynamic addition of printers and systems.
3of 3 votesGiven a sorted array which is rotated n number of times. Find out how many times the array is rotated. Time complexity should be less than O(n).
0of 0 votesGiven a Binary Search tree along with the parent pointer, find the next largest node for the given node. Give the time and space complexity. The node Structure is
class Node {
Int data;
Node left;
Node right;
Node parent;
}
0of 0 votesGiven a string in the form of a Linked List, check whether the string is palindrome or not. Don’t use extra memory. Give the time complexity. The node structure is
Class Node {
Char data;
Node next;
}
0of 0 votesA log file is of below format
log.txt
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
SUCCESS:200:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:400:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:=500:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:400:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:401:________________________
I want the count of error between two given dates.grep '0[6789]:\| 1[01234567]' | ""grep -c "ERROR" log.txt timestamp = grep "TIMESTAMP" awk '$timestamawk>=from&&$timestamp<=to' from="2007/03/20 15:13" to="2007/08/19 14:31" log.txt | grep "ERROR" | wc -l timestamp = grep "TIMESTAMP" echo timestamp | awk -F'[- ]' '$2 >= 25 && $3 <= 04 { print }' | grep -c "ERROR"
0of 0 votesgiven an array of charactes have to replace space with %20. where %20 is considered as 3 characters.write complete code to implement this.
ps: assume that array has enough space at the end that can fit one space character to 3 chacters(%20).import java.io.* char fn(char [] word) { for(int i =1;i<=word.length();i++) { if(char[i]==" " && isArrayRightShiftable(word)){ shiftArrayToRight(word,i); char[i]='%'; char[i+1]='2'; char[i+2]='0'; } } return word; } private boolean isArrayRightShiftable(char[] word) { if(word.length()+2 < 50){ return true; } return false; } private void shiftArrayToRight(char[] word, int i) { for(int j = word.length();j>=i;j--) word[j+2]=word[j]; }
0of 0 votesFind the maxProduct of three numbers from a given integer array.
1. Handle all the cases
2. Interviewer was looking for a complete codepublic int maxPro() { // -5, -4, -3, -2 , 0 Int array[] = new Int[]{4,5,6,0,-5,-7,-2,-10}; Arrays.sort(array); // -10,-7,-5,-2,0,4,5,6 int count =0; for(int i =0; i<array.length();i++){ if(array[i]<0) count = count+1; } int maxProduct =1; if ( array.length()<3){ return -1; } else if( array.length()>=3 ){ int a=1; b=2; if(count>=2){ a = array[0]*array[1]*array[array.length-1]; b = array[array.length-1]*array[array.length-2]*array[array.length-3]; maxProduct = Math.max(a,b); } else if (count == 0 || count == 1 || count == array.length()){ maxProduct = array[array.length-1]*array[array.length-2]*array[array.length-3]; } } return maxProduct; }
-5of 7 votesFor 2 given array a[] and B[], find the highest index of A such that logical array A[0...i] and A[N-1...N-1-i] are same.
4of 4 votesGiven an array of integers such that each element is either +1 or -1 to its preceding element. Find 1st occurrence of a given number in that array without using linear search.
1of 1 voteFunction to reverse a c style sub-string
start - points to the first character to be reversed
end - points to character after the last character to be reversed
Note: STL not allowed
void reverse(char* start, char* end)
0of 0 votes1. N-Petrol bunk problem: There are n petrol bunks located in a circle. We have a truck which runs 1 km per 1 liter (mileage 1kmpl). Two arrays are given. The distances between petrol bunks are given in one array. Other array contains the no of liters available at each petrol bunk. We have to find the starting point such that if we start at that point , you we would able to visit entire circle without running out of fuel. Initially truck has no fuel
-1of 1 votewrite a code to print the second largest element in a list
Shortest possible complexity.
0of 0 votesThere is a HealthMonitor and two Servers (Primary and Secondary), all connected to one and another.
The HealthMonitor keeps pinging both the servers at specific time intervals and waits for their response for a time-out period after the request has been sent.
The server responds with a health status of itself and of its neighbor (meaning Primary responsds: OK; NEIGHBOR_OK)
Implement the server's code to send and receive responses and then take action based on response.
2of 2 votesWrite a class that will have following functions:
long CheckOut()
CheckIn(long)
Range of values is 1 to LONG_MAX
At any given point in time checkout should return the minimum available LONG number
Checkin can return the value back
No need to check for border conditions (e.g. check out when all values are exhausted)
Implement:
1. long checkout()
2. void checkIn(long input)
0of 0 votesWrite a class For Contacts on a device
Implementing Search a contact was the biggest problem I faced (because search should potentially search: FirstName, LastName, Address, PH#, Email etc)
0of 0 votesWrite a class for a parking garage:
One level
One entry point
No membership or payments required
Handles multiple types of cars
0of 0 votesImplement:
1. a search that will return all the strings that match a sub-string
2. an insert into this datastructureClass { Insert (string str){}; List<strings> Predictions(string subString){}; }
0of 0 votesImplement an iterator for a Binary tree. It should have the following things:
1. bool HasNext()
2. <T> Next()
It should be an in-order traversal.
0of 0 votesIf a function is der mostCommonChar(String str, int num) ,
1-.First input is Aabra Ka Daabra and second argument is 1 then the function should return first most repeated character in the string .Means in sorted descending .
2-> First input is Aabra Ka Daabra and second argument is 2
then the function should return second most repeated character in the string
like wise 3rd 4rth ....etc
1of 1 voteWrite a C program to find the number of shift required to convert one string to another. Check all the corner cases.
Eg: abc to acb o/p shd be 2 as 'b' shifted from 1st index to 2nd and 'c' shifted to 1st from second.
0of 0 votesAdding Very Large Numbers. Write clean code for it. please check all corner cases..
Number can be really really large
0of 0 votesDesign a singleton design pattern.
0of 0 votesDesign a class in C++ such that only one object of it can be created.
0of 0 votesFind the 3rd closest element in a bst.You will be given a pointer to root and a value within the tree against which the closest has to be figured out. (closeness is in terms of value, not by distance ) and then follow up qn: for finding the kth closest in a bst.
0of 0 votesA video streaming server is generating the following data. Find the potential customers facing buffering issues.
A person is said to face buffering issues when he hits the play button multiple times on the same video
You are given a huge file (say 1GB) that contains the following data:
CustomerId-TimeStamp-Event-VideoId-Videolength
0040 -01.00pm -Play -Video1 -02:30:00
Write code for this. What data structure will you use
He also said, lets say all the parsing is taken care of and you are given a collection of classes that contain the above data:Class { CustomerId TimeStamp Event VideoId }
0of 0 votesDesign an online hotel reservation system.
(I think this has been posted in Careercup earlier)
0of 0 votesDesign a furniture store with Tables and chairs. Write a constructor for chair and table
1of 1 voteYou are given a UNIX path with dot (current) and two dots (parent). Convert this to an absolute path
E.g. $/home/abc/.././def/./ghi/../.
becomes $/home/ghi/