Re: [algogeeks] Re: max sum b/w 2 leaf nodes in a binary tree

2012-08-29 Thread kunal rustgi
@navin it is not necessary that path b/w two leaves always pass thru root. On Wed, Aug 29, 2012 at 1:15 AM, Navin Gupta wrote: > I think the path between two leaves always passes thru root. > Now we can keep track of root-to-leaf path whose sum is max and secondMax > among all sums. > Now betwe

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread kunal rustgi
t; > Please correct me! > > > On Mon, Aug 27, 2012 at 11:46 PM, kunal rustgi wrote: > >> @ravi >> yep, you're right. >> >> But method is similar to finding diameter as given on geeksforgeeks as >> atul suggested . Thanks. >> >> >>

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread kunal rustgi
ce between two nodes. > > > On Sun, Aug 26, 2012 at 6:12 PM, atul anand wrote: > >> its the diameter of tree. >> you can find implementation on geeksforgeeks >> >> On 8/25/12, kunal rustgi wrote: >> > Hi, >> > >> > Can anyone suggest th

Re: [algogeeks] Re: Printing random word from file

2012-08-26 Thread Kunal Patil
Okay..missed it..thnx fr info.. Your approach is nice..it took me some time to understand your code's though.. Great answer!! On Aug 26, 2012 3:55 AM, "Dave" wrote: > @Kunal: Yes. You are missing that you don't know the number of words in > the file in advance. So, to

[algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-26 Thread kunal rustgi
Hi, Can anyone suggest the best approach for finding max sum b/w 2 leaf nodes in a binary tree ( not BST ) ? -- 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 fro

Re: [algogeeks] Re: Printing random word from file

2012-08-25 Thread Kunal Patil
How about using rand()%n ?? Like, calculate lucky_pos = rand()%n Then print word at lucky_pos th position... Am I missing anything? All words are still equiprobable to get printed right? On Aug 20, 2012 11:45 AM, "Dave" wrote: > @Navin: Okay. Here is a paraphrase. Assume double function random()

Re: [algogeeks] Spoj Domino Tiling

2012-02-10 Thread Kunal Patil
> On Thu, Feb 9, 2012 at 7:19 PM, Kunal Patil wrote: > >> I am solving spoj problem Tiling a Grid With >> Dominoes.(http://www.spoj.pl/problems/GNY07H/).. >> I am not able to come up with a recurrence relation.. >> One of my friend said it has the recurrence relation

[algogeeks] Spoj Domino Tiling

2012-02-09 Thread Kunal Patil
I am solving spoj problem Tiling a Grid With Dominoes.(http://www.spoj.pl/problems/GNY07H/).. I am not able to come up with a recurrence relation.. One of my friend said it has the recurrence relation as f(n) = f(n-1) + 5*f(n-2) + f(n-3) - f(n-4). I am not convinced and have trouble deriving this f

Re: [algogeeks] array or matrix problems...anyone?

2011-11-01 Thread Kunal Patil
@shady: There were no specific constraints. Actually, they didn't expect any best solution. People who wrote brute force also got shortlisted. Brute force would be Just picking a number one by one from first row and then checking other rows for existence of this number. I think it is a O(n^3) algor

Re: [algogeeks] Re: Directi Questions - needed answers

2011-10-28 Thread Kunal Shridhar
@Mohit Agreed. The answer is O(n). On Fri, Oct 28, 2011 at 6:48 PM, mohit verma wrote: > @ankur - Ans-9 how can it be log n. The heap given is Max heap. I think > it should be O(n) using array or tree traversal (as heap is implemented) > keeping current min at hand. Correct me if m wrong. > >

Re: [algogeeks] [SPOJ] ZSUM

2011-10-25 Thread Kunal Patil
Can you tell why (x * z * z) % MOD is different from (x * ( (z*z)%MOD) ) % MOD Again why ((x%MOD)*(z%MOD)*(z%MOD))%MOD is giving WA I thought of a simple examples like (100* 53*72) % 90 --> ((90+10)*53*72) % 90 --> (10*53*72)% 90 which is same as (100%90 * 53%90 * 72%90) % 90 Another

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-15 Thread Kunal Patil
@Sunny: Thanks for the info !! That's gr8..& your logic also seems to be working perfectly fine.. On Sat, Oct 15, 2011 at 12:16 PM, shady wrote: > u can always post the code.,... but before posting code, you must state > your algorithm > else code becomes useless for other users > > On Sat, Oc

Re: [algogeeks] another group?

2011-10-06 Thread Kunal Shridhar
Agree. On Fri, Oct 7, 2011 at 5:08 AM, Arun Vishwanathan wrote: > Hey all, > > Just a thought...since people feel strongly the urge to post only algo > related questions here, can a new group be made to post stuff related to > interviews and the questions asked for different companies?I thot it w

Re: [algogeeks] New Group For Practicing and Learning Efficient Ways of Coding

2011-10-05 Thread Kunal Patil
Great work shady...+1 I was so bored of the company interview queries on this group.. Hope to see Real algorithmic discussion on the new group. On Wed, Oct 5, 2011 at 11:27 PM, KARTHIKEYAN V.B. wrote: > +1 > > -- > You received this message because you are subscribed to the Google Groups > "Algo

Re: [algogeeks] Explain output

2011-09-29 Thread Kunal Patil
Why don't you post a code that compiles ? On Fri, Sep 30, 2011 at 12:41 AM, Brijesh wrote: > void main() > > { > void *ptr; > char *a='A'; > char *b="TAN"; > int i=50; > ptr=a; > ptr=(*char)malloc(sizeof(a)); > printf("%c",*ptr); > ptr=i; > ptr=(*int)malloc(sizeof(i)); > printf("%d",++(*ptr)); >

Re: [algogeeks] Re: Amazon OS question

2011-09-26 Thread Kunal Patil
Nice question & nice answer... :) On Tue, Sep 27, 2011 at 6:25 AM, UTKARSH SRIVASTAV wrote: > what's the algo of this question > > > On Mon, Sep 26, 2011 at 2:38 PM, vikas wrote: > >> simple graph question, >> graph is given as list , just check the dependancy >> >> On Sep 25, 6:25 pm, siva vikne

Re: [algogeeks] without using '-'

2011-09-26 Thread Kunal Yadav
@sandeep: Its simple xor. How can this be equal to difference?? -- 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

Re: [algogeeks] without using '-'

2011-09-26 Thread Kunal Yadav
onverting it to negative one >> and then adding it..its the same principle...which is used for dividing two >> numbers without using '/' and '-'...right kunal?? >> >> >> On Mon, Sep 26, 2011 at 10:38 PM, Ashima . wrote: >> >>> grt

Re: [algogeeks] without using '-'

2011-09-26 Thread Kunal Yadav
ubscribed 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. > For more options, visit this group at > http://grou

Re: [algogeeks] help nedded

2011-09-24 Thread Kunal Yadav
orithm 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. >>>> For more options, visit this group at >>>>

Re: [algogeeks] help nedded

2011-09-24 Thread Kunal Yadav
l=en. >>> >>> >> >> >> -- >> *Dheeraj Sharma* >> Comp Engg. >> NIT Kurukshetra >> >> >> > > > -- > *Dheeraj Sharma* > Comp Engg. > NIT Kurukshetra > > > -- > You received this message because you are s

Re: [algogeeks] Re: can any body explain the output and the general method

2011-09-23 Thread Kunal Yadav
oup/algogeeks?hl=en. >> > > -- > 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] output

2011-09-13 Thread Kunal Patil
@Kumar: +1 @Kumar & Rajeshwar: ExitFailure is outputted because main is expected to return something which is not done in your case. Just add return 0; at the end of main to get expected output. On Tue, Sep 13, 2011 at 11:33 PM, Ishan Aggarwal < ishan.aggarwal.1...@gmail.com> wrote: > int main()

Re: [algogeeks] C Puzzle

2011-09-12 Thread Kunal Patil
Allocate memory for pointer variables. On Mon, Sep 12, 2011 at 11:03 AM, sukran dhawan wrote: > run time error > first int * a is not assigned some address... so it will be pointing to > some garbage value > second two pointers of different types without a typecast will result in > unpredictable

Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Kunal Patil
un, Sep 11, 2011 at 4:20 PM, Ankur Garg wrote: > This solution is not in O(n) time :( > Unfortunately interviewer wants O(n) . > > > On Sun, Sep 11, 2011 at 4:01 PM, Kunal Patil wrote: > >> @Brijesh: +1 >> >> >> On Sun, Sep 11, 2011 at 2:14 PM, Brijesh w

Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Kunal Patil
@Brijesh: +1 On Sun, Sep 11, 2011 at 2:14 PM, Brijesh wrote: > This is the fastest way I can think of to do this, and it is linear to the > number of intervals there are. > > Let L be your original list of numbers and A be a hash of empty arrays > where initially A[0] = [0] > > sum = 0 > for i in

Re: [algogeeks] Re: worst case complexity

2011-09-10 Thread Kunal Patil
he O(n^5) Time complexity. :) :) On Sat, Sep 10, 2011 at 5:10 PM, Kunal Patil wrote: > @Piyush: In 2 ways I will prove you wrong. > > 1) > Lets take 2 innermost loops. > > for(j=0;j { > > for(k=0;k } > > Let i*i be m. Thus, It becomes. > > for(j=0

Re: [algogeeks] Re: worst case complexity

2011-09-10 Thread Kunal Patil
@Piyush: In 2 ways I will prove you wrong. 1) Lets take 2 innermost loops. for(j=0;j O(( i^2) ^ 2) --> O(i ^ 4) Outer loop iterates over i once till n. So, for i=0 it will run O(i^4=0) times for i=1 it will run O(i^4=1) times for i=2 it will run O(i^4=16) times for i=n it will run O(n^4) times.

Re: [algogeeks] Re: Kth largest element

2011-09-10 Thread Kunal Patil
@Dave: TC in your first case will be O(klogn + n). Transforming array into heap would be O(n). Correct me If i am wrong. -- 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 unsub

Re: [algogeeks]

2011-09-10 Thread Kunal Patil
@Piyush: +1 On Sat, Sep 10, 2011 at 1:07 AM, Piyush Grover wrote: > pseudo algo: > > =>array idx[0...k-1] indicates the current pointer position in the ith > stream(initialized to 0). > =>heap tree of size k where each node stores value of the data and value of > stream which the node belong

Re: [algogeeks] ACM

2011-09-08 Thread Kunal Patil
Cool.. If you can share/ask algorithm related programming questions.. :) In fact it is the main cause of this group. :) :) :) There are sufficient SPOJ problem discussions over here.. You can continue asking questions if you think, that particular problem needs special data handling techniques to m

