[algogeeks] Re: Question on algo

2015-10-10 Thread Dave
Very simple. If MAXOR of the entire input set is not equal to zero, there are no subsets with equal MAXORs. If MAXOR of the entire set is zero, then any two complementary subsets have equal MAXORs. Since there are 2^N (^ is the exponential operator) subsets of a set of N elements, Little Panda

Re: [algogeeks] Re: Question on checking divisibility of binomial coefficients of a number by a prime number

2012-08-27 Thread Dave
@Ankit: I haven't written code for this problem, but here is how I would do it. You are given values of n and P, with n being up to a 500-digit number (e.g., stored in an array, with say 9 digits of the number stored in each of up to 112 (500/9 rounded up) integers and P fitting in one integer.

Re: [algogeeks] Re: Question on checking divisibility of binomial coefficients of a number by a prime number

2012-08-27 Thread Ankit Singh
@dave: Can u Please elaborate your idea?? I didn't understand lucas theorem and in that theorem, i see too much calculation and here we have to deal with testcases upto 100 and each testcase containing n in range of 10500. On Mon, Aug 27, 2012 at 4:02 AM, Dave wrote: > @Ankit: Apply Lucas' The

[algogeeks] Re: Question on checking divisibility of binomial coefficients of a number by a prime number

2012-08-26 Thread Dave
@Ankit: Apply Lucas' Theorem, which you can find written up in Wikipedia. Dave On Sunday, August 26, 2012 3:57:18 PM UTC-5, Ankit Singh wrote: > In mathematics, *binomial coefficients* are a family of positive integers > that occur as coefficients in the binomial theorem. [image: \tbinom > nk

Re: [algogeeks] Re: question

2012-08-22 Thread megha agrawal
Thanks Dave sir ! On Wed, Aug 22, 2012 at 3:47 AM, Dave wrote: > @Megha: Answered in one line of code in the post > https://groups.google.com/d/msg/algogeeks/Fa-5AQR3ACU/jlmjb_nEZCsJ, which > also contains a link to an explanation of how the algorithm works. > > Dave > > On Tuesday, August 21, 2

[algogeeks] Re: question

2012-08-21 Thread Dave
@Megha: Answered in one line of code in the post https://groups.google.com/d/msg/algogeeks/Fa-5AQR3ACU/jlmjb_nEZCsJ, which also contains a link to an explanation of how the algorithm works. Dave On Tuesday, August 21, 2012 8:23:21 AM UTC-5, megha agrawal wrote: > >Can anyone suggest solut

[algogeeks] Re: Question asked in Amazon online test

2012-07-24 Thread Amit
Let's define a term "RANDOMNESS" of array as... summation of position of each 1's for eg RANDOMNESS for (0,0,1,0,1,0,1,1) will be 23 now calculate max possible RANDOMNESS for the given array (each 1 on max possible right position) here it will be 26 so ans will be--> MAX RANDOMNESS of given arra

Re: [algogeeks] Re: Question asked in Amazon Online Test

