wu :: forums
« wu :: forums - Google interview question »

Welcome, Guest. Please Login or Register.
Apr 25th, 2024, 2:38pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: SMQ, Eigenray, towr, Grimbal, william wu, ThudnBlunder, Icarus)
   Google interview question
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Google interview question  (Read 4305 times)
diptendubhowmick
Newbie
*





   


Posts: 11
Google interview question  
« on: Mar 6th, 2014, 7:31am »
Quote Quote Modify Modify

Recently I was asked this question in Google interview -
Suppose you have a set of n random positive numbers. You can pick p numbers at a time where p is a constant. Come up with a strategy to select p numbers every time in such a way that all the big numbers come in the end with highest probability.
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Google interview question  
« Reply #1 on: Mar 6th, 2014, 8:00am »
Quote Quote Modify Modify

What sort of constraints are there? 'cause as long as p >=2 you can just sort the set as long as you're allowed to pick p numbers often enough.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
diptendubhowmick
Newbie
*





   


Posts: 11
Re: Google interview question  
« Reply #2 on: Mar 6th, 2014, 8:10pm »
Quote Quote Modify Modify

on Mar 6th, 2014, 8:00am, towr wrote:
What sort of constraints are there? 'cause as long as p >=2 you can just sort the set as long as you're allowed to pick p numbers often enough.

 
The constraint here is that you are not given the dataset beforehand so you won't be able to any kind of preprocessing like sorting on it. You will be given p + constant number of elements at a time and you need to run your algo on that. The catch here is that you don't have the visibility of the entire dataset so that you can place the big numbers in the end by sorting the whole array.
IP Logged
mttdbrd
Newbie
*





   


Posts: 1
Re: Google interview question  
« Reply #3 on: Mar 9th, 2014, 8:06pm »
Quote Quote Modify Modify

To make sure we understand this correctly: you select p elements such that each selection increases the probability that all of the biggest numbers will come in the final selection? Or is it that they must come closest to the maximum index position in the p buffer?
 
This set is not sorted, cannot be sorted, and does not contain duplicate elements, correct?
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Google interview question  
« Reply #4 on: Mar 11th, 2014, 7:47am »
Quote Quote Modify Modify

Is the question how to pick the p largest numbers in a long stream, given that you can only store p values at a time?
 
You just need to discard the smallest number if it is smaller than the next number you examine.
 
To do it efficiently, you can use a heap.
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board