Re: [algogeeks] Re: microsoft paper that i wrote today..

2011-08-12 Thread Neeraj Gupta
Ques 5 might be value of 1+2+'4' https://ideone.com/8b91t Obviously if we use , then it represents string and we can't define + operation with other operand being an integer. On Fri, Aug 12, 2011 at 11:06 PM, Anil Arya anilarya...@gmail.com wrote: Q.5 . [warning] initialization makes

Re: [algogeeks] o/p

2011-08-08 Thread Neeraj Gupta
Precedence of + is higher than ? On Mon, Aug 8, 2011 at 3:27 PM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: #include stdio.h #define max(a,b)(ab)?a:b int main() { int m,n; m=3+max(2,3); n=2*max(3,2); printf(%d,%d,m,n); getchar(); return 0; } y the o/p is

Re: [algogeeks] mcq

2011-08-08 Thread Neeraj Gupta
As it's given that array is searched using BS, then it's quite obvious that they are sorted. Also, if that's not the case, then the complexity will be O(N/P log(N/P)) for sorting and O(Log(N/P)) for search. Not given as an option. On Mon, Aug 8, 2011 at 5:09 PM, Kamakshii Aggarwal

Re: [algogeeks]

2011-07-30 Thread Neeraj Gupta
Create a balance BST. Maintain counter. Whenever You hit duplicate increase the counter while inserting. O(nlogn) for creating it and O(N) space. Now while traverse the array. If you find the element, then print it acco the counter value. After printing delete it. if not found continue traversing.

Re: [algogeeks] Re: Array doubt

2011-07-30 Thread Neeraj Gupta
Create a balance BST. Maintain counter. Whenever You hit duplicate increase the counter while inserting. O(nlogn) for creating it and O(N) space. Now while traverse the array. If you find the element, then print it acco the counter value. After printing delete it. if not found continue traversing.

Re: [algogeeks] Output Help.

2011-07-30 Thread Neeraj Gupta
Yes, it's UB. For such ques, try to run it on ideone. It will give a warning if any operation is not standard. http://ideone.com/bJBGl http://ideone.com/bJBGl On Sun, Jul 31, 2011 at 1:38 AM, aditi garg aditi.garg.6...@gmail.comwrote: it would be undefined... On Sun, Jul 31, 2011 at 1:34

Re: [algogeeks] Re: Array doubt

2011-07-30 Thread Neeraj Gupta
Yes, i agree, it will increase the code complexity only. you can just set the counter to -ve value only. On Sun, Jul 31, 2011 at 1:38 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: @neeraj:deleting after printing will adds to complexity.. On Sun, Jul 31, 2011 at 1:34 AM, Neeraj Gupta

Re: [algogeeks] size of self referential structure

2011-07-26 Thread Neeraj Gupta
28.? int a- 4 Five array of pointer to char 20( each pointer of 4 bytes) struct node * 4 bytes. On Tue, Jul 26, 2011 at 6:10 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: #includestdio.h #includestddef.h struct node{ int a; char *b[5]; struct node *link; };

Re: [algogeeks] C doubt!

2011-07-25 Thread Neeraj Gupta
On Tue, Jul 26, 2011 at 1:43 AM, Nitish Garg nitishgarg1...@gmail.comwrote: This following code produces output as 8 4 4. 8 is fine, as the size of an int plus a pointer is 8, but why the size of p and q is being shown as 4? #includestdio.h#includestdlib.hint main(){ struct node

Re: [algogeeks] Re: Microsoft Question!

2011-07-21 Thread Neeraj Gupta
Ankit's Solution is actually based on the assumption that we will only reverse bits till MSB which is set. So, for 0100 It will reverse will 100, so the answer should be one. On 7/21/11, aditi garg aditi.garg.6...@gmail.com wrote: i have tried solving so many tyms bt i dnt think dis also is

Re: [algogeeks] Re: Microsoft Question!

2011-07-21 Thread Neeraj Gupta
Yes, that's correct what is wrong with that? Basically when n1 occurs, it kind of initiates the multiplication by m by setting m+=1. So, After that, m gets multiplied by 2 which is nothing but left shift by 1. n=100 m remains 0 as n1==0 so m=0; n- 10; 2. n=10 m*2- m=0; n1=0 so m=0; n-1; 3 n=1;

Re: [algogeeks] Some basic bit fiddling

2011-07-18 Thread Neeraj Gupta
UB. http://ideone.com/Dwof8 On Tue, Jul 19, 2011 at 12:26 AM, Ankur Khurana ankur.kkhur...@gmail.comwrote: please try this cout(134); // gives output 0 int i=1; i=i34; couti ; //gives 4 as out put , why ? -- Ankur Khurana Computer Science , 4th year Netaji Subhas Institute Of

[algogeeks] Problem: Longest Increasing Seq code

2011-07-15 Thread Neeraj Gupta
Hi, Can anyone help me in understanding the following code http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence.cpp I am not able to understand what is the exact purpose of vector p in the above mentioned code. A little detail explanation will be helpful. ~Neeraj -- You

[algogeeks] Re: Problem: Longest Increasing Seq code

2011-07-15 Thread Neeraj Gupta
Hi Can anyone help me in understanding the following code http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence.cpp I am not able to understand what is the exact purpose of vector p in the above mentioned code. A little detail explanation will be helpful. I have already

Re: [algogeeks] microsoft ques

2011-07-13 Thread Neeraj Gupta
Oppalis algo- Please let me know if there is a bug in it. http://www.ideone.com/u1m07 On Wed, Jul 13, 2011 at 11:36 AM, Aniket Dutta aniketdutt...@gmail.comwrote: @sunny: right thanks for correcting On Wed, Jul 13, 2011 at 11:33 AM, sunny agrawal sunny816.i...@gmail.comwrote: @Aniket

Re: [algogeeks] Re: questions related to C

2011-07-12 Thread Neeraj Gupta
http://www.cplusplus.com/reference/algorithm/swap/ On Wed, Jul 13, 2011 at 10:40 AM, Aniket Dutta aniketdutt...@gmail.comwrote: what about a generic swap function which works for structures also? On Wed, Jul 13, 2011 at 2:23 AM, Don dondod...@gmail.com wrote: To check for overflow, use

Re: [algogeeks] Re: Amazon interview Question (Array yet again!)

2010-08-28 Thread Neeraj Gupta
On Sun, Aug 29, 2010 at 1:35 AM, Gene gene.ress...@gmail.com wrote: My algorithm proposal wasn't correct, but I can't see how to get 8. You need to decrement 14, 15, 16, 13 to 11. This costs 14. So do I. May be he has not noticed that incrementing a number is not an option. ;) On Aug 28,