Re: [algogeeks] Re:

2011-09-06 Thread Kunal Patil
@siddharam suresh: sizeof(void) is an prohibited operation. So your code would result in compile time error. On Tue, Sep 6, 2011 at 11:47 PM, siddharam suresh wrote: > my guess, > sizeof() takes only the declaration properties not the definition > properties(that means it wont call the function)

Re: [algogeeks] EOF

2011-09-06 Thread Kunal Patil
If I understand question correctly, then just read as many characters as you can using standard string functions. (like fgets n all related) Output these all characters in a file. Iterate until you have read all the characters and go on appending what you have read to file. You intended to ask some

Re: [algogeeks] Re:

2011-09-06 Thread Kunal Patil
sizeof never executes whatever expression is given as parameter. It needs only size of parameter. In this case, parameter main() returns an int type. So sizeof returns sizeof int. It doesnt need to call main() to get its task, of finding size, done. On Tue, Sep 6, 2011 at 11:41 PM, siddharam sures

Re: [algogeeks] c doubt

2011-08-31 Thread Kunal Patil
@kartik: typedef struct { int bit1:29; int bit2:4; }bit; This makes total number of bits 33, which is not on int boundry. (multiple of 32 bits) So to make it aligned on int boundry, 31 extra bits are padded at the end of bit2. This makes size of struct 29 + 4 + 31 = 64 bits --> 8 bytes. When bit1

Re: [algogeeks] Re: Zig Zag tree traversal

