## Amazon Interview Questions

- 0of 0 votes
calculate the summary statistics for a fleet of hosts. Each host has a fixed number of slots in which virtual instances can run. Each host can only run instances of a particular type, e.g. M1, M2, or M3. You are provided with the file “FleetState.txt” that contains the state of the fleet. Each line in the file represents a single host in the following comma-separated format:

<HostID>,<InstanceType>,<N>,<Slot1State>,<Slot2State>,…,<SlotNState>

where

<HostID> is an integer

<InstanceType> can be M1, M2, or M3

<N> is the total number of slots on the machine

<SlotjState> is 0 if slot j is empty and 1 if it is occupied by an instance

Write a program that loads the state of the fleet from the input file “FleetState.txt” and then computes and writes out the following summary statistics to the output file “Statistics.txt”:

For each instance type, the count of empty hosts (all slots empty)

For each instance type, the count of full hosts (all slots filled)

For each instance type, the count of the most filled hosts (having the smallest number of empty slots > 0). Both the host count and number of empty slots must be written out in that order.

The output file must have the following format:

EMPTY: M1=<count>; M2=<count>; M3=<count>;

FULL: M1=<count>; M2=<count>; M3=<count>;

MOST FILLED: M1=<count>,<empty slots>; M2=<count>,<empty slots>; M3=<count>,<empty slots>;

What is the best way to solve this problem?

- 0of 0 votes
calculate the summary statistics for a fleet of hosts. Each host has a fixed number of slots in which virtual instances can run. Each host can only run instances of a particular type, e.g. M1, M2, or M3. You are provided with the file “FleetState.txt” that contains the state of the fleet. Each line in the file represents a single host in the following comma-separated format:

<HostID>,<InstanceType>,<N>,<Slot1State>,<Slot2State>,…,<SlotNState>

where

<HostID> is an integer

<InstanceType> can be M1, M2, or M3

<N> is the total number of slots on the machine

<SlotjState> is 0 if slot j is empty and 1 if it is occupied by an instance

Write a program that loads the state of the fleet from the input file “FleetState.txt” and then computes and writes out the following summary statistics to the output file “Statistics.txt”:

For each instance type, the count of empty hosts (all slots empty)

For each instance type, the count of full hosts (all slots filled)

For each instance type, the count of the most filled hosts (having the smallest number of empty slots > 0). Both the host count and number of empty slots must be written out in that order.

The output file must have the following format:

EMPTY: M1=<count>; M2=<count>; M3=<count>;

FULL: M1=<count>; M2=<count>; M3=<count>;

MOST FILLED: M1=<count>,<empty slots>; M2=<count>,<empty slots>; M3=<count>,<empty slots>;

what is the best way to solve it?

- 1of 3 votes
== Question ==

Given a list of TestResult, where each result contains a test score, a student ID and a date, figure out the students' final scores. A final score is the average of a student's top 5 scores.

Here is a sample of the list of TestResult:

50 JACK 5/14/2013

89 ALICE 3/25/2012

70 BOBBY 12/7/2010

60 JACK 8/9/2013

99 MIKE 9/11/2011

100 JOHN 7/4/2011

38 JACK 1/28/2014

46 JACK 11/15/2012

<... more ...>

struct TestResult {

score,

student_id,

date,

}

- 0of 0 votes
Given ~300k words with an average length of 7 in a file.

All words are dictionary correct words.

Print all the anagrams that are present in this list of words without repeating them.

E.g. if the list has:

ACT

BAT

CAT

TAB

TAC

print:

ACT, CAT, TAC

BAT, TAB

- 0of 0 votes
Design the algorithm and the system for a WebCrawler.

The webcralwler will be provided millions of URLs. The webpage will be downloaded and then parsed for more URLs. If more URLs are found then they should also be downloaded and parsed.

He was interested in:

1. Scale to handle millions of URLs

2. What are the bottle necks in the system? How will you resolve them

- 1of 1 vote
Design a vending machine

- 0of 0 votes
Given a sorted array with some sequenced numbers and some non-sequenced numbers. Write an algorithm that takes this array as an input and returns a list of {start, end} of all consecutive numbers. Consecutive numbers have difference of 1 only.

E.g. of array:

[4, 5, 6, 7, 8, 9, 12, 15, 16, 17, 18, 20, 22, 23, 24, 27]`public class Range { private int begin; private int end; public int begin { get; set; } public int end { get; set; } }`

- 4of 4 votes
You are given with an array of 1s and 0s. And you are given with an integer m, which signifies number of flips allowed.

find the position of zeros which when flipped will produce maximum continuous series of 1s.

e.g.

input:

arr={1 1 0 1 1 0 0 1 1 1 } m=1

output={1 1 1 1 1 0 0 1 1 1} position=2

arr={1 1 0 1 1 0 0 1 1 1 } m=2

output={1 1 0 1 1 1 1 1 1 1} position=5,6

- 0of 0 votes
This test was on https://www.hackerrank.com

