Move all equal objects to the median location of those objects.
So if you have
{5,5,1,5,1,1,1,5,1,5}
Then we would move the fives to index 3 and the 1's to index 5.
Why? Consider any candidate position to place a collection of objects.
If there are x more objects to the left of that position than
@bharat
n=4 k =2
1 2 5 7
this is the explanation for the 3rd case given in the question
For the third case, group objects 1 and 2 together by moving the first
object to position 2 and group objects 3 and 4 together by moving object 3
to position 7. Thus the answer is 1 + 2 = 3.
here the eleme
@rakesh : u misunderstood the question ..
As per u'r ans to ex is ...
1,3 to 2 --> cost = 1+3=4
10 to 9 --> cost = 10. => total cost = 10+4 =14.
On Sat, Mar 23, 2013 at 9:26 PM, rakesh kumar wrote:
>
> Ok here is a counter example for your solution
>
> for n= 5 ,k=2
> 1 2 3 9 10
> n-k=>3 so mov
Ok here is a counter example for your solution
for n= 5 ,k=2
1 2 3 9 10
n-k=>3 so moving first 3 elements ans = 1+2+3 =6
but the answer should be 3
by placing center of 2 groups be 2,9 and moving 1 ,3 to 2 and 10 to 9
On Sat, Mar 23, 2013 at 9:09 PM, bharat b wrote:
> If we take examples shown
If we take examples shown above ..
3 3
1 1 3 --> we need 3 groups and 3 numbers are given.. no need to do anything.
3 2
1 2 4 --> we need to form 2 groups ..sort it. n-k=1-> first 1 element(s)
has to be moved to other bigger elements. ans=1.
4 2
1 2 5 7 --> we need to form 2 groups.. sort it. n-k=2
I don't get it how sorting will get us to the solution
On Sat, Mar 23, 2013 at 7:23 PM, bharat b wrote:
> can any one give counter example where sorting doesn't work?
>
>
> On Sat, Mar 23, 2013 at 3:15 PM, rakesh kumar
> wrote:
>
>> this was a facebook online programming contest question so righ
can any one give counter example where sorting doesn't work?
On Sat, Mar 23, 2013 at 3:15 PM, rakesh kumar wrote:
> this was a facebook online programming contest question so right now there
> is no link available for that
>
>
> On Sat, Mar 23, 2013 at 2:59 PM, Lucifer wrote:
>
>> Looks like a
this was a facebook online programming contest question so right now there
is no link available for that
On Sat, Mar 23, 2013 at 2:59 PM, Lucifer wrote:
> Looks like a dp problem..
> I have an idea..
> I believe that u must have this problem hosted on a system having a code
> checker..
> Can yo
Looks like a dp problem..
I have an idea..
I believe that u must have this problem hosted on a system having a code
checker..
Can you provide the link to the same, so that we can see if the logic
works..
On Saturday, 23 March 2013 14:29:42 UTC+5:30, rakesh kumar wrote:
>
>
> There are N objects
> There are N objects kept in a row. The ith object is at position x_i. You
> want to partition them into K groups. You want to move all objects
> belonging to the same group to the same position. Objects in two different
> groups may be placed at the same position. What is the minimum total amount
At first I found this tricky, as the number of strings in the array is
unknown, and it can be hard to iterate over unknown items of unknown
length. Since repeated combinations are included, we know the total number
of combinations (lengths of all strings multiplied). In my Ruby example
below, I u
Well as far as I Knw this is the typical question which Amazon was know to
ask frequently ... the reason behind this is simple to see how is the
peoples approach. However the right answer of this question is yet to found
... its under research...
On Mon, Jul 30, 2012 at 6:46 PM, Lucifer wrote:
@above..
In case the no of nodes that are placed at the certain height from the
start node are growing at an extremely fast rate, we can instead use a
dfs approach as well.
On 30 July, 18:13, Lucifer wrote:
> @Mahendra Sengar..
>
> We can solve it by interpreting it as a graph problem (as N and
@Mahendra Sengar..
We can solve it by interpreting it as a graph problem (as N and K are
small).
Lets say that :-
a) Each node in the graph defines a particular state of the disks and
the pegs.
b) Each edge in the graph defines a valid transition from one state to
another and weight of each edge
couldn't understand the question ??
so we have been given a combination and ranking set
and set of cards ?
now if every time any one picks up 3/5/7, rating must be higher. seems
like a lot of randomness here.
Do we need to rearrange the cards. and how user is going to pickup the
card , from top, r
http://codegolf.stackexchange.com/questions/2952/count-number-of-hefty-decimals-between-2-numbers
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group,
@Gene,
The algorithm which you have given below is O(n^2). I tried too and could
not figure out anything better than this unless we go for data structures
like kd-trees, as you already suggested.
Is it really the case that w/o using kd-tree, there is no better algorithm?
On Fri, Dec 23, 2011 at 5
AND, for two points to be close, they need not be on the same quadrant
On Dec 21, 10:55 pm, atul anand wrote:
> to find all points which lies on the same quadrant for a specific node(say
> 1) , we have to check all nodes...rite??
> we have to find difference b/w 2 node(frome origin ) is less or g
@Gene -
Cool algorithm! I tried before in java and messed a little to get exact
output format.
Just wondering how you came up with simple yet working code?
-Carol
On Thu, Dec 22, 2011 at 6:08 PM, Gene wrote:
> The simplest algorithm is probably to check each point against all
> others while mai
The simplest algorithm is probably to check each point against all
others while maintaining a list of the top 3. Since 3 is a small
number, you can just maintain the top 3 in sorted order by insertion.
For a bigger K top-K you'd use a max heap.
This can also be done in O(n log n) time by building
Binary tree is 2n-2
this question was asked in MS also...
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Sun, Dec 4, 2011 at 4:59 PM, Ashish Goel wrote:
> wouldn't a binary tree do?
> Best Regards
> Ashish Goel
> "Think positive and find fue
wouldn't a binary tree do?
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Tue, Nov 29, 2011 at 3:17 AM, Dave wrote:
> @Atul: Your code uses 2*n - 2 comparisons. Thus, it is non-responsive
> to the problem of using something close to 3*n/2 compa
yup...wrong solution by me
Aamir solution is correct.
On Tue, Nov 29, 2011 at 3:17 AM, Dave wrote:
> @Atul: Your code uses 2*n - 2 comparisons. Thus, it is non-responsive
> to the problem of using something close to 3*n/2 comparisons.
>
> Dave
>
> On Nov 28, 12:20 pm, atul anand wrote:
> > voi
@Atul: Your code uses 2*n - 2 comparisons. Thus, it is non-responsive
to the problem of using something close to 3*n/2 comparisons.
Dave
On Nov 28, 12:20 pm, atul anand wrote:
> void findMinMax(int arr[],int len,int *min,int *max)
> {
> int tempMin,tempMax,i;
>
> tempMin=arr[0];
> tempMax=
Hey what was the facebook question at IIT Roorkee?
On Nov 5, 6:04 pm, saket wrote:
> As far as I have googled about the 'game of life' problem, of which
> this question is a variant ; no mathematical pattern/series emerges
> out of it ...
> but in this problem since the moves are defined in a 3*
As far as I have googled about the 'game of life' problem, of which
this question is a variant ; no mathematical pattern/series emerges
out of it ...
but in this problem since the moves are defined in a 3*3 grids, I
found some test cases where the board configurations do not change
after certain k
No,O(N^2) because all the flips happens simultaneously, it can be
reduce to O(2N) if each tile is represented using a single bit
On Fri, Nov 4, 2011 at 11:12 PM, Dumanshu wrote:
> is ur brute force O(1) for space?
>
> On Nov 4, 10:24 am, sunny agrawal wrote:
>> What can be a better solution than
is ur brute force O(1) for space?
On Nov 4, 10:24 am, sunny agrawal wrote:
> What can be a better solution than a Brute Force O(N^2* No of iteration)
>
> --
> Sunny Aggrawal
> B.Tech. V year,CSI
> Indian Institute Of Technology,Roorkee
>
> fb1_input.txt
> < 1KViewDownload
>
> facebook.jpg
> 119
i/p o/p files are attached in the post, see carefully :-o
On Fri, Nov 4, 2011 at 6:23 PM, Dumanshu wrote:
> plz post a samle input output..
>
> On Nov 4, 10:24 am, sunny agrawal wrote:
>> What can be a better solution than a Brute Force O(N^2* No of iteration)
>>
>> --
>> Sunny Aggrawal
>> B.Tec
plz post a samle input output..
On Nov 4, 10:24 am, sunny agrawal wrote:
> What can be a better solution than a Brute Force O(N^2* No of iteration)
>
> --
> Sunny Aggrawal
> B.Tech. V year,CSI
> Indian Institute Of Technology,Roorkee
>
> fb1_input.txt
> < 1KViewDownload
>
> facebook.jpg
> 119KV
logic:
N=3.. k=5th(position).length...
no. of setbit :0...
000 k =5
no. of setbit :1.. on every loop get next number of same number of bits and
decrement k by 1.
001k = 4
010k=3
100k= 2
no. of setbit: 2
011 k=1..
101
110
Therefore answer is 011
complexity : O(n)...
code::
#include
#include
void check(int &count, int &k,int max)
{
int right,leftmost,rightmost;
if(k==1)
return;
right=count&(-count);
leftmost=count+right;
rightmost=count^leftmost;
rightmost=rightmost/right;
rightmost=rightmost>>2;
count=leftmost
made it.. :)
With regards,
Praveen Raj
DCE-IT 3rd yr
735993
praveen0...@gmail.com
On Tue, Oct 25, 2011 at 11:13 AM, raju wrote:
> @icy
> It's still there except that you'll get a different question.
> That page promises you a telephone interview if you solve the challenge
> but I don't k
@icy
It's still there except that you'll get a different question.
That page promises you a telephone interview if you solve the challenge
but I don't know how true that is for non-US guys ..
i solved one question two weeks back .. and no one contacted me till now ..
~raju
On Tue, Oct 25, 2011
the contests are over... this was a question asked in a college...
but now that you have already written such an awesome code, would you mind
sharing it??? or atleast the algorithm of your code???
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" grou
is this contest still going? if so, where ? i have a solution that
does
(100, 1267650600228229401496703205376 )(just one hundred 1's)
in 0.03 seconds in an older ruby on an older pc
I'd like to submit ;P
On Oct 21, 10:48 pm, sunny agrawal wrote:
> yea i know 1st Approach is much better and
The questions asked to us was simliar to this (it was titled *The Game of
Life* :D),
Consider a MxN matrix, with each cell painted either black or white. A flip
is defined over a cell as inverting the colors of all cells in the 3x3 grid
centered at that cell. The outermost boundary never changes c
Hi,
Thanks for this information. How many rounds of interview do they have and
what package do they offer??
On Thu, Sep 8, 2011 at 9:25 AM, arvinthdd wrote:
> Try the " facebook puzzle master " page and few given puzzles there.
> FB loves linux, mac a lot. Your exposure to these OS is a big plu
Try the " facebook puzzle master " page and few given puzzles there.
FB loves linux, mac a lot. Your exposure to these OS is a big plus.
Its all about puzzle solving and your approach to new problems.
On Sep 8, 1:04 am, Ankit Minglani wrote:
> they will give a puzzle kind of problem .. and you wi
I'm wondering if we should be using the rand() library function or
the guy is expecting us to create a random function.
y = rand( )%100; if(yhttp://groups.google.com/group/algogeeks?hl=en.
No i was not able to come up with a soln dere.. my bad :(
This was my 1st interview hope the upcoming interviews would be nice!!
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
I am wrong about the complexity. Its O(n*2^n).
>> @amitno it wont work..check it..
My code generates all subsets of a set containing elements from 1 to
n(inclusive). I was answering for ankur.
Why won't it work ?
On Jul 28, 1:39 pm, Piyush Sinha wrote:
> @amitno it wont work..check it..
ya me toowas readin % as modulus :)
*Muthuraj R.
4TH Year BE.**
Information Science Dept*
*PESIT, Bengaluru .
*
On Thu, Jul 28, 2011 at 9:13 PM, sunny agrawal wrote:
> Okay... i was reading % as Modulus operator :(
>
> did u gave the solution Nikhil posted , i think that should be the answ
Okay... i was reading % as Modulus operator :(
did u gave the solution Nikhil posted , i think that should be the answer.
On Thu, Jul 28, 2011 at 9:10 PM, KK wrote:
> @Nikhil: ya true but i dont know wht else was he expecting.
>
> @sunny and Muthu: like suppose u pass 20 then func should re
@Nikhil: ya true but i dont know wht else was he expecting.
@sunny and Muthu: like suppose u pass 20 then func should return true
with 20% probabily and false otherwise...
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this g
as Number of possible sets are nCk i think complexity of the best solution
will be O(k*nCk) (as in siddarths solution)
siddharth's solution will fail in case k > 64
a simple recursive program is possible i think in same complexity.
On Thu, Jul 28, 2011 at 6:40 PM, Tushar Bindal wrote:
> though th
though the code given by siddharth seems to be a bit tough to understand due
to one long statement, it gives a good idea to run the main loop fron 2^k
-1 to (2^k - 1)*(2^(n-k)) since these rae the only numbers having k digits
set
--
You received this message because you are subscribed to the Goo
#include
#include
int set_bits(int a)
{
int c=0;
while(a)
{
if(a & 1)
c++;
a >>=1;
}
return c;
}
void sub(int a[],int n,int k)
{
int i; int x,c=0,j;
x = pow(2,n);
for(i=0;i>j & 1)
{
#include
#define ARR_LEN 5
using namespace std;
int main()
{
int int_arr[ARR_LEN], k, min, max, x, temp, i;
for(i=0; i>int_arr[i];
cout<<"Enter k: ";
cin>>k;
min = (1<>2)/(x&(-x )
{
temp = x;
i = 0;
while(temp)
{
@amitno it wont work..check it..
On Wed, Jul 27, 2011 at 10:07 PM, amit wrote:
> This should be O(2^n)
>
> #include
> #include
> using namespace std;
>
> int n;
> int sol[1000];
> void solve(int pos, int k) {
>for(int i = 0; i < k; i++) printf("%d, ", sol[i]);
>putchar('\n');
>
This should be O(2^n)
#include
#include
using namespace std;
int n;
int sol[1000];
void solve(int pos, int k) {
for(int i = 0; i < k; i++) printf("%d, ", sol[i]);
putchar('\n');
for(int i = pos; i < n; i++) {
sol[k] = i+1;
solve(i+1, k+1);
}
}
int main() {
s
You can take a string with k no. of 1's at the end and generate all
possible permutations of the string thus formed.Doing this way you can
generate all possible strings and corresponding to each "1" in string
write the number in array(corresponding to that position) and thus you
can generate all su
First of all i would like to describe the what an event it is..
so In computing an event is an action that is usually initiated
outside the scope of a program and that is handled by a piece of code
inside the program.
I Would Like to Add Some Points & modify the above algo so that it can
be coded
@sravan,
What i meant was get the jth digit in the representation of i to the base
NUM_PER_DIGIT. ie 3rd digit of (2137)8 which is 2.. 7 is the 0th digit, 3
being 1st digit, 1 being 2nd digit and 2 being 3rd digit.Here 2137 is a base
8 representation.
Thanks,
Immanuel
On Tue, May 24, 2011 at 6:37
@Immanuel:
In the iteretive approach, can you tell me what you meant by this function.
A code is not required, but, how are we going to calculate? the method name
is little confusing.
The recursive is good.. but.. I'm looking at the iterative approach.
---> getJthDigitinItotheBaseNumPerDigit(N
@Anuj, true.This will optimise the solution by reducing the amount of stack
space used for recursion.
NUM_PER_DIGIT = 3
char c[][NUM_PER_DIGIT] = {"abc","def",...};
char n[] = 2156169 (number is pressed);
int k=7;
char * s = (char *) malloc(sizeof(char) * k);
void printAllCombinations (int k, c
Immanuel,
We can keep c and n arrays as global variable as they are not part of state
of the recursion.
Anuj Agarwal
Engineering is the art of making what you want from things you can get.
On Mon, May 23, 2011 at 10:04 PM, immanuel kingston <
kingston.imman...@gmail.com> wrote:
> small correcti
small correction
On Mon, May 23, 2011 at 9:46 PM, immanuel kingston <
kingston.imman...@gmail.com> wrote:
> A Recursive soln:
>
>
> NUM_PER_DIGIT = 3
> char c[][NUM_PER_DIGIT] = {"abc","def",...};
>
> char n[] = 2156169 (number is pressed);
> int k=7;
> char * s = (char *) malloc(sizeof(char) * k
A Recursive soln:
NUM_PER_DIGIT = 3
char c[][NUM_PER_DIGIT] = {"abc","def",...};
char n[] = 2156169 (number is pressed);
int k=7;
char * s = (char *) malloc(sizeof(char) * k);
void printAllCombinations (char c[][], char n[], int k, char *s, int count)
{
if (count >= k - 1) {
s[k] = '
Extending the above soln:
NUM_PER_DIGIT = 3
char c[][NUM_PER_DIGIT] = {"abc","def",...};
char n[] = 2156169 (number is pressed);
int k=7;
for i <-- 0 to NUM_PER_DIGIT ^ k
String s="";
for j <-- 0 to k
int index = getJthDigitinItotheBaseNumPerDigit(NUM_PER_DIGIT,i,j);
// ie get 1s
the same question i have asked in microsoft interview. (if it is the same
:P)
for 12 perutation are (ad, ae, af, bd, be, bf, cd, ce ,cf);
i have given them 3 solution(recusrsive, stack based) and the last one what
they wanted.
take a tertiary number(n) = 3^(number of digits) in case of 12 it is e
I didn't get the question actually. I have copied the post(the
question). but i dont think for 12, 36 can be the answer. We have to
go for the permutation of the telephone number i guess after
substituting for each number the corresponding set of alphabets.
The question given is - "Given a telephon
best approach for such problems is try to solve for very small numbers
then do DP for solve large numbers. as follows
single digit = 7,8,9 answer = 3 [i am taking 7 inclussive]
double digit= 7*2 = 14. now smallest number can be.
59=1
68, 69 = 2
77 78, 79,=3
86, 87, 88, 89=4
95,96,97,98,99 =5
3 dig
Ok. Here's a possible O(n) solution.
Assuming last digit of a is 0.
for(n=a;n<=b;n+=10)
{
Calculate the sum of digits, leaving the last digit.
Find the minimum value of last digit for it to be a heavy number.
Increment count by 10-that number.
}
So here, complexity will be: O(n/10*(d-1))
where, d
t; Would that work equally well for 59 up to 1000?
>
> Sent from my Windows Phone From: James Curran
> Sent: Tuesday, April 05, 2011 7:50 AM
> To: Algorithm Geeks
> Subject: [algogeeks] Re: Facebook Interview QuestionHeavy Number
> OK, here's my rather rambling theory on
Hey , i m a new follower to this group.. i was actually looking for a nice
group that would contain a nice challenge to sharpen the brain. and i
finally ended with this group... i m happy to follo this group along with
geeks like you.
--
You received this message because you are subscribed to the
Hey James
Would that work equally well for 59 up to 1000?
Sent from my Windows Phone From: James Curran
Sent: Tuesday, April 05, 2011 7:50 AM
To: Algorithm Geeks
Subject: [algogeeks] Re: Facebook Interview QuestionHeavy Number
OK, here's my rather rambling theory on how to approa
OK, here's my rather rambling theory on how to approach it:
First break the range down into a series of smaller ranges into form:
xxyzz
where:
xx is 0 to n digits which are fixed throughout the range.
y is 0 or 1 digit in the range 0..n or m..9 (with a special case *)
zz is 0 to n digits in th
@all , Nikhi Jindal ,.as i already told that O(n^2) Solution is
Obvious ..but .it wont work for 1Biillion as a time
limit exceeds , memory Error occur, so its not a good solution ..I
think There is DP Solution Exist For Thats We Need to Figure it Out to
resolve this problem
@anand what r u trying
69 matches
Mail list logo