## Recent Interview Questions

- 0of 0 votes
How would you implement an LRU cache using just a *single* container ? i.e., map or unordered_map ?

The cache must support operations:

1. value_t find(key_t) - find a certain value in cache

2. insert(key_t, value_t) - insert a new value to the cache (with optionally deleting an LRU entry)

- 2of 2 votes
There are several people sitting in the cinema, some of them are couples, some are not, they decide to swap their seats so that the couples can seat together, please calculate the minimal swap numbers.

1. the swap can happen between any two position.

2. E.g. AABCCDB -> AADCCBB, ans is 1

- 0of 0 votes
Given n, return 1 ^ 2 ^ 3 ^ ... ^ n

Where ^ is binary xor.

Note: n is a 64-bit number, and 1<<63 is a valid n for this problem.

Examples:`>>> reduce(lambda a,b:a^b, [1,2,3]) 0 >>> reduce(lambda a,b:a^b, [1,2,3,4]) 4 >>> reduce(lambda a,b:a^b, [1,2,3,4,5,6,7]) 0 >>> reduce(lambda a,b:a^b, [1,2,3,4,5,6,7,8,9]) 1`

- 0of 0 votes
consider an array1={1,1,1,1,1,1,1,1,1,1}

if n=4 add first four elements and next four elements

result : array1={4,4,2}

if n=3 add first three elements and next three elements repeat process untill size of array <=n

result1:

array1={3,3,3,1}

result2 : array1={6,4}

- 0of 0 votes
You are building a small command-line application to calculate hotel availability for a city. Your application reads in two (2) data files, and outputs its answer to STDOUT.

Your application will read in:

· a list of hotels along with how many rooms each contains (in no particular order)

· a list of bookings that have been made (in no particular order)

Your application will then print the list of all hotels which have availability for check-in and check- out date range, if any.

Do not worry about whether a specific room is available in a hotel for the entire booking period without switching rooms: availability is defined as the hotel having at least one (1) available room for each night of the target stay, regardless of whether it's the same room from day to day.

Data Files

hotels.csv

# Name, Rooms

Westin, 10

Best Western, 20

Hilton, 10

...

bookings.csv

# Name, Checkin, Checkout

Hilton, 2015-04-02, 2015-04-03

Hilton, 2015-04-02, 2015-04-04

Westin, 2015-05-01, 2015-05-20

- 0of 0 votes
Given an array of positive, unique, increasingly sorted numbers A, e.g. A = [1, 2, 3, 5, 6, 8, 9, 11, 12, 13]. Given a positive value K, e.g. K = 3. Output all pairs in A that differ exactly by K.

e.g. 2, 5

3, 6

5, 8

6, 9

8, 11

9, 12

what is the runtime for your code?

- 0of 0 votes
Yahoo mail customer support is the convenient way to connect and resolve Yahoo mail problem coming up with various operating system and smart gadgets including iPhone, iPad and other handheld computer. Online or Remote support services save the time and hassle of user. Yahoo mail customer support is provided by highly trained support engineers connect the user whenever users needs. Users can talk to live chat router to setup your call with appropriate engineers who’re able to resolve your particular Yahoo mail glitch. Remote support service allows the representative provide fast and accurate assistance to customers by seeing their screen.

Facebook: https://www.facebook.com/YahooEmailContactNumber

Youtube: https://www.youtube.com/watch?v=vXVZMsQtU0M

- 0of 0 votes
there are N cities (numbered from 1 to N) in the game and connect them by N-1 highways. It is guaranteed that each pair of cities are connected by the highways directly or indirectly.The game has a very important value called Total Highway Distance (THD) which is the total distances of all pairs of cities. Suppose there are 3 cities and 2 highways. The highway between City 1 and City 2 is 200 miles and the highway between City 2 and City 3 is 300 miles. So the THD is 1000(200 + 500 + 300) miles because the distances between City 1 and City 2, City 1 and City 3, City 2 and City 3 are 200 miles, 500 miles and 300 miles respectively.