2011-08-28 Thread Kunal Patil
@ Kartikeyan: If you use normal queue implementation how you are going to print reverse??? (From ptr2 to ptr1)...If you are implementing queue in an array, then your solution can be feasible.. If not in array, you must modify your queue DS to include pointers to previous elements. Or you can do th

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Kunal Patil
@Dave: Still your approach to solve the problem remains correct. (subtracting a number from max possible value & then comparing this difference with another number). So, no need to think that you were brain dead (If you were, you would have posted a movie story here)..[?] Mathematically it is wrong

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Kunal Patil
@Dave: +1 for nice solution... :) On Sat, Aug 27, 2011 at 10:12 PM, Dave wrote: > @Avinash: What do you mean by "exceeding limit(already overflowed)"? > The number maxint is the limit. Every positive number is <= maxint. > > Dave > > On Aug 27, 10:31 am, "Avinash LetsUncomplicate.." 2...@gmail.

Re: [algogeeks] Google Question:Given a BST and a number, Find the closest node to that number in the BST.

2011-08-20 Thread Kunal Patil
@Abhishek: Its not always that you reach a leaf through the node. But still your logic seems correct. There would be 3 candidates for minimum: -->predecessor -->current node -->successor. On Sat, Aug 20, 2011 at 1:13 PM, Abhishek Yadav wrote: > No your solution is correct tooits just that in

Re: [algogeeks] Re: Possible solutions to these sort of Questions

2011-08-18 Thread Kunal Patil
+1 Yasir. On Wed, Aug 17, 2011 at 11:39 PM, Yasir wrote: > For questions specifically asking about test cases, I would suggest > following 3 step approach: > > First think of a* basic flow that MUST work for the application* (what is > expected with the application. Firstly make it clear with yo

Re: [algogeeks] Re: an array question

2011-08-14 Thread Kunal Patil
; whereas the answer has to be: >>> >>> 9,678,543,45,32,1 >>> and hence largest no created is 967854345321 >>> >>> I think thats the way radix sort will work... >>> >>> Correct me if i m wrong...! >>> >>> >>> O

Re: [algogeeks] Re: How to solve this problem

2011-08-14 Thread Kunal Patil
Yes..i agree with Dave..Here is what i think. As you have integers upto n^3 in your input, it would need [3*lg(n) + 1] bits to represent each integer. So take each group of r = ceil(lg(n)) bits at a time. So this becomes number of bits needed to represent single digit. Each digit thus can take 2^r

Re: [algogeeks] Re: an array question

2011-08-13 Thread Kunal Patil
d quickly. As you can see you will not always require string upto largest length to determine lexicographical order of 2 strings. I am bad at explaining things. So let me know whether this solved your doubt. On Sat, Aug 13, 2011 at 10:35 PM, aditi garg wrote: > @ kunal : arent we supposed to constr

Re: [algogeeks] Re: an array question

2011-08-13 Thread Kunal Patil
=len1 && ind2==len2) // same strings return true; //If I missed anything in the code, let me know On Sat, Aug 13, 2011 at 9:29 PM, aditi garg wrote: > @kunal: what is the best way to implement step 2? > > > On Sat, Aug 13, 2011 at 7:33 PM, Ashish Sachdeva < > ashish.asachd..

Re: [algogeeks] Re: c output doubt

2011-08-13 Thread Kunal Patil
@rohit: Cast pointer to an integer into an int to get what you are expecting. for e.g. printf("%d",(int)&a[4]-(int)&a[0]); This will give 16. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@go

Re: [algogeeks] Re: an array question

2011-08-13 Thread Kunal Patil
Following approach should work: 1) Count max number of digit in any integer of input. Let it be m. (Thanks to dave..) 2) For each int having less than m digits: Convert it to string of length m where you append circularly. For e.g. if m=5 53 --> 53535 100 --> 10010

Re: [algogeeks] Re: logic???????????

2011-08-13 Thread Kunal Patil
@Yasir: Yups...I also have the same algo... Just to improvise your solution, you need not do binary search on both sides of the pivot. Just check End points (min-max) of the both sub-array to decide which side to do a binary search..This works in the case of duplicate elements too. for e.g. 2 5

Re: [algogeeks] Re: Amazon question.

2011-08-10 Thread Kunal Patil
@Ankit: Ohh Sorry..I didnt actually read the question properly.. I didnt see we have to check for sum which must be another element in the array & not some user provided constant value..I mis-understood it with sum upto k problem which can be solved on sorted array in O(n)... thats why gave a wrong

