Re: [algogeeks] Google Interview Question: In how many intervals does a number exists
2-2 as 2 lies in [2,3] and [1,4] ? On Sun, Jun 9, 2013 at 12:50 PM, Monish Gupta monish.gup...@gmail.comwrote: There are n Intervals. Given a set of m numbers, tell in how many intervals does each number exists. Example: 4 Intervals: [2,3] [3,4] [1,4] [3,10]. Numbers {2,4,11} For 2 - 1 as 2 lies only in 1 interval [2,3] For 4 - 3 as 4 lies in 3 intervals For 11 - 0 as 11 lies in none of the given 4 intervals. It can be easily done in O(m*n) by traversing n intervals for each number in the given set of m numbers. How would improve this? Note: I could not fully recall, but I have seen very similar question in codechef but could not find the same. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] stack. Mid element in o(1)
I think there is no need for such a complex code. use length() method to get the size of the stack and return the middle element i.e. m=S.length() if(m is even) return arr[m/2] else return arr[m+1/2] it can be done in O(const) time On Thu, May 23, 2013 at 12:54 PM, Avi Dullu avi.du...@gmail.com wrote: Code is here http://codebin.org/view/30e9f2c0. Logic is made clear by the variable names. Idea is similar to the one which is used to build a queue using 2 stacks. On Wed, May 22, 2013 at 8:45 AM, MAC macatad...@gmail.com wrote: I think this is only possible if you make sure that at push you store the middle element with the top element as well .. this would mean push would cease to be o(1)become o(n) .. . or is there some other trick ? Veni Vedi Slumber ! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] Question asked in Tachyon interview
main(a,b,m) 02{ 03while (~scanf(%d%d,a,b)) 04{ 05 m=0; 06 while (a) 07 { 08if (a1) 09 m+=b; 10a=1; 11b=1; 12 } 13 printf(%d\n,m); 14} 15} -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] problem with increment operator
yups...it is compiler dependent...but a logic is necessary to get it... -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] problem with increment operator
okk -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] The following problem is a variation of Tower of hanoi problem...Plz suggest on how to approach the following problem...
built a tree (not binary) where the root node is the initial configuration of pegs. For each possibility of movement of the initial configuration of disks, a child node is created. Thus, for each child node created, I check if the current configuration is the final configuration. If yes, problem was solved and we are done =). Otherwise its creates other child nodes of the current node. Note that the verification of the current configuration with the final configuration of the nodes is done by breadth-first searchhttp://en.wikipedia.org/wiki/Breadth-first_search(this is the secret of this solution to find the smallest number of moves). If u need i can give u the JAVA code for this -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] problem with increment operator
how is it 6? ++a(5) + ++a(6) + a++(6) it shud be 17 -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] probability of winning with two cards
ya obviously...it is 1/3.no need of any data is required On 1/18/12, sunny agrawal sunny816.i...@gmail.com wrote: isn't the answer will be 1/3, without any calculations :) On Thu, Jan 19, 2012 at 7:10 AM, Sundi sundi...@gmail.com wrote: there are 52 cards.. there are 3 players a1,a2,a3 each player is given 2 cards each one of A=2...J=11,Q=12,K=13..a user wins if his sum of cards is greater then the other two players sum. find the probability of a1 being the winner? -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- 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, visit this group at http://groups.google.com/group/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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: which is better?
depends on the requirement of the code... On Thu, Sep 22, 2011 at 11:00 AM, DIPANKAR DUTTA dutta.dipanka...@gmail.com wrote: Depends on compiler architecture , and how they use instruction set architecture ( Increment Op) of underlining machine On Thu, Sep 22, 2011 at 7:21 AM, Don dondod...@gmail.com wrote: If the value of the expression is not being used, ++n is preferred. Most coding standards used by big companies require the prefix operator to be used unless the pre-incremented value is required. Don On Sep 22, 7:54 am, Sahil Garg garg.sahi...@gmail.com wrote: n=n+1 n++ ++n which of the three is better ?? Sahil Garg Computer Engg. DCE -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, -- **DIPANKAR DUTTA Software Development Engineer Xen Server - OpenStack Development Team (DataCenter and Cloud) Citrix RD India Pvt Ltd 69/3, Millers Road, Bangalore – 560052 Phone: +91 8147830733 Office: Extn: 16429 Email: dipankar.du...@citrix.com -- 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, visit this group at http://groups.google.com/group/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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Find the output
Brijesh is right.until u do the type casting it will show an error On Fri, Sep 16, 2011 at 5:57 AM, Pradip Singh qnit...@gmail.com wrote: it will print 2,5 On Fri, Sep 16, 2011 at 2:35 AM, Brijesh brijeshupadhyay...@gmail.comwrote: On Friday, 16 September 2011 13:25:38 UTC+5:30, Anup wrote: #includestdio.h int main() { int a[5]={1,2,3,4,5}; int *ptr=(a + 1); int *ptr=(int *)(a + 1); printf(%d %d\n,*(a+1),*(ptr-1)); return 0; } Find the output! Now it will print 2 5 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/4tXlbiojgm8J. 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. -- 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, visit this group at http://groups.google.com/group/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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c aps
the printf function returns 1 when it prints a string.. for (1;1i--;1) { printf(bat); } note that i=2 has been cunningly initialized before. and the decrement of i has been done in middle expression of the for loop hence, actually its like for(;i--;) { } how many times will this execute? Twice.i=1 and i=2, for i=O, the middle condition shall become O and hence fails. therefore the ouput. On Sun, Jan 9, 2011 at 6:48 PM, siva viknesh sivavikne...@gmail.com wrote: #includestdio.h int main() { int i=2; for(printf(cat );printf(rat )i--;printf(mat )) { printf(bat ); } } ouput : cat rat bat mat rat bat mat rat can anybody plz explain how we get this output?? -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/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 algoge...@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.