During the game the length of some highways may change. you want to know the latest THD.

sample input

3 5

1 2 2

2 3 3

QUERY

EDIT 1 2 4

QUERY

EDIT 2 3 2

QUERY

sample output

10

14

12

- 0of 0 votes
You are given a permutation arr[N]. E.g. arr[3] = {2, 1, 0} or arr[5] = {0,1,2,4,3};

Then you can prepare somehow and then start serving requests: request(a, b, k) = sorted(arr[a:b])[k], that is, k-th order statistic on slice [a:b] of arr.

E.g. if arr is [3,4,5,0,1,2] and a = 2 and b = 5, then arr[a:b] = [5,0,1] and let k = 2, so we sort it - get [0,1,5] and take k-th element, that is - 5.

Implement request(a, b, k) function. You can preprocess input data, that is, assume there will be only one array and many request() calls.

- 0of 0 votes
A nXn matrix consisting of 0 and 1 only is given. n is always odd. A variable k is also given as input. You have to find the minimum vaue of a function F(x,y) over k contiguous row wise elements such that arr[x][y] is 1 for all k contiguous elements.

F(i,j) for any index (i,j) is (n/2-i)^2 + (n/2-j)^2.

- 0of 0 votes
Design a unique hash function for every tweet in Twitter which will be used as part of a service.

- 0of 0 votes
Wedding Planner

Julia is a wedding planner who puts together phantasmagorical

extravaganza packages for new couples and their guests from 2 to

2,000. Hundreds of items are needed for each event, and Julia has a list

of supplier offers for all these items in various quantities. The price per

unit of every item is highly variable, depending on the supplier, the

number ordered, and the client/buyer who places the order. With her

years of record-keeping, Julia knows the best unit price she can get for

any item in any of a limited number of order sizes. Some items cost less

per unit when the number ordered goes up, some cost less per unit

when the number ordered goes down, and others have no rhyme or

reason for the unit prices available.

To price a new event, Julia consults her database of past offers.

If the amount needed for the new event is exactly the same as the

amount in a past offer, the unit price is also the same.

If she has a price for a higher amount and a price for a smaller

amount, her best guess will be that the unit cost will be linearly

interpolated from the unit costs for the closest lower amount and

the closest higher amount.

If the database only has one amount, then her best guess is that this

will be her unit cost.

And, if the amounts for which she has offers are all smaller or all

larger than the amount she needs, then she finds it most accurate to

linearly extrapolate from the closest two points to the amount

needed.

Finally, sometimes price offers lapse. When this happens, Julia, who

is not very database savvy, just overwrites the old unit price with a

zero or negative number. The amounts associated with zero or

negative unit price need to be disregarded.

automated so she can do it for hundreds of items with thousands of

individual prices.

Complete the function extrapolate , which takes a new amount n, an

array amount of old offer amounts in increasing order, and an array

ucost of corresponding unit prices. Your completed function should give

the expected unit price p for the new amount. The unit prices may

increase, decrease or oscillate, and may also contain invalid values like

0 or negative numbers. Your answer, as well as the unit prices in the

second array, should all be real numbers with exactly two decimal

places, representing dollars and cents. Use standard rounding to arrive

at two decimal places.

Input

A positive integer n, denoting the number if items for which a unit

price is needed.

1.

An array amount of l positive integers denoting the different order

amounts for which historical unit costs exist.

2.

An array ucost of l strings of real numbers denoting the different

unit costs for the corresponding amounts in array a.

3.

Output

A single positive number p with exactly two decimal places.

Note that the code for processing input and output is already present in

the system and designed to be compatible with the test case files used

to score your solution. There is no need to change only of the code other

than the body of the function extrapolate.

Constraints

1 ≤ l ≤ 100

2 ≤ n <= 2000