Re: [algogeeks] Re: m'th max element

2011-08-10 Thread Kunal Patil
@Ankuj: +1 for different approach. (Though selection algo is more efficient than this.) On Wed, Aug 10, 2011 at 1:44 PM, nick wrote: > nice logic :) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web

Re: [algogeeks] Re: Amazon question.

2011-08-10 Thread Kunal Patil
@Ankit Sambyal: Agree with ankuj...TC of your solution is O(nlogn) and not O(n^2)... -- 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 t

Re: [algogeeks] Re: directi prepration

2011-08-09 Thread Kunal Yadav
send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Kunal Yadav (http://algoritmus.in/) -- You received this message because you are subscribed to the Google Groups "Algorithm

Re: [algogeeks] Directi Question

2011-08-07 Thread Kunal Patil
@Shady : No...we can say this only at the time when following constraints are satisfied: 1) *Outcome* of event *should be* *binary*. (In above example Sum can have binary outcomes only i.e. EVEN or ODD) 2) Random variable x in P(x) should be supported on set {1,2,3,4,} i.e. It *should start fr

Re: [algogeeks] Re: Probability Puzzle

2011-08-07 Thread Kunal Yadav
to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Regards Kunal Yadav (htt

Re: [algogeeks] how to reverse a string in place??plz post code also

2011-08-07 Thread Kunal Yadav
gle 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. > For more options, visit this group at > http://groups.google.com/group/alg

Re: [algogeeks] Re: probablity

2011-08-07 Thread Kunal Yadav
. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Kunal Yadav

Re: [algogeeks] Re: Directi Question

2011-08-07 Thread Kunal Patil
Probability of getting an even sum in one roll is 1/2.. Thus, expected number of rolls required to get even sum is inverse of that i.e. 2. Alternatively, Going by basics... Let P(x) be probability of getting Even sum in x rolls. P(1) = 1/2(Even) P(2) = (1/2) * (1/2) (Odd + Odd) P(3) = (1/2)

Re: [algogeeks] xplanation plz

2011-08-06 Thread Kunal Patil
@Saurabh: +1 for your second code. On Sun, Aug 7, 2011 at 12:17 PM, Amol Sharma wrote: > nice :) > -- > > > Amol Sharma > Third Year Student > Computer Science and Engineering > MNNIT Allahabad > > > > > On Sun, Aug 7, 2011 at 8:16 AM, saurabh singh wrote: > >> Yup it was due to compiler optimi

Re: [algogeeks] Directi Question

2011-08-06 Thread Kunal Yadav
tion value does > not exist. > > @Kunal: For E(2)...The running sum can be even if > (i) On the first die, we get an odd and then again an odd. > (ii) On the first die, we get an even and then again an even. > > How have you considered only a single case? > > Please correct

Re: [algogeeks] Directi Question

2011-08-06 Thread Kunal Yadav
Hey sry for my above post. I got a little confused. x is the no of times dice is rolled so e(x)=e(1)+e(2)+e(3)+ =1/2 + 2*1/(2*2) + 3*1/(2*2*2) + .. Please correct me if m wrong.. On Sat, Aug 6, 2011 at 10:54 PM, Kunal Yadav wrote: > Expected value of a random variable x is defi

Re: [algogeeks] Directi Question

2011-08-06 Thread Kunal Yadav
d 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. > For more options, visit this

Re: [algogeeks] Re: latest google interview questions

2011-08-03 Thread Kunal Patil
@Shady: +1 But I cant stop laughing.[?] Hacking some1's account and doing such hilarious posts...[?] On Wed, Aug 3, 2011 at 9:55 PM, Anil Arya wrote: > @shadythank you very much > .Good job > > > On Wed, Aug 3, 2011 at 9:48 PM, shady wrote: > >> utkarsh - banned for 2 weeks. >> >> >> On We

Re: [algogeeks] Amazon Question

2011-08-03 Thread Kunal Patil
Sort both the lists... (Keep track of their original indices as we need to return to original list) Modify the merge process of merge_sort: // Assume size of list1 is m and that of list2 is n curr_list1=0;curr_list2=0;curr_output=0; while( curr_list1 < m && curr_list2 < n ) { If (list1[curr_l

