X
Submit Question

Algorithm  Questions

View By:

Q1 PONY

Discord is in trouble for causing discord, so he is trying to escape from Equestria. He's arrived at the port, and he doesn't care what boat he gets on, he just wants to get out. He can see the boat schedule, where he sees that N boats are arriving today,

boat 1 arrives any time within a_1 minutes

boat 2 arrives any time within a_2 minutes

...

boat N arrives any time within a_N minutes (uniform distribution)

Tell discord the expected number of minutes he needs to wait for a boat to arrive.

For example If n=3 , and there arriving times are 49,50,51 respectively then expected number of minutes would be 12.495000 . Thats all I know .

Google  |  Level - 3

Answer Write Code Visit Question Page

Q2 Log parser

Each time a visitor requests a page from our website, our webserver writes a log entry recoding the visitor's identity and the kind of page requested. Entries are written in chronological order to a plain-text file, with one entry per line. The format of each entry is:

user-id page-type-id

User IDs are arbitrary strings that uniquely represent a given user; if a user visits multiple pages, each log entry will have the same user ID. Page type IDs are arbitrary strings that uniquely represent a given kind of page on our site, such as the homepage, a product detail pages, or the shopping cart. Tons of users visit our website, but there are only a few dozen types of pages.

We can use our weblogs to answer questions about user b...
show more

Amazon  |  Level - 3

Answer Write Code Visit Question Page

Q3 Balanced BST

Find two elements in balanced BST which sums to a given a value. Constraints Time O(n) and space O(logn).
      6
 3         8

1 4 7 12

sum = 16 o/p should be 4 and 12

Google  |  Level - 2

Answer Write Code Visit Question Page

Q4 Staves

You want to create a staff to use in your martial arts training, and it has to meet some specific requirements.
  1. You want it to be composed of two smaller staves of equal length so that you can either use it as a single staff or as two smaller ones.

  2. You want the full sized staff's center of gravity to be exactly in the middle of the staff.

You have a very, very long branch from which you can cut the pieces for your staff. The mass of the branch varies significantly throughout it, so you use just any two pieces of the same length. Given a description of the mass throughout the branch, determine the longest staff you can make, then return three integers on a single line, the first two indicatin...
show more

Facebook  |  Level - 3

Answer Write Code Visit Question Page

Q5 URL Detection

MS Word has the inbuilt logic to detect the url when user writes to any document. MS Word application detects the url typed by user and hyperlinks it. Write a code to:

1) Detect url assuming that MS Word engine streams the characters to your function BOOL DetectURL(UCHAR chUserCharEntry) 2) Once #1 is completed then execute the url from IE

Google  |  Level - 2

Answer Write Code Visit Question Page

Q6 Given a 2-D MxN matrix having each value as difficulty for the block

Given a 2-D MxN matrix having each value as difficulty for the block. A frog is starting from a point Matrix[0][0] and will have to reach Matrix[M-1][N-1]. It can jump any step in one go [ 1, 2, ..... M-1] horizontally OR [ 1,2,3,.... N-1] vertically Each difficulty value is positive. Write code to give path trace for frog. Two structure to use -

struct node { int x; int y; struct node *next; };

struct path { int difficulty; struct node *pathlink; }

Ex matrix - 4X4 matrix

7 9 2 11 13 23 1 3 14 11 20 6 22 44 3 15

Minimum difficulty = 7 (a[0][0])+ 2(a[0][2]) +3(a[3][2])+15(a[3][3]) = 27 Path trace will have = 7->2->3->15

Amazon  |  Level - 3

Answer Write Code Visit Question Page

Q7 N-2 Problem

You are given 2 machines. There are N jobs you have to perform. Job i takes Ai time to perform on machine A and Bi time to perform on machine B. Each job should be done either on machine A or B. The jobs should be performed in order. Given the arrays A and B and an integer K, find the minimum time required to complete the jobs, given that you cannot do more than K jobs on the same machine continuously. This can be done in O(N K)space and time. This can be improved to O(N K) time and O(N ) space and further to O(N logN ) time.

Microsoft  |  Level - 3

Answer Write Code Visit Question Page

Q8 Octa to Decimal Conversion

eg 12 in octa is 10 in deci

Libsys  |  Level - 1

Answer Write Code Visit Question Page

Q9 Print the Pascal triangle.

If you choose the number of rows as 3, the output will be

1 121 1331

Vinsol  |  Level - 1

Answer Write Code Visit Question Page

Q10 Facebook interview question

The beauty of a number X is the number of 1s in the binary representation of X.

Two players are plaing a game. There is number n written on a black board. The game is played as following:

Each time a player chooses an integer number (0 <= k) so that 2^k is less than n and (n-2^k) has as beautiful as n. Next he removes n from blackboard and writes n-2^k instead. The player that can not continue the game (there is no such k that satisfies the constrains) looses the game.

The First player starts the game and they play in turns alternatively. Knowing that both two players play optimally you have to specify the winner.

Input:

First line of the Input contains an integer T, the number of testcase. 0 <= T &...
show more

Facebook  |  Level - 2

Answer Write Code Visit Question Page