size(a) = l = size(u)

a(i) < a(j) ⇔ i < j

1

2

3

4

5

n = 25

a = {10, 25, 50, 100, 500 }

u = {"2.46","2.58", "2", "2.25", "3" }

Sample Output #1:

p = 2.58

Explanation #1:

The amount 25 is one of the values in the database. Its corresponding

unit price is 2.58.

Sample Input #2:

n = 2000

a = {10, 25, 50, 100, 500 }

u = {"27.32", "23.13", "21.25", "18.00", "15.50"}

Sample Output #2:

6.13

Explanation #2:

The item count 2,000 is not in the database. It is larger than any amount

in the database. The closest two price points to it are 15.5 for 500 and

18.00 for 100. Linear extrapolation from these two points means

reducing the price by 2.5 for every increase in amount of 400. There 3.75

jumps of 400 from 500 to 2,000, or 4.75 jumps of 400 from 100 to

2,000. The unit price for 2,000 is therefore 15.5 - 2.5 × 3.75 or 18 - 2.5 ×

4.75. Both expressions evaluate to 6.125. This rounds up to 6.13.

- 0of 0 votes
Strong relation group

A group of social network experts are searching for an algorithm to find

"Strong relation groups" among people. A group of people form a strong

relation group if each of them know everyone else in the group. The

problem seemed very tough to them, so they want to attack a smaller

problem. If there are n people in a network and there are m pairs of

relationship among them, what will be the minimum size of the largest

"Strong relation group" in the network? If you know about graphs, you

can think of people as nodes and their relationship as edges.

Parameters:

Complete a function strongRelation which takes two integers n and m

as parameters.

Input Format:

First line contains a single integer denoting N.

Second line contains a single integer denoting M.

Return value:

Return the answer to the problem.

Constraints

1 <= T <= 100000

2 <= N <= 10000

1 <= M <= N*(N-1)/2

Sample Input:

3

2

Sample Output 1:

2

Sample input 2:

4

6

Sample Output 2:

4

Sample input 3:

5

7

Sample Output 3:

3

Explanation

1

2

3

4

5

"Strong relation group" cannot be smaller than 4.

For the third sample, it is easy to verify that any graph with 5 nodes and

7 edges will surely have a "Strong relation groups" of size 3 or more

- 0of 0 votes
Can you predict the missing

grade?

Problem Statement

Introduction

The CBSE Class 12 examination, is taken by Indian high school students

at the end of K-12 school education. The scores or grades in this

examination form the basis of their entry to the College or University

system, for an undergraduate program. At the K-12 level, students

appear for examination in five subjects. These five subjects generally

include one language; three elective subjects oriented towards Science,

Commerce or Humanities; and any elective of their choice as a fifth

subject.

The Challenge

This challenge is based on real school data of the CBSE Class 12

examination conducted in the year 2013. You are given the grades

obtained by students with specific but popular combinations of subjects

(and all these students had opted for Mathematics). Their grades in four

subjects are known to you. However their grade in Mathematics (i.e, the

fifth subject) is hidden.

The records provided to you are the grades obtained by students who

had opted for the following combinations of subjects or courses and

obtained a passing grade in each subject. The individual subjects in the

data are:

English, Physics, Chemistry, Mathematics, Computer Science, Biology,

Physical Education, Economics, Accountancy and Business Studies.

The most dominant subject combinations, account for approximately

99% of the data are:

English, Physics, Chemistry, Mathematics, Physical Education

English, Physics, Chemistry, Mathematics, Economics

English, Physics, Chemistry, Mathematics, Biology

English, Economics, Accountancy, Mathematics, Business Studie

s

The grades of students in four subjects (other than Mathematics) are

provided to you. Can you predict what grade they had obtained in

Mathematics?

To help you build a prediction engine, we will provide you with a training

file, containing the grade points obtained by students with the above

subject combinations, in all five subjects.