Re: [algogeeks] Re: Goldman sachs

2011-08-03 Thread Kunal Patil
I agree with Ved that Apti of GS is really really tough and technical is relatively easy..They ask CAT (Quant) like questions and you have to solve them in little time too...Also there will be sectional cut-off for this written test. So dont be afraid if you can solve only 10-15 questions from quan

Re: [algogeeks] Re: Merging K-sorted lists using Heap

2011-08-02 Thread Kunal Patil
@Kumar:Thanks for the very good question and @Dave:Thanks for very very good solution... -- 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 ema

Re: [algogeeks] Find the number of solutions.

2011-07-28 Thread Kunal Patil
x^(x^x) - (x^x)^x = 0 Thus, x^(x^x) = (x^x)^x Let's open it up by taking log on both sides... (x^x)*log(x) = x* log(x^x) (x^x)*log(x) = x*x*log(x) If x==1 equation is satisfied as log(x) becomes 0.. so x=1 is definitely a solution. what if when x != 1 cancelling log(x) on both the sides.. x^x = x^

Re: [algogeeks] Puzzle

2011-07-28 Thread Kunal Patil
Insufficient data to calculate what you need to find out !!! On Thu, Jul 28, 2011 at 9:39 PM, shubham wrote: > A man leaves his office daily at 07:00 PM. His driver arrives with the car > from home to his office at sharp 07:00 PM. So he doesn't need to wait for > any transport medium as soon he

Re: [algogeeks] Facebook Interview question at NIT Warangal

2011-07-26 Thread Kunal Patil
@Ankur Garg: Nice explanation at the link given by u... On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg wrote: > Check this > > http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html > > > On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote: > >> Here is the working code.. >> >> #i

Re: [algogeeks] Re: Shooters in a circle

2011-07-22 Thread Kunal Patil
@surender: I assume you want to give general solution to Josephus problem in which we shoot every kth person...In that case formula for pos must be: pos = ( x*k )%n + (k-1) In current context, k=2...thus the formula which you gave also holds true..but not when k != 2 -- You received this message

Re: [algogeeks] Coding..........

2011-07-22 Thread Kunal Patil
@Sunny: Excellent explanation (& solution) !! -- 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.c

Re: [algogeeks] Finding the Kth Prime

2011-07-15 Thread Kunal Patil
@Antony: To post in this group..Just login to your gmail account. Compose new mail containing your question and send it to "algogeeks@googlegroups.com " -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algo

Re: [algogeeks] Counting the ways.

2011-07-15 Thread Kunal Patil
I agree with skript: Number of ways of doing this is n! One in the first row can be placed in n ways. After one in first row has been placed, we can place One in second row in n-1 ways and so on. So total num of ways is n*(n-1)*...*1 = n! One possible solution to this problem can be coded as foll

Re: [algogeeks] array or matrix problems...anyone?

2011-07-09 Thread Kunal Patil
@My post: matrix was randomly generated 3X3 matrix...(Not any 2D matrix) On Sat, Jul 9, 2011 at 9:08 PM, Kunal Patil wrote: > I had one in my MS apti... > Given a randomly generated 2 d matrix find an element which occurs in all 3 > rows... > > > On Sat, Jul 9, 2011 at 2:

Re: [algogeeks] array or matrix problems...anyone?

2011-07-09 Thread Kunal Patil
I had one in my MS apti... Given a randomly generated 2 d matrix find an element which occurs in all 3 rows... On Sat, Jul 9, 2011 at 2:47 PM, Nitish Garg wrote: > I think Strassen Algorithm is used to multiply Matrices efficiently. Read > Cormen. > > -- > You received this message because you ar

Re: [algogeeks] Longest substring 0's & 1's

