## Recent 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?

- 0of 0 votes
Got this sh***y problem.

A judge tells a person under trial that if your answer is true, you get 2 year sentence and if your answer is false you get 3 year sentence. The person under trial gives an answer which made the judge set him free. What did he say?

- 0of 0 votes
How to impliment a method to track devices using mac addresses in a wifi lan in java?

- 0of 2 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
The third question is a brain teaser: if 1000 couples are to give birth to male and female babies(50% change each), and they would keep giving birth until they have a girl, what's the boy to girl ratio in 20 years

- 0of 0 votes
A parent array P is given where P[i] denotes the parent of the ith node in the tree(the tree is generic). Parent of root is indicated with -1. I need to find the height/depth of tree. (Best sol in O(n))

- 0of 0 votes
Given an array of object A, and an array of object B. All A's have

different sizes, and all B's have different sizes. Any object A is of the

same size as exactly one object B. We have a function f(A, B) to compare the

size of one A and one B. But we cannot compare between two A's or two B's.

Give an algorithm to match each A with each B.

- 0of 0 votes
2.

String encode(List<String> input);

List<String> decode(String input);

- 0of 0 votes
This is two questions I got from a google interview. Not very sure how to solve it. Any comments would be appreciated.

1.

interface RateLimit {

/** Sets the rate, from 1 to 1000000 queries per second */

void setQPS(int qps);

/** accept or reject a request, called when request is received */

boolean allowThisRequest();

}

brief example:

server instantiates your object, calls setQPS(1)

at at time t, user1 makes a request, allowThisRequest() returns true

at time t+0.01 sec, user2 makes a request, allowThisRequest() returns false

at at time t+1, user4 makes a request, allowThisRequest() returns true

at time t+5 sec, user3 makes a request, allowThisRequest() returns true

- 0of 0 votes
We have two strings A and B with the same super set of characters. We need to change these strings to obtain two equal strings. In each move we can perform one of the following operations:

1. swap two consecutive characters of a string

2. swap the first and the last characters of a string

A move can be performed on either string.

What is the minimum number of moves that we need in order to obtain two equal strings?

- 1of 1 vote
given n > 0 fair dice with m > 0 "sides", write an function that returns a histogram of the frequency of the result of dice rolls. For example, for two dice, each with three sides, the results are:

(1, 1) -> 2

(1, 2) -> 3

(1, 3) -> 4

(2, 1) -> 3

(2, 2) -> 4

(2, 3) -> 5

(3, 1) -> 4

(3, 2) -> 5

(3, 3) -> 6

And the function should return:

2: 1

3: 2

4: 3

5: 2

6: 1

- 0of 0 votes
Given n rows of integers, such that the ith row (1 <= i <= n) contains i integers, find the path having the maximum weight.

Path traversal rules:

1. A valid path sequence would be top-down i.e. begins with the integer in the first row, and traverses all rows selecting only one integer in each row.

2. From any jth integer in the ith row i.e row[i][j], traversal can happen either downward (i.e to row[i+1][j]) or diagonally downward to the right (i.e to row[i+1][j+1])

The weight of a Path is the sum of values of integers in the Path sequence.

Sample Input:

No. of Rows: 5

4

2 9

15 1 3

16 92 41 44

8 142 6 4 8

Expected Output: 4, 2, 15, 92, 142 (Max weight is 255)

- 0of 0 votes
Given two integer arrays. Find the Largest Common sub array. For example,

arr1 = {1,2,3,2,3,2} arr2={2,2,3,3,4,5}, the largest common sub array is {2,2,3,3}

- 2of 2 votes
`int fun() { /*write code here.*/ } int main() { int i=10; fun(); printf("%d",i); }`

change the value of the i without changing code of the main function, assign 20 to i ?

- 1of 1 vote
Question: Two players A and B are playing a game. Pots of gold, each with

varying number of coins are placed in a single line. The rules of the game are:

1) Players play turn by turn.

2) On each turn a player can pick a pot of gold from either end of the line. He

gets all the gold in that pot. The next pot of gold on that end is now available

for picking.

What is the maximum number of gold can the first player get ?

- -1of 1 vote
a left grow binary tree. Describe as below. (Transform from A to B)

A: B:

1 1

/ \ /

2 3 2 - 3

/ \ /

4 5 4 - 5

/ \ /

6 7 6 - 7

a left grow binary tree. Describe as below. (Transform from A to B)

A: B:

1 1

/ \ /

2 3 2 - 3

/ \ /

4 5 4 - 5

/ \ /

6 7 6 - 7

- 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

- 0of 0 votes
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; } }`

- 0of 0 votes
1. Consider an ordinary binary min- heap data structure with n elements supporting the instructions INSERT and EXTRACT-MIN in O(lg n) worst case time. Give a potential function f such that the amortized cost of INSERT is O(lg n) and the amortized cost of EXTRACT-MIN is O(1) , and show that it works.

- 1of 1 vote
Implementing Deque using 3 Stacks (Amortized time O(1)) , I can't solve this problem ???

Amortized time O(1) what is Amortized time O(1)) ????

- 0of 0 votes
There are two coins that make 55 cents. If one of them is not nickle then what are the two coins?

- 0of 0 votes
A bear have to climb a 60.5 feet long hill. It climbs 3 feet in every minute before it fall down for 2 feet. How long it will take to climb the hill?

- 0of 0 votes
Create a random number generator within the given range? what if no range given? it should not repeat the sequence of random numbers generator before and after JVM is re-booted?

- 0of 0 votes
Create a random number generator within the given range or without range, it should repeat the sequence of random numbers generator before and after JVM is re-booted

- 0of 0 votes
Colorful Number:

A number can be broken into different sub-sequence parts. Suppose, a number 3245 can be broken into parts like 3 2 4 5 32 24 45 324 245. And this number is a colorful number, since product of every digit of a sub-sequence are different. That is, 3 2 4 5 (3*2)=6 (2*4)=8 (4*5)=20 (3*2*4)= 24 (2*4*5)= 40

But 326 is not a colorful number as it generates 3 2 6 (3*2)=6 (2*6)=12.

You have to write a function that tells if the given number is a colorful number or not.

- 0of 0 votes
A string "aBIY" is said to be a well-ordered word as each of the letters are in sequential manner regardless of case. So, "AbLe" is not a well-ordered word.

You are a anti-hacker. you have a number of character sequences. Your task is to generate all possible well-ordered word that can be generated by those numbers of given character sequences.

- 0of 0 votes
Edge Detection:

Two-dimensional array representation of an image can also be represented by a one-dimensional array of W*H size, where W represent row and H represent column size and each cell represent pixel value of that image. you are also given a threshold X. For edge detection, you have to compute difference of a pixel value with each of it's adjacent pixel and find maximum of all differences. And finally compare if that maximum difference is greater than threshold X. if so, then that pixel is a edge pixel and have to display it.