Input is a string of Bytes E.g.341B

Convert it to human readable form: 3 characters long (excluding decimal)

No trailing or leading zeros

E.g:

Input 341B

Output 341B

Input 12345B

Output 12.3K

Input 1234567B

Output 1.23M

Input 1000000000B

Output 1G

Do not round off

Assume input will not be more than 1G

For this problem 1000B = 1K, so on and so forth

- 0of 0 votes
Write 4 testcases for the usecase "Customer buys a book with the credit card payment option."

- 0of 0 votes
Write 4 testcases for the usecase "Customer buys a book with the credit card payment option."

- 0of 0 votes
Write 4 testcases for the usecase "Customers buy a book with the credit card payment option."

- 0of 0 votes
Write a test plan for the first time launch of a website that will sell digital books.

- -2of 2 votes
Given an array of numbers print the values in diagonal format.

Example (1) for 8 dataset

Input Array : [1, 2, 3,4,5,6,7,8]

Output

01 02 04 07

03 05 08

06

Example (2) for 45 dataset

Input Array: [1, 2, 3,4,5,6,7,8,9,10……….44, 45]

Output

01 02 04 07 11 15 19 23 27 31 35 39

03 05 08 12 16 20 24 28 32 36 40 43

06 09 13 17 21 25 29 33 37 41 44

10 14 18 22 26 30 34 38 42 45

Code in Java.

- 0of 0 votes
Replace %20 with ' '.

E.g. input: www.space%20.com

output: www.space .com

- 0of 0 votes
Suppose I am given a set of input strings input[5](five of them) and their corresponding replacement strings replace[5]. Then I am given an input text, how can I replace the strings in the text matching any of the inputs with their corresponding replacements.

Also I have to make sure that if suppose, I find a match input[0] and I replace it by replace[0], then because of that it could be possible that I have a new match for input[2] lets say because of the new characters added by replace[0]. I don't want to make replacements with replace[2].

Also I cannot use regex of java.

- 0of 0 votes
design a algo so that it receive an input

`787668 787787 787948 787980 788094 788124`

and produce the output the difference of two consecutive numbers

`119,161,32,114,30`

the input can varry to any length

- 0of 0 votes
desing a algo so that it receive an input

`787668 787787 787948 787980 788094 788124`

and produce the output the difference of two consecutive numbers

`119,161,32,114,30`

the input can varry to any length

- 1of 1 vote
`Given a String s and a hashmap containing certain decodings for all the characters of alphabet. Find all possible passwords that can be generated by replacing decodings in the string s. Note that decodings of a charachter can only be single charachters Eg: String s="abcde" decodings given a-{1,2,p,o,q} b-{2,y} c-{p} d-{4,a,m,n} e-{9,z,x} h-{1} ' ' ' x-{0} y-{4,k,l} z-{r,5} So possible set passwords will be abcde,1bcde,2bcde,pbcde,obcde,qbcde, //replace a with all possible decodings a2cde,12cde,22cde,p2cde,o2cde,q2cde,aycde,1ycde,2ycde,pycde,oycde,qycde //replace b will all possible decodings a2pde,12pde,22pde,p2pde,o2pde,q2pde,aypde,1ypde,2ypde,pypde,oypde,qypde.....//replace c will all possible decodings`

- 0of 0 votes
Implement bool isPalindrome(SingleLinkList *node) in constant Space.

Sorry for incomplete post earlier..

- 0of 0 votes
Implement bool regex() Function.

- 0of 0 votes
Implement bool isBST(Tree * root)

- 0of 0 votes
Given a file which contains large number of strings.

e.g.:my name is XYZ. My emansi XYZ i.e. it has words and reverse of words. There can be the case where no reverse word is present.He told me to print all those pair whose reverse is also present in the file.

For above example output will be:

{name,eman}, {is, si}

Constraints were Minimum space should be used and time complexity should be minimum, further he added don’t compute reverse of string at all.

- 0of 0 votes
Hi,

Anyone here who has given the Amazon work style and personality test for the SDE/SDET position? If someone could shed some light on what exactly it is?

- 0of 0 votes
Hi,

Anyone here who has given the Amazon work style and personality test for the SDE/SDET position? If someone could shed some light on what it is exactly?

- 0of 0 votes
compare the time complexity of quick ,merge and bubble sort

- 0of 0 votes
Given a sorted array, construct Balanced BST

- 0of 0 votes
Find all the Leaders in an Array.

An Array element is Leader if all the elements following that array element is lesser than or equal to it.

Ex: Arr = {13, 17, 5, 4, 6, 2}

O/p: 17, 6, 2

- 1of 1 vote
Two dices are tossed. Once die is regular and the other is biased with probabilities P(1) = P(6) = 1/6, P(2) = P(4) = 0, P(3)= P(5) = 1/3.

Determine the probabilities of obtaining the sum 4.

- 1of 1 vote
Write a function to find the nth "ugly number". ugly numbers are numbers that can only be fully divided by 1, 2, 3, 5 and itself.