2011-07-04 Thread Kunal Patil
@Sunny : Excellent !!! Keep posting such nice solutions !! :) On Sat, Jul 2, 2011 at 1:47 AM, Anika Jain wrote: > ohh ok i got it.. thanx :) > > > On Sat, Jul 2, 2011 at 12:48 AM, sunny agrawal wrote: > >> it is (2,4] not [2,4]. >> open interval, close interval . consider (i,j] as [i+1,j

Re: [algogeeks] Implementing QUEUE with Singly link list

2011-07-04 Thread Kunal Patil
@Sandeep: Without storing explicit pointer to last element, how would you be able to access last element in a Singly Linked List in O(1) ??? Is there any parallel data structure that needs to be maintained ?? and if it is larger than size of 2 explicit pointers to last and first elements then 2 po

Re: [algogeeks] [brain teaser] What word am I

2011-06-23 Thread Kunal Yadav
egroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Kunal Yadav (http://algoritmus.in/) -- You received this message because y

Re: [algogeeks] Re: spoj NKTM

2011-06-15 Thread Kunal Yadav
group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Kunal Yada

Re: [algogeeks] Re: Print 1 to n without loops

2011-06-13 Thread Kunal Patil
@Divye Kapoor : It was interesting...use of inheritance concept to print that... On Mon, Jun 13, 2011 at 12:09 AM, Divye Kapoor wrote: > This will probably be the best solution yet ;) > > Compile time template metaprogramming: > > template > class X : public X { > public: > X() { cout << N << en

Re: [algogeeks] [brain teaser ] Probability Riddle Loaded Revolver 13 june

2011-06-13 Thread Kunal Patil
Assuming everything is unbiased: probability of the next slot to contain a bullet (given, first was empty) would be (1/4) = 0.25 After spinning: prob(bullet) = (2/6) = 0.334... We want to minimize the probability... thus answer should be just to pull the trigger again.. On Mon, Jun 13, 2011 at 1

Re: [algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-11 Thread Kunal Patil
011 at 11:39 PM, KK wrote: > It wont give correct answer when u pass same values of a and b and > such conditions arises in sorting > > > -- > *** > Kunal Kapadia > Computer Science a

Re: [algogeeks] Re: MS Interview

2011-06-10 Thread Kunal Patil
@ Dumanshu: With memory restriction also XOR method works.. :) In this case difference is just that you will be working with 400/ X number of files..where X is size of the RAM...just maintain a variable Curr_XOR_value and go on XORing it with element read from the file. When you are done wi

Re: [algogeeks] Re: Puzzle

2011-06-10 Thread Kunal Patil
@ross: seems logically correct..nice solution.. -- 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

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Kunal Patil
How about this??? * unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1< wrote: > How do you reverse the bits between j to k in a 32 bit integer. > > For e.g.: > > n = 11100011; j = 2 and k = 5 >

Re: [algogeeks] Print 1 to n without loops

2011-06-10 Thread Kunal Patil
IF allowed ??? If yes...Use recursion.. On Fri, Jun 10, 2011 at 9:12 PM, Navneet Gupta wrote: > Take n from user and print 1 to n. No loops like for/while/do-while are > allowed to use. > > --Navneet > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm

Re: [algogeeks] write an algo that deletes all negative integers without changing the order of remaining elements of the queue

2011-06-10 Thread Kunal Patil
Yups...that seems best.. :) On Fri, Jun 10, 2011 at 4:03 PM, sunny agrawal wrote: > initialy cal size of queue then apply a for loop > > > On Fri, Jun 10, 2011 at 4:00 PM, sunny agrawal wrote: > >> First algorithm taht comes in mind >> >> deque a element >> if +ve enque again >> if(-ve) do nothin

Re: [algogeeks] [brain teaser ] Find The Next Number 6 june

2011-06-08 Thread Kunal Patil
Ohh...that was a hard one...[?] On Tue, Jun 7, 2011 at 10:30 AM, shashankreddy509 < shashankreddy...@gmail.com> wrote: > http://mathworld.wolfram.com/TwinPrimes.html > > > have look at this link... > > -- > You received this message because you are s

Re: [algogeeks] Re: get rid of sohail panzer spam

2011-06-08 Thread Kunal Patil
Automatic deletion will solve the trouble only for you not for the group as such messages are not reported spam.. [?] What i do is: When i login just type in search box 'panzer'...mark all...report spam and then delete from spam box..That way they are definitely reported as spams..[?] We can't crea

Re: [algogeeks] [brain teaser ] Famous Probability puzzle SHOOT

2011-06-08 Thread Kunal Yadav
p, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Kunal Yadav (http://algoritmus.in/) -- You r

Re: [algogeeks] Stack and Permutation Problem

2011-06-05 Thread Kunal Patil
Manually calculated it to be 14.. [?] Can't think of any general formula but i think a formula or at least recursive function must be there to solve this. On Sat, Jun 4, 2011 at 1:01 PM, siva viknesh wrote: > Stack A has the entries a,b,c ( with a on the TOp) Stack B is empty. > an entry pooped

Re: [algogeeks] Microsoft ques : reverse of dutch national flag problem

2011-06-05 Thread Kunal Patil
Simple solution of order O(n^2), similar to bubble_sort, is obvious... Any improvements ??? On Sun, Jun 5, 2011 at 7:03 PM, Arunachala Karthik < arunachalakart...@gmail.com> wrote: > > What is the order of time specified in the question? > > On Thu, Jun 2, 2011 at 5:03 PM, siva viknesh wrote: > >

Re: [algogeeks] [brain teaser ] Mystery Puzzle Sherlock Holmes 26 may

2011-06-03 Thread Kunal Patil
Hahaha..nice one.. :) :) On Thu, May 26, 2011 at 9:43 PM, DeVaNsH gUpTa wrote: > Mark as it reads ?(Question Mark) Crimson. > > -- > 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.

Re: [algogeeks]

2011-06-03 Thread Kunal Patil
Go to hell u spammer..[?] -- 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. For more options

Re: [algogeeks] Array Merge Problem

2011-06-03 Thread Kunal Patil
@Ashish: your solution is not O(N). I dont think you are taking advantage of the statement "( A and B need not be sorted in the end)" @sravanreddy: excellent solution. On Thu, Jun 2, 2011 at 7:46 PM, Ashish Goel wrote: > > int i=lenA-1; > int j=lenB-1; > > while (j>=0) > { > if (A[i] >B[j]) {s

Re: [algogeeks] remove duplicate chars in a string without using extra memory

2011-06-03 Thread Kunal Patil
If you are not going to allow extra space, you have to compromise on time complexity..[?] If you dont have your string already stored in a trie/hashmap usage of it requires additional buffer. Simple solution would be: Sort given string using in-place sorting algorithm and then removal of duplicate

Re: [algogeeks] MS Question

2011-06-01 Thread Kunal Patil
@Gaurav: You might want to say circular doubly linked list, didn't you ? coz without that, its not possible to reach last node if we are at first node or vice-versa. On Thu, Jun 2, 2011 at 9:31 AM, Gaurav Aggarwal <0007gau...@gmail.com>wrote: > other solution might be to use doubly linked list, e

Re: [algogeeks] snake and ladder

2011-05-29 Thread Kunal Yadav
gle 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. > For more options, visit this group at > http://groups.google.com/group/alg

Re: [algogeeks]

2011-05-24 Thread Kunal Patil
@Piyush: I don't think 1010 (and any even number) will be a binary palindrome (Unless u allow single leading zero)...(Either you allow all or allow none) If its not so what about 1001 then ? Whether it will be a palindrome or not ?[?] Don't you think, it isn't possible to do this in less than O(n)

[algogeeks] 3 in 1 remote control

2011-05-21 Thread Kunal Patil
Not strictly an algorithmic question, rather a test-of-design-skills type of question. You are asked to design a 3-in-1 remote control for TV, a DVD player, and a cable box. How will you go with design ? In my approach it should have following buttons. 1) *Device Key* : Will represent device

Re: [algogeeks] Array problem

2011-05-19 Thread Kunal Patil
@ Piyush: Excellent Solution...It appears both Correct and O(n)...Good work !![?] Just a minor correction in your algo.[?] * while(B[i]http://groups.google.com/group/algogeeks?hl=en. <<363.gif>><<360.gif>>

Re: [algogeeks] [brain teaser ] Greater than God Riddle 18 may

2011-05-18 Thread Kunal Patil
Hahaha...Nice answer Piyush ! On Wed, May 18, 2011 at 12:44 PM, Piyush Sinha wrote: > *NOTHING*. > > *Greater than GOD - NOTHING* > *Worse than EVIL - NOTHING* > *Poor have it and rich want it - NOTHING* > *if you eat it, you die - NOTHING > * > On Wed, May 18, 2011 at 12:35 PM, Lavesh Rawat

  1   2   >