Notes about the Grading System

The student is first assessed on a scale of 100. (S)He needs a score of at

least 33% to pass in the subject. Among those who pass:

Grade 1 is assigned to the top one-eighth of students who pas

s the course.

Grade 2 is assigned to the next one-eighth of students who pa

ss the course.

.....

Grade 8 is assigned to the last one-eighth of students who pa

ss the course.

If more than 1 student share the same score and lie in the margin, they

share the higher grade.

Input Format

The first line will be an integer N. N lines follow each line being a valid

JSON object. The following fields of raw data are given in json.

SerialNumber (Numeric): The identifier of the student record.

This is provided just for identification purposes and does n

ot have any direct use.

English (numeric) : The grade (between 1 and 8) obtained in E

nglish. This will always be present.

Three more numeric fields from among: Physics, Chemistry, Com

puterScience, Hindi, Biology, PhysicalEducation, Economics, A

1

2

3

4

5

The input for each record has the grade for all subjects opted by a

student, other than Mathematics which you have to predict as the

answer.

Constraints

1 <= N <= 10

The SerialNumber field will contain a unique numeric identifier such

that 1 <= SerialNumber <= 5 * 10 .

All other fields in the JSON fragment will represent the grades obtained

in four subjects and will be populated by numeric values between 1 and

8, both inclusive.

Output Format

For each student record that is given as a JSON object, containing the

grade obtained in four subjects, output the predicted grade in

Mathematics (this will be a numeral between 1 and 8, both inclusive) in

a newline.

Training File and Sample Tests

The training file with sample test data is available here.

The three files in this package are:

training.json

sample-test.in.json

sample-test.out.json

Training data as well as sample testcases have been provided in the

above file for offline training and to help you build your prediction

model. Feel free to include file data inside your code.

Sample Input

12345