2012-07-01 Thread Akshat Sapra
*Using Stack : * j = 0; for ( int i = 0; i < prefix.len(); i++ ) { if ( isOperator(prefix[i]) ) stk.push(prefix[i]); else { postfix[j] = prefix[i]; j++; while ( !stk.empty() && stk.top == '#' ) {

[algogeeks] Re: Question asked in Amazon Online Test

2012-07-01 Thread neelpulse
I think this algo is correct. On Sunday, 1 July 2012 13:06:17 UTC+5:30, Ashu wrote: > > count=0; > Start parsing from left to right > If operator push in stack. > In number add in queue and increment count by one, > if count == 2 then > pop from stack add in queue, decrements the count by one. >

[algogeeks] Re: Question asked in Amazon Online Test

2012-07-01 Thread Ashu
count=0; Start parsing from left to right If operator push in stack. In number add in queue and increment count by one, if count == 2 then pop from stack add in queue, decrements the count by one. On Friday, 29 June 2012 19:46:43 UTC+5:30, zerocool142 wrote: > > Given an integer expression in a

[algogeeks] Re: Question asked in Amazon online test

2012-06-30 Thread Navin Gupta
minimum number of swaps required to sort the given input array = no. of inveresions in the array No. of inversions in the array is defined as no. of pairs (i,j) such that a[i] > a[j] && ihttps://groups.google.com/d/msg/algogeeks/-/44gDXly-hq0J. To post to this group, send email to algogeeks@

[algogeeks] Re: Question asked in Amazon online test

2012-06-28 Thread Prateek Khurana
Hi, This one is quite easy. You have to calculate the number of one's before every zero and add them up. That's it. public class Test1 { public void printArray(int[] tmpArr) { for (int i : tmpArr) { System.out.println(i); } } public int calculateMinSwaps(int[] tmpArr) { int minSwaps = 0; int n

[algogeeks] Re: Question asked in Amazon online test

2012-06-28 Thread ANKIT BHARDWAJ
get the right most zero and left most one if index of right most zero is less than the index of left most one ,the problem is solved other wise swap 0 and 1 and so on... i argue this will give minimum swaps... -- You received this message because you are subscribed to the Google Groups "Algor

[algogeeks] Re: Question asked in Tachyon interview

2012-06-27 Thread Dave
@Zerocool142: See https://groups.google.com/d/msg/algogeeks/483lcb0FTY0/YoQTNbOQ3aIJ. It implements addition using bitwise operators, and then uses that addition function and more bit operations to do multiplication, handling both positive and negative (2's complement) numbers. Dave On Tuesd

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
@deepika anand solution given by me is for getting number of swap's in O(n) as far as sorting goes any O(n lgn) algo can be used . if count sort is allowed then O(n) for sorting also.[constant extra space.. ] On Sat, Jun 23, 2012 at 12:49 AM, ashish jain wrote: > @all > > yaa.. For getting nu

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread ashish jain
@all yaa.. For getting number of swaps.. we have to calculate total number of zeroes on the right for each '1' and on adding them we will get the number of swaps. and in O(n) time. On Sat, Jun 23, 2012 at 1:16 PM, Guruprasad Sridharan < sridharan.mi...@gmail.com> wrote: > It will work because

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Guruprasad Sridharan
It will work because we need to swap only adjacent elements. So we do a sweep from left to right finding the number of ones encountered to the left of a zero when we find a zero. We keep adding the number as we sweep the entire length. On Sat, Jun 23, 2012 at 1:14 PM, deepikaanand wrote: > @saura

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread rajesh pandey
start scanning the array from last .. maintain two pointers. one for last encountered zero. second for moving backward. whenever you encounter the one just swap it with the last zero. enhance the pointer till next zero encounters. at last you will have the number of swaps. I think my solution

[algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Anurag Gupta
if we just need to determine number of swaps, it can be Done in O(n) Ex : 11100010 start counting number of zeros from the end so we have zeroCount = 1 whenever we encounter a 1 we add current zeroCount to numberOfSwaps so numberOfSwaps = 1 and so on the final value of numberOsSwaps is the answe

[algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread deepikaanand
@saurabh..wat array r u getting finallyis it all 1's or in sorted order for the input int a[8]={1,1,1,0,1,0,1,1}; -- 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 unsubsc

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
@ALL see if this work's : #include using namespace std; int a[8]={0,0,1,0,1,0,1,1}; int count_zero(int size) { int i,count =0; for(i=0;i wrote: > i think it can be done in O(n) > for each 1, calculate no. of zeros in right > and adding all no. of zeros in right of all 1's will give no. of

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Darpan Baweja
i think it can be done in O(n) for each 1, calculate no. of zeros in right and adding all no. of zeros in right of all 1's will give no. of swaps. correct me if i am wrong On Sat, Jun 23, 2012 at 12:19 PM, Sourabh Singh wrote: > @deepika > > yes, it's giving number of swaps. > still Linear time

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-22 Thread Sourabh Singh
@deepika yes, it's giving number of swaps. still Linear time solution would be better :-) On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand wrote: > > will bubble sort give number of swaps?? > > I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5 > and for the array  (0,0,1,0,1,0,1,1

[algogeeks] Re: Question asked in Amazon online test

2012-06-22 Thread deepikaanand
will bubble sort give number of swaps?? I tried the (bubble sort) code of 1,0,0,1,1,0,1 >swapcount = 5 and for the array (0,0,1,0,1,0,1,1)>swapcount = 3 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send em

Re: [algogeeks] Re: question

2011-09-22 Thread Shravan Kumar
@Yogesh Yadav algo geek's approach is correct. With your number 759845. When you start moving left from right most integer, you stop when the numbers are no longer in increasing order, in this case you stop at first integer i.e, at 5 and swap with 4. Which gives exactly same correct answer as you

Re: [algogeeks] Re: question

2011-09-22 Thread Abhishek Goswami
I have seen code and output but I think it should be 7965 am i right? if you are looking for first largest On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya wrote: > http://ideone.com/pmil8 > > > On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya wrote: > >> @kartik >> Is it right >> >> >> On Wed, Sep 21, 2

Re: [algogeeks] Re: question

2011-09-22 Thread Piyush Kapoor
Isn't it simply finding the next permutation of a number??? On Thu, Sep 22, 2011 at 7:01 PM, Dheeraj Sharma wrote: > @bharat...so i thnk 7585 shud hav 7855 as ans..!! > > > On Thu, Sep 22, 2011 at 5:42 PM, Arpit Sood wrote: > >> @yogesh nice algo... >> >> it is not even required to sort the lef

Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
@bharat...so i thnk 7585 shud hav 7855 as ans..!! On Thu, Sep 22, 2011 at 5:42 PM, Arpit Sood wrote: > @yogesh nice algo... > > it is not even required to sort the left out array, just reverse it :) > > On Thu, Sep 22, 2011 at 5:05 PM, Yogesh Yadav wrote: > >> @ratan: thanks for correction

Re: [algogeeks] Re: question

2011-09-22 Thread Arpit Sood
@yogesh nice algo... it is not even required to sort the left out array, just reverse it :) On Thu, Sep 22, 2011 at 5:05 PM, Yogesh Yadav wrote: > @ratan: thanks for correction little correction in my logic... > > start from rightmost digit and search towards left a digit less than > this.

Re: [algogeeks] Re: question

2011-09-22 Thread Yogesh Yadav
@ratan: thanks for correction little correction in my logic... start from rightmost digit and search towards left a digit less than this... if found ... just swap...now after swapping save the index with which you are swapping ...and after that sort the array in ascending order...u got the an

Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
the answer should be 759435... On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav wrote: > my logic: if wrong then plz tell... > > start from rightmost digit and search towards left a digit less than this... > if found ... just swap...u got the answer... if no small digit found then > select secon

Re: [algogeeks] Re: question

2011-09-22 Thread Yogesh Yadav
my logic: if wrong then plz tell... start from rightmost digit and search towards left a digit less than this... if found ... just swap...u got the answer... if no small digit found then select second rightmost digit and follow the same process...and so on... for ex: 759354 rightmost digit

Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
the following pseudocode may work: for(i=l;i>=0;i--) { if(a[i-1] wrote: > @deeraj : for i/p 7585 u'r code is giving 7855 .. > > On Thu, Sep 22, 2011 at 6:54 AM, algo geek wrote: >> >> Keep a pointer ont the rightmost digit. Keep moving right until you find >> the number in increasing number. As

Re: [algogeeks] Re: question

2011-09-22 Thread Yogesh Yadav
@algo geek: there is some error in your logic... consider a number 759845 according to ur logic the number greater than this will be 784559 but it should be 759854 . On Thu, Sep 22, 2011 at 4:24 PM, algo geek wrote: > Keep a pointer ont the rightmost digit. Keep moving right until y

Re: [algogeeks] Re: question

2011-09-22 Thread bharatkumar bagana
@deeraj : for i/p 7585 u'r code is giving 7855 .. On Thu, Sep 22, 2011 at 6:54 AM, algo geek wrote: > Keep a pointer ont the rightmost digit. Keep moving right until you find > the number in increasing number. As soon as this breaks. stop. Swap the > digit at the current position with the smalle

Re: [algogeeks] Re: question

2011-09-22 Thread algo geek
Keep a pointer ont the rightmost digit. Keep moving right until you find the number in increasing number. As soon as this breaks. stop. Swap the digit at the current position with the smallest digit, but larger than the current position digit, sort the array to the right of the current position in

Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
in nlog(n) #include #include #include #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int t; void quicksort(char arr[],int left,int right) { if(left>str; int min=0; int len=strlen(str); while(str[i]) { if(str[i]<=str[min]) min=

Re: [algogeeks] Re: question

2011-09-22 Thread kartik sachan
@ratan suggest some efficient algo... -- 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, send email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
#include #include #include #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int main() { char str[100],t; cin>>str; int len=strlen(str); int i,x,boo=1; for(i=len-1;i>0&&boo;i--) { for(x=i-1;x>=0&&boo;x--) { if(str[x]0) { //Sorting..

Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
@dheeraj ... ya u r ryt thnxs for the correction On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma wrote: > @Ratan: > i think the next largest here would be 784559 > > On Thu, Sep 22, 2011 at 12:39 PM, Ratan wrote: >> >> @kartik : to some extent ur code is giving the right answer... btw >> som

Re: [algogeeks] Re: question

2011-09-22 Thread Dheeraj Sharma
@Ratan: i think the next largest here would be 784559 On Thu, Sep 22, 2011 at 12:39 PM, Ratan wrote: > @kartik : to some extent ur code is giving the right answer... btw > somehow check tis > let for example the no be 759854 > then the next biggest no is 794558 > btw ur program is giving 795854

Re: [algogeeks] Re: question

2011-09-22 Thread Ratan
@kartik : to some extent ur code is giving the right answer... btw somehow check tis let for example the no be 759854 then the next biggest no is 794558 btw ur program is giving 795854 which is undoubtedly wrong the code would give more appropriate result if u sort the numbers from from

Re: [algogeeks] Re: question

2011-09-21 Thread Ramakant Sharma
starting from right find first digit less then right most digit,if no any digit is less,then move to next right most and compair when found exchange those no, now sort the no.s up to that index of the given no which is exchanged: Ex: 43987723893239876 first required sequence: 439877238932[3]987

Re: [algogeeks] Re: question

2011-09-21 Thread kartik sachan
@arya ur code for 7695...giving ans 9765 but ans should be 7965 -- 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, send email to algogeeks+

Re: [algogeeks] Re: question

2011-09-21 Thread Anil Arya
http://ideone.com/pmil8 On Thu, Sep 22, 2011 at 12:46 AM, Anil Arya wrote: > @kartik > Is it right > > > On Wed, Sep 21, 2011 at 10:24 PM, kartik sachan > wrote: > >> obivously it will be first largest >> >> -- >> You received this message because you are subscribed to the Google Grou

Re: [algogeeks] Re: question

2011-09-21 Thread Anil Arya
@kartik Is it right On Wed, Sep 21, 2011 at 10:24 PM, kartik sachan wrote: > obivously it will be first largest > > -- > 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

Re: [algogeeks] Re: question

2011-09-21 Thread kartik sachan
obivously it will be first largest -- 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, send email to algogeeks+unsubscr...@googlegroups.com

[algogeeks] Re: question

2011-09-21 Thread Ankuj Gupta
If it is the first largest ? On Sep 21, 8:02 pm, Dave wrote: > @Prasanth: Since there is no requirement to find the next larger > number, you can go for the largest. Extract the digits into an array > using modulus and division by 10. Then sort the digits into descending > order. Finally, constru

[algogeeks] Re: question

2011-09-21 Thread Dave
@Prasanth: Since there is no requirement to find the next larger number, you can go for the largest. Extract the digits into an array using modulus and division by 10. Then sort the digits into descending order. Finally, construct the answer by repeated multiplication by 10 and addition. If you wa

[algogeeks] Re: Question -->

2011-09-20 Thread veeru
before, i wrote small mistake N=(N&(~0<<(j+1))|(~(~0

[algogeeks] Re: Question -->

2011-09-20 Thread veeru
N=(N&(~0<<(j+1))|(~(~0

[algogeeks] Re: Question -->

2011-09-20 Thread Don
@Dave: Beautiful. Don On Sep 20, 11:53 am, Dave wrote: > I am missing a couple of parentheses. So make that > > N = (N & ~((2 << j) - (1 << i))) | (M << i); > > And to make up for the extra post to get it right, I'll explain it: > 2< 1< The difference of the two is a number with one bits from pos

[algogeeks] Re: Question -->

2011-09-20 Thread Dave
I am missing a couple of parentheses. So make that N = (N & ~((2 << j) - (1 << i))) | (M << i); And to make up for the extra post to get it right, I'll explain it: 2< wrote: > @Ishan: Using bitwise operations: > > N = (N & ~((2 << j) - (1 << i) | (M << i); > > Dave > > On Sep 20, 2:03 am, Ishan A

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Ishan Aggarwal
Can someone explain me what this code is doing?? void main() { int n,m i,j; int max = ~0; // 1's through position j, then 0's int left = max - (( 1 << j) - 1); //1' after position i int right = (( 1<< i) -1) // 1's with 0's betwwen i and j int mask = left | right ; // clear i through j , then put

[algogeeks] Re: Question -->

2011-09-20 Thread Dave
@Ishan: Using bitwise operations: N = (N & ~((2 << j) - (1 << i) | (M << i); Dave On Sep 20, 2:03 am, Ishan Aggarwal wrote: > You are given two 32-bit numbers, N and M, and two bit positions, i and > j.Write a method to set all bits between i and j in N equal to M (e.g., M > becomes a substring

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Yogesh Yadav
@ishan: there is error in your loop bro... for(k=31;k>=0;k++) it should be k-- . On Tue, Sep 20, 2011 at 3:10 PM, vijay singh wrote: > > > On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal < > ishan.aggarwal.1...@gmail.com> wrote: > >> Hi, >> >> When I am running this program, I am getting seg

Re: [algogeeks] Re: Question -->

2011-09-20 Thread vijay singh
On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal < ishan.aggarwal.1...@gmail.com> wrote: > Hi, > > When I am running this program, I am getting segmentation fault. Can u plz > confirm where is the error. > > #include > void main() > { > int Num[31]={0}; > int Mum[31]={0}; > int n = 64,m = 7 ,i=0,j

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Dheeraj Sharma
int num1=0; int num2=1; int num3=21; int j=6; int i=2; for(int k=1;k<=(j-i);k++) { num2<<=1; num2+=1; printf("%d\n",num2); } for(int k=1;k<=i;k++) { num2<<=1; num3<<=1; printf("%d\n",num2); printf("%d\n",num3); } num2=~num2;

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Ishan Aggarwal
Again it is giving the same error. on changing it to 32. On Tue, Sep 20, 2011 at 2:18 PM, abhinav gupta wrote: > Instead of Num[31] u should tk Num[32] > > On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal < > ishan.aggarwal.1...@gmail.com> wrote: > >> Hi, >> >> When I am running this program, I a

Re: [algogeeks] Re: Question -->

2011-09-20 Thread abhinav gupta
Instead of Num[31] u should tk Num[32] On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal < ishan.aggarwal.1...@gmail.com> wrote: > Hi, > > When I am running this program, I am getting segmentation fault. Can u plz > confirm where is the error. > > #include > void main() > { > int Num[31]={0}; > int

Re: [algogeeks] Re: Question -->

2011-09-20 Thread Ishan Aggarwal
Hi, When I am running this program, I am getting segmentation fault. Can u plz confirm where is the error. #include void main() { int Num[31]={0}; int Mum[31]={0}; int n = 64,m = 7 ,i=0,j=3,k; for(k=31;k>=0;k++) { Num[k]=n & 1; Mum[k]=m & 1; n=n>>1; m=m>>1; } for(k=i;k<=j;k++) Num[k]=Mum[k]; f

[algogeeks] Re: Question -->

2011-09-20 Thread tec
mask = (1<<(j+1))-(1< wrote: > You can also solve the problem by using bit operators. by using >> << & | ! > . > Need sm thinking in dat..No time rite nw! > > On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta > wrote: > > > > > > > > > > > Its because o/p should look like dat.Bt dats simple you can d

[algogeeks] Re: question on algorithm

2011-09-19 Thread Don
I divide by 5 to determine how many ways there are to use nickles. I could have written a for loop: for(nickles = 0; (quarters+dimes+nickles) <= n; nickles += 5) ++result; But that would have just executed 1+(n-quarters-dimes)/5 times incrementing result every time. I just computed the result i

Re: [algogeeks] Re: question on algorithm

2011-09-17 Thread bharatkumar bagana
@don: will u pls explain why divided by 5 is used On Fri, Sep 16, 2011 at 3:44 PM, prasanth n wrote: > @Don: > thanks a lot > > On Sat, Sep 17, 2011 at 12:28 AM, Don wrote: > >> The algorithm is to count them, looping over the number of quarters >> and dimes. Then it is easy to compute the

Re: [algogeeks] Re: question on algorithm

2011-09-16 Thread prasanth n
@Don: thanks a lot On Sat, Sep 17, 2011 at 12:28 AM, Don wrote: > The algorithm is to count them, looping over the number of quarters > and dimes. Then it is easy to compute the number of nickles which > could be used, and the shortfall is made up with pennies. > It is very common to see a recur

[algogeeks] Re: question on algorithm

2011-09-16 Thread Don
The algorithm is to count them, looping over the number of quarters and dimes. Then it is easy to compute the number of nickles which could be used, and the shortfall is made up with pennies. It is very common to see a recursive solution, but that is not necessary or beneficial when the iterative s

[algogeeks] Re: Question --> plz answer

2011-09-16 Thread Gene
Sorry. Small mistake. First test should have been > W(n,k) = (k < 1 || k > n) ? 0 : This is fixed below. On Sep 16, 4:48 am, Gene wrote: > My guess is that the "and so on..." means we should be able to solve > this assuming the pyramid is as high as it needs to be in order not > to > overflow

[algogeeks] Re: Question --> plz answer

2011-09-16 Thread Gene
My guess is that the "and so on..." means we should be able to solve this assuming the pyramid is as high as it needs to be in order not to overflow. With this the problem gets more interesting. I worked it out a bit farther: L/C --- Filled cups 1 --- 1 3 --- 2,3 5 --- 5 7 --- 4-6 8 1/3 --- 8,9

[algogeeks] Re: Question --> plz answer

2011-09-16 Thread Gene
My guess is that the "and so on..." means we should be able to solve this assuming the pyramid is as high as it needs to be in order not to overflow. With this the problem gets more interesting. I worked it out a bit farther: L/C --- Filled cups 1 --- 1 3 --- 2,3 5 --- 5 7 --- 4-6 8 1/3 --- 8,9

[algogeeks] Re: Question --> plz answer

2011-09-13 Thread Dave
@Vikas. I tried to understand what you were saying, but couldn't. Sorry. Dave. On Sep 12, 7:33 am, vikas wrote: > If L <= C, then >     cup1 = L >     cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0 > else if L < 3*C, then >     cup1 = C >     cup2 = cup3 = (L-C)/2 >     cup4 = cup5 = cup6 = ove

[algogeeks] Re: Question --> plz answer

2011-09-12 Thread vikas
If L <= C, then cup1 = L cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0 else if L < 3*C, then cup1 = C cup2 = cup3 = (L-C)/2 cup4 = cup5 = cup6 = overflow = 0 else if L < 5*C, then cup1 = cup2 = cup3 = C cup4 = cup6 = (L-3*C)/4 cup5 = (L-3*C)/2 overflow = 0 els

[algogeeks] Re: Question --> plz answer

2011-09-11 Thread Dave
@Vikas: I think I have it covered. That's what the divisors do. If I'm wrong, give me a value of L where I am wrong. Dave On Sep 11, 2:17 pm, vikas wrote: > @Dave, >    should not rate of filling be considered here ? if you note , the > side cups are filling in half of rate than to rest of cups

[algogeeks] Re: Question --> plz answer

2011-09-11 Thread vikas
@Dave, should not rate of filling be considered here ? if you note , the side cups are filling in half of rate than to rest of cups in row. On Sep 11, 10:01 am, bharatkumar bagana wrote: > what is M? > > On Sat, Sep 10, 2011 at 8:10 PM, Ishan Aggarwal < > > > > > > > > > > ishan.aggarwal.1...@g

[algogeeks] Re: Question --> plz answer

2011-09-10 Thread Dave
@Ishan: Here is the algorithm: If L <= C, then cup1 = L cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0 else if L < 3*C, then cup1 = C cup2 = cup3 = (L-C)/2 cup4 = cup5 = cup6 = overflow = 0 else if L < 5*C, then cup1 = cup2 = cup3 = C cup4 = cup6 = (L-3*C)/4 cup5 =

[algogeeks] Re: Question --> plz answer

2011-09-10 Thread Ankuj Gupta
what is C and M On Sep 10, 7:40 pm, Ishan Aggarwal wrote: > 1.) > > there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so > on.. > It looks something like this > 1 > 2 3 > 4 5 6 > every cup has capacity C. you pour L liters of water from top . when cup 1 > gets filled , it o

[algogeeks] Re: question in C

2011-08-25 Thread Ninad Page
On Aug 24, 6:51 pm, sadhana kumar wrote: > Can anyone explain this code pls?? > > #include > #define f(a,b) a##b > #define g(a) #a > #define h(a) g(a) > int main() > { > printf("%s\n",h(f(1,2))); > printf("%s\n",g(f(1,2))); > return 0; > > > > > > > > } Read about stringizing operator (#) and

[algogeeks] Re: question on fork()

2011-08-24 Thread DK
@Ankuj: Sorry. I read the getch() as a call to green(). Please ignore the 20 green(). It should be 10 green() instead. -- DK http://twitter.com/divyekapoor http://www.divye.in http://gplus.to/divyekapoor -- You received this message because you are subscribed to the Google Groups "Algorithm

Re: [algogeeks] Re: question on fork()

2011-08-24 Thread shashi kant
6 red 10 greens On Wed, Aug 24, 2011 at 9:25 AM, Ankuj Gupta wrote: > how can be there 20 greens ? > > On Aug 24, 12:12 am, DK wrote: > > The standard library is neither multithread safe nor multiprocess safe. > > If you want the correct answer, use shared memory and maintain a shared > > cou

[algogeeks] Re: question on fork()

2011-08-23 Thread Ankuj Gupta
how can be there 20 greens ? On Aug 24, 12:12 am, DK wrote: > The standard library is neither multithread safe nor multiprocess safe. > If you want the correct answer, use shared memory and maintain a shared > counter. Alternatively, as a quick hack, insert a fflush(stdout) after the > printf sta

[algogeeks] Re: question on fork()

2011-08-23 Thread DK
The standard library is neither multithread safe nor multiprocess safe. If you want the correct answer, use shared memory and maintain a shared counter. Alternatively, as a quick hack, insert a fflush(stdout) after the printf statements. Answer: red() - 6 green() - 20 -- DK http://twitter.

Re: [algogeeks] Re: question on fork()

2011-08-23 Thread Prem Krishna Chettri
I Can See 10 Green and 10 Red Process.. Can Someone Compile to verify this... Prem On Tue, Aug 23, 2011 at 1:24 AM, gmagog...@gmail.com wrote: > Infinite times > Yanan Cao > > > > On Mon, Aug 22, 2011 at 2:43 PM, Don wrote: > >> // DO NOT RUN THIS! By inspection, how many times will it print "H

Re: [algogeeks] Re: question on fork()

2011-08-22 Thread gmagog...@gmail.com
Infinite times Yanan Cao On Mon, Aug 22, 2011 at 2:43 PM, Don wrote: > // DO NOT RUN THIS! By inspection, how many times will it print "Hello > world"? > // If you find out by running it, that is cheating. Don't do it! > int main() > { > int i=0, j=0; > for(i = 0; i*j < 20; ++i) > { >if

Re: [algogeeks] Re: question on fork()

2011-08-22 Thread gmagog...@gmail.com
I am getting 6 red and 8 green as expected using the original code Yanan Cao On Mon, Aug 22, 2011 at 2:38 PM, Yasir wrote: > Surprisingly, if I comment the last if condition ( which is AFTER red() > call ), it is printing red only 6 times as expected.. > http://ideone.com/XMHzC > > main() > {

[algogeeks] Re: question on fork()

2011-08-22 Thread Don
// DO NOT RUN THIS! By inspection, how many times will it print "Hello world"? // If you find out by running it, that is cheating. Don't do it! int main() { int i=0, j=0; for(i = 0; i*j < 20; ++i) { if (fork() > 0) ++j; else i = j = 0; printf("Hello world\n"); } return 0; }

[algogeeks] Re: question on fork()

2011-08-22 Thread Yasir
Surprisingly, if I comment the last if condition ( which is AFTER red() call ), it is printing red only 6 times as expected.. http://ideone.com/XMHzC main() { fork(); int color=fork(); if(color==0) fork(); red(); //if(color==0) // fork

[algogeeks] Re: question on fork()

2011-08-22 Thread Ankuj Gupta
I am getting 6 calls to red and 8 calls to green when i built parent child tree but when i ran this code http://ideone.com/UBaBB I got 10 calls to red and 10 calls to green. Can some explain this ? On Aug 22, 9:31 pm, ghsjgl k wrote: > i saw this question in one of DREAM companies > > i dont kn

[algogeeks] Re: Question from Google interview

2011-08-19 Thread WgpShashank
I Think Trie is suitable DS for this problem , its similar "Did You Mean" Feature of Google Paste it in ur address bar http://www.google.com/#hl=en&source=hp&q=Thatwouldbefantastic&oq=Thatwouldbefantastic&aq=f&aqi=&aql=&gs_sm=e&gs_upl=546l546l0l841l1l1l0l0l0l0l234l234l2-1l1l0&bav=on.2,or.r_gc.r_

[algogeeks] Re: Question from Google interview

2011-08-18 Thread Navneet
I have an answer to the problem which requires a single pass of string to get the output string. (Though debatable if it covers all cases) Look to make it as time efficient as possible. On Aug 19, 2:28 am, Dave wrote: > @Icy: We agree that you have to look ahead in order to set the spaces > corr

[algogeeks] Re: Question from Google interview

2011-08-18 Thread Dave
@Icy: We agree that you have to look ahead in order to set the spaces correctly. The only point of difference is whether you choose to become more greedy or less greedy when looking ahead fails. Dave On Aug 18, 2:55 pm, "icy`" wrote: > Well no, I would think it would match "Balls"  for him, sinc

[algogeeks] Re: Question from Google interview

2011-08-18 Thread icy`
Well no, I would think it would match "Balls" for him, since it is greedy --> it would try to match as much as possible that works/is in dict. So I have to agree with Aditya here, but I would go from the back/right to the left. So I would first get " round", then hopefully " are round" and fin

[algogeeks] Re: Question from Google interview

2011-08-18 Thread Dave
@Aditya: You probably have to be a bit more careful than that. You can't add the space until both the first part is a word in the dictionary and the rest of the string can also be broken into words in the dictionary. Consider "Ballsareround." Your algorithm seems to put a space after the second "l"

[algogeeks] Re: question

2011-08-07 Thread bugaboo
1) Firstly, size of the data type depends on the language. With C/C++, since they are not platform independent, size of integer varies from machine to machine. 2) With C/C++, the size depends on the underlying hardware (architecture). HardwareOSPossible --

Re: [algogeeks] Re: Question

2011-08-06 Thread saurabh singh
Always ready to help mate:) Party do ab:D On Sat, Aug 6, 2011 at 4:55 PM, UTKARSH SRIVASTAV wrote: > thnx saurabh i got ac > > > > On Sat, Aug 6, 2011 at 4:22 AM, UTKARSH SRIVASTAV > wrote: > >> MY LOGIC IS .LET AFTER N STEPS RELATION BETWEEN NUMBER OF >> ONES(1),ZEROONE(01)

[algogeeks] Re: Question

2011-08-06 Thread UTKARSH SRIVASTAV
thnx saurabh i got ac On Sat, Aug 6, 2011 at 4:22 AM, UTKARSH SRIVASTAV wrote: > MY LOGIC IS .LET AFTER N STEPS RELATION BETWEEN NUMBER OF > ONES(1),ZEROONE(01) AND DOUBLEZERO(00) IS > > INITIALLY > ONE=1 > ZEROONE=0 > DOUBLEZERO=0 > > FOR N=1 > K=ONE > L=ZEROONE > M=DOUBLEZERO > ONE

[algogeeks] Re: Question

2011-08-06 Thread UTKARSH SRIVASTAV
MY LOGIC IS .LET AFTER N STEPS RELATION BETWEEN NUMBER OF ONES(1),ZEROONE(01) AND DOUBLEZERO(00) IS INITIALLY ONE=1 ZEROONE=0 DOUBLEZERO=0 FOR N=1 K=ONE L=ZEROONE M=DOUBLEZERO ONE=K+L+M ZEROONE=K+M DOUBLEZERO=L i.e. ONE=1 ZERONE=1 DOUBLEZERO=0 FOR N=2 K=ONE L=ZEROONE M=DOUBLEZERO ON

[algogeeks] Re: Question

2011-07-29 Thread Anika Jain
i also feel the point of kiddle is ryt.. can anybody plz explain more On Jul 26, 12:18 am, SkRiPt KiDdIe wrote: > How much time does he reach home is a bad question to ask. > > Say i walk 90-x minutes before i meet my driver.If i had walked x more > minutes the driver would have reached my office

Re: [algogeeks] Re: question

2011-07-28 Thread tech rascal
lets say- if a=1 1 0 0 1 0 1 1 b=0 1 1 1 0 1 1 1 by finding xor of a & b, u will be able to find how many bits in a are reqd to be changed to get b bcoz if bits in a & b are different at any position then only u need to change( 0->1 or 1->0) else not code int bitswapreqd(int a, int b) { int c,

[algogeeks] Re: question

2011-07-28 Thread Tim Zheng
int BitFlipRequired::bitFlipRequired(int A, int B){ int count(0); int bitMask(1); A ^= B; for (unsigned int bitPosition = 0; bitPosition < sizeof(int)*8; bitPosition++){ if ((A & bitMask) != 0) count++; bitMas

[algogeeks] Re: question

2011-07-28 Thread sylvester
i just read this quetion somewhere...i dont have any idea what exactly they mean by this...so m looking for any soln that can be possible On Jul 29, 2:19 am, Tim Zheng wrote: > What's the basic operation on A allowed here to convert it to B? Just > to flip individual bit? > > On Jul 28, 2:14 

[algogeeks] Re: question

2011-07-28 Thread Tim Zheng
What's the basic operation on A allowed here to convert it to B? Just to flip individual bit? On Jul 28, 2:14 pm, sylvester wrote: > Given two integers A & B. Determine how many bits required to convert > A to B. Write a function int BitSwapReqd(int A, int B); -- You received this message becau

  1   2   >