{"SerialNumber":1,"English":1,"Physics":2,"Chemistry":3,"Comp

uterScience":2}

json_object

json_object

json_object

.

.

.

5

5

1

2

3

4

5

Sample Output

1

3

4

7

8

....

....

....

Explanation

It is predicted that first candidate obtained grade 1 in Mathematics, the

second candidate achieved grade 3 in Mathematics, the third candidate

achieved grade 4 in Mathematics and so on.

Scoring

For each of the N records in the input file, we will compute:

p = abs(Predicted Grade Point in Mathematics - Actual Grade Point in

Mathematics)

Where 'abs' indicates the Absolute Value or Magnitude. If p = 0 or 1 your

answer for that particular student record will be considered correct. i.e,

we allow a tolerance of one grade point away from the correct answer,

to take into consideration the marginal errors which might occur during

the testing or grading process.

Score = 100 * ((C-W)/N)

Where C = Number of Correct predictions, not more than one grade

point away from the actual grade point assigned.

W = Number of wrong (incorrect) predictions and

N = Total number of records in the input.

While the contest is in progress, only the score based on the sample

test case will be displayed to you. After the contest is completed, we

will revise the scores based on performance on a hidden test set only.

However, when you make submissions, you will be able to see whether

your program attains a positive score on both the sample and the

hidden test cases (to avoid a situation where unexpected errors occur

on the hidden test set at the end).

- 0of 0 votes
Nuclear Rods

A core meltdown has occurred at the Fubaru nuclear plant. There are

n nuclear fuel rods that are damaged and need to be removed using

specialized radiation-hardened robotic equipment

with solid-lead isolation chambers. Remote imaging has already

uniquely identified every damaged fuel rod and assigned it a number

between 1 and n. The imaging data also records which fuel rods were

fused to each other during the meltdown. Every recovery sortie by the

robot can pick up one set of nuclear fuel rods that are directly or

indirectly fused to each other.

The recovery costs per sortie are proportional to the square root of the

number of fused rods recovered. So the cost is K to recover K rods.

Isolation chambers are available for all positive integer costs (1, 2, 3, …).

An isolation chamber can be used multiple times, and each use will

incur the same cost. The robot can also recover a lower number of rods

than a chamber's capacity on a sortie.

Find the minimal cost to recover all the radioactive rods by completing

the given function.

Input

The first parameter integer n specifies the number of rods. The second

parameter pairs is an array of pairs of rods that are fused together. Each

item in the array contains exactly two integers, P and Q separated by a

space (" "), which means that the rod numbered P is fused to the rod

numbered Q. *Note - Each item in the array is a string which needs to be

parsed to P and Q

Output

2

Constraints

2 ≤ N ≤ 100,000

1 ≤ P, Q ≤ N

P ≠ Q

Sample Input

4

2

1 2

1 4

Sample Output

3

Explanation

Rods #1, #2, #4 are connected to each other (2-1-4) so they are in a

single group of 3. The sortie to recover them will cost 2 (with isolation

chamber capacity 2 = 4). Rod #3 is not fused to any other, so it can be

recovered at a cost of 1 (with isolation chamber capacity 1 = 1).

- 0of 0 votes
StringChain

You are given a library with n words (w[0], w[1], ..., w[n - 1]). You

choose a word from it, and in each step, remove one letter from this

word only if doing so yields a another word in the library. What is the

longest possible chain of these removal steps?

Constraints:

1 ≤ n ≤ 50000

1 ≤ the length of each string in w ≤ 50

Each string composed of lowercase ascii letters only.

Input Format:

Complete the function "longest_chain" which contains an array of

strings "w" as its argument.

Output Format:

Return a single integer that represents the length of the longest chain of

character removals possible.

Sample Input #00:

6

a

b

ba

bca

bda

bdca

Sample Output #00:

4

- 0of 0 votes
Given a string and array of strings, find whether the array contains a string with one character difference from the given string. Array may contain string of different lengths.

Ex: Given string`banana`

and array is

`[bana, apple, banaba, bonanza, banamf]`

and the outpost should be true as banana and banaba are one character difference.

- 0of 0 votes
Test Question

- 0of 0 votes
Problem Two: Conference Track Management

You are planning a big programming conference and have received many proposals which have passed the initial screen process but you're having trouble fitting them into the time constraints of the day -- there are so many possibilities! So you write a program to do it for you.

• The conference has multiple tracks each of which has a morning and afternoon session.

• Each session contains multiple talks.

• Morning sessions begin at 9am and must finish by 12 noon, for lunch.

• Afternoon sessions begin at 1pm and must finish in time for the networking event.

• The networking event can start no earlier than 4:00 and no later than 5:00.

• No talk title has numbers in it.

• All talk lengths are either in minutes (not hours) or lightning (5 minutes).

• Presenters will be very punctual; there needs to be no gap between sessions.

Note that depending on how you choose to complete this problem, your solution may give a different ordering or combination of talks into tracks. This is acceptable; you don’t need to exactly duplicate the sample output given here.

Test input:

Writing Fast Tests Against Enterprise Rails 60min

Overdoing it in Python 45min

Lua for the Masses 30min

Ruby Errors from Mismatched Gem Versions 45min

Common Ruby Errors 45min

Rails for Python Developers lightning

Communicating Over Distance 60min

Accounting-Driven Development 45min

Woah 30min

Sit Down and Write 30min

Pair Programming vs Noise 45min

Rails Magic 60min

Ruby on Rails: Why We Should Move On 60min

Clojure Ate Scala (on my project) 45min

Programming in the Boondocks of Seattle 30min

Ruby vs. Clojure for Back-End Development 30min

Ruby on Rails Legacy App Maintenance 60min

A World Without HackerNews 30min

User Interface CSS in Rails Apps 30min

Test output:

Track 1:

09:00AM Writing Fast Tests Against Enterprise Rails 60min

10:00AM Overdoing it in Python 45min

10:45AM Lua for the Masses 30min

11:15AM Ruby Errors from Mismatched Gem Versions 45min

12:00PM Lunch

01:00PM Ruby on Rails: Why We Should Move On 60min

02:00PM Common Ruby Errors 45min

02:45PM Pair Programming vs Noise 45min

03:30PM Programming in the Boondocks of Seattle 30min

04:00PM Ruby vs. Clojure for Back-End Development 30min

04:30PM User Interface CSS in Rails Apps 30min

05:00PM Networking Event

Track 2:

09:00AM Communicating Over Distance 60min

10:00AM Rails Magic 60min

11:00AM Woah 30min

11:30AM Sit Down and Write 30min

12:00PM Lunch

01:00PM Accounting-Driven Development 45min

01:45PM Clojure Ate Scala (on my project) 45min

02:30PM A World Without HackerNews 30min

03:00PM Ruby on Rails Legacy App Maintenance 60min

04:00PM Rails for Python Developers lightning

05:00PM Networking Event

- 0of 0 votes
Test Question, this is a test question

- 0of 0 votes
Given two Binary Trees (not BST). Each node of both trees has an integer value. Validate whether both trees have the same integers, there could be repetitive integers.

ex-

Tree1:

5

1 6

5 4 3 6

Tree2:

1

3 4

6 5

have identical integers.

- 1of 1 vote
Given a string which may contain parenthesis. We must verify the validity of the string.

ex-

1) "<ad675+-fkmfd>" is a valid string

2) "<[((kskfhdbh7)" is invalid

3) "[<<((shfs8))>>]" is valid

Extension to the question -

Suppose you had a hash table that told you how a parenthesis starts and how it ends as a key value pair, how would you then validate the string.

ex - <key,value> = < '(' , ')' > indicates '(' is a start parenthesis and ')' should be the end of that paranthesis.

<'A','&'> indicates that 'A' is a start parenthesis and '&' is the end parenthesis.

Note: Validity means a parenthesis that starts, must end.

- 0of 0 votes
Given a linked list which in addition to the 'next' pointer has another valid pointer to a random node in the string, write a function to copy the linked list.

- 1of 1 vote
Find the largest substring palindrome in a given string.

ex: input: abbac output: abba

Solution: Use Hashmap

- 0of 0 votes
You are tasked with defining and implementing a function. as input, you are given an n x m matrix. x may appear any number of times in a matrix. your function should modify thebmatrix such that any row and column where x originally appears are completely over written with x

For example:

- - - - -

- - - - -

- - - x -

x - - - -

- - - - -

Expected output:

x - - x -

x - - x -

x x x x x

x x x x x

x - - x -

- 0of 0 votes
Design a train system which suggests shortest path and transfer needed to reach from source to destination. What can be the optimization.

For example:

A system may have 10 trains from t1 to t10.

There are total 100 stops in the system s1 to s100.

Each train has fixed set of stops. You could allow to change and transfer train of source and destination does not cover using just 1 train.

What all can be APIs, data structure, optimizations scalable option.

- 0of 0 votes
Design Live comments. If your facebook.com homepage is open with bunch of feeds and if someone comments on those feeds, the comments should automatically show up in facebook.com home page without refreshing the page. Feeds could be a simple status update by a friend, post in a group, post by a person you're following, post in a page you've liked etc.

Few things what they are looking for -

1. How do you solve it initially and how do you scale it?

2. How do you scale push model in-case if you choose PUSH model to solve it?

3. If push cannot scale how do you solve it?

4. How pull model solves it?

5. When will you use push vs pull?

- 0of 0 votes
Gmail Password Recovery Phone Number Helpline Support.?

- 0of 0 votes
Given a cube made of N x N x N sub-cubes, how many sub-cubes are on the outside of the cube?

- -2of 2 votes
Did anyone given JPMC java coding test in Jersey city or new York?