[algogeeks] Facebook Interview Question
There are K pegs. Each peg can hold discs in decreasing order of radius when looked from bottom to top of the peg. There are N discs which have radius 1 to N; Given the initial configuration of the pegs and the final configuration of the pegs, output the moves required to transform from the initial to final configuration. You are required to do the transformations in minimal number of moves. A move consists of picking the topmost disc of any one of the pegs and placing it on top of anyother peg. At anypoint of time, the decreasing radius property of all the pegs must be maintained. Constraints: 1= N=8 3= K=5 Input Format: N K 2nd line contains N integers. Each integer in the second line is in the range 1 to K where the i-th integer denotes the peg to which disc of radius i is present in the initial configuration. 3rd line denotes the final configuration in a format similar to the initial configuration. Output Format: The first line contains M - The minimal number of moves required to complete the transformation. The following M lines describe a move, by a peg number to pick from and a peg number to place on. If there are more than one solutions, it's sufficient to output any one of them. You can assume, there is always a solution with less than 7 moves and the initial confirguration will not be same as the final one. Sample Input #00: 2 3 1 1 2 2 Sample Output #00: 3 1 3 1 2 3 2 Sample Input #01: 6 4 4 2 4 3 1 1 1 1 1 1 1 1 Sample Output #01: 5 3 1 4 3 4 1 2 1 3 1 -- *Regards* Mahendra Pratap Singh Sengar B-tech 4/4 NIT Warangal. Facebook ID http://www.facebook.com/mkingmahi -- 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: Directi Interview Ques
@naveen : 3*7+2*9+1*3 =42 is not maximum.. sum of the product would me maximum wen, i guess, most weighted elements are adjacent like in this case if c={1,2,3,3,7,9} 1*2 + 3*3 + 7*9=74 (maximum ) thus this question is just merging both strings such resultant (here C) is in sorted order which can be easily done in nlogn . On Sat, Jul 14, 2012 at 2:15 PM, Navin Gupta navin.nit...@gmail.com wrote: As the final array contains element in stable-order, at any time we have 3 options for choosing the elements from A B. 1- A[i] A[i+1] 2- A[i] B[I] 3- B[i] B[i+1] we will choose that pair whose product is maximum. For ex:- A-2,1,3 B-3,7,9 C- 3,7,2,9,1,3 Its a linear time solution with constant time complexity. Algo :- 1 - Keep two indexes i=0 and j=0 pointing to arrays A B respectively and k=0 for array C. 2 - Now , check the maximum of (a[i]*a[i+1], a[i]*b[j], b[j]*b[j+1] ). 3 - If a[i]*a[i+1] is maximum, add a[i],a[i+1] to C, i+=2. 4 - If a[i]*b[j] is maximum, add a[i],b[j] to C, i++,j++. 5 - If b[j]*b[j+1] is maximum, add b[j],b[j+1] to C, j+=2. 6 - k+=2. 7 - If i,j reached end, then break else Goto step 2. Time Complexity :- O(n) Space Complexity :- O(1) -- 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/-/6-JIwC7l-hYJ. 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* Mahendra Pratap Singh Sengar B-tech 4/4 NIT Warangal. Facebook ID http://www.facebook.com/mkingmahi -- 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 peak element in log(n)
@adarsh :its nt dat easy as u see it.. On Sun, Jun 24, 2012 at 1:45 AM, Sourabh Singh singhsourab...@gmail.comwrote: @adarsh kumar are u sure it's worst case will be O (log n) ?? i think iff array is fully sorted O(n) will be required to say NO such element present On Sat, Jun 23, 2012 at 1:11 PM, adarsh kumar algog...@gmail.com wrote: This is a variation of binary search, the difference being that we have to search for an element that is greater than its immediate left one and lesser than its immediate right one. Just implement binary search with these additional constraints, thereby giving O(log n). In case of any difficulty/error, let me know. On Sun, Jun 24, 2012 at 1:27 AM, Hassan Monfared hmonfa...@gmail.com wrote: Given an array of integers find a peak element of array in log(n) time. for example if A={3,4,6,5,10} then peak element is 6 ( 65 64 ). Regards. -- 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/-/AQI6ahWgyOIJ. 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. -- *Regards* Mahendra Pratap Singh Sengar B-tech 4/4 NIT Warangal. Facebook ID http://www.facebook.com/mkingmahi -- 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] Please explain
sry i got confused its 3 then 2 then 1. i thought its 321 On Thu, Jun 14, 2012 at 2:13 PM, Mahendra Sengar sengar.m...@gmail.comwrote: main() { static i=3; printf(%d,i--); return i0 ? main():0; } the above code gives output 321 Please Explain how? -- 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/-/G-wUarnLpbEJ. 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: Can anyone explain this strange behavior ?
Nope ,the output is correct.as I had studied somewhere ,i don't remember where exactly but in (x||y) type condition's,if x evaluates to true( non zero) then value of y doesn't matter and is not evaluated and condition turns out to be true anyhow without even checking y ,control never goes to y and y is never executed; now in your case m=++i || ++j ++k; since precedence of is more than or,so we can take it as m=++i || (++j ++k); now expression evaluates to true just by checking i++ which is -2 now(non zero) and value of ++j ++k is not even checked nor changed ,hence both j and k remain unchanged. This is a correct explanation u can rely an this. thank you :) On Tue, Jun 12, 2012 at 2:19 AM, Dave dave_and_da...@juno.com wrote: This is the result of short-circuit evaluation. See, e.g., http://en.wikipedia.org/wiki/Short-circuit_evaluation, or this topic in your language reference. Dave On Monday, June 11, 2012 2:28:52 PM UTC-5, ((** VICKY **)) wrote: #includestdio.hint main(){int i,j,k,m,l; i=-3; j=2; k=0;m=++i || ++j ++k ;printf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(\n%d %d %d %d,i,j,k,m);return 0;} o/p: -2 2 0 1 k should be 1 right -- Cheers, Vicky -- 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/-/8PoAya7NqjYJ. 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: wrong output of C program
@naveen :read the his doubt properly...he was expecting 5 10 15 but was getting 8 32 96...and dats the correction required which i made On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar algorithm.i...@gmail.comwrote: @Mahendra: for ur above code with t=(a2)+a o/p will be 5,10, 15 as i explained above. without bracket answer will be 8 , 32 and 96 because + precedence is higher than . On Fri, Jun 8, 2012 at 7:31 AM, Mahendra Sengar sengar.m...@gmail.comwrote: Cracked it...i guess precedence of + is more than so use t=(a2)+a; I checked, its giving proper output now !!! On Friday, June 8, 2012 5:46:09 AM UTC+5:30, algo lover wrote: The following is a simple C program which tries to multiply an integer by 5 using the bitwise operations. But it doesn't do so. Explain the reason for the wrong behavior of the program. #include stdio.h #define PrintInt(expr) printf(%s : %d\n,#expr,(expr)) *int* FiveTimes(*int* a) { *int* t; t *=* a**2 *+* a; *return* t; } *int* main() { *int* a *=* 1, b *=* 2,c *=* 3; PrintInt(FiveTimes(a)); PrintInt(FiveTimes(b)); PrintInt(FiveTimes(c)); *return* 0; } -- 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/-/7CNEyeGuUzEJ. 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] If any one have algorithms for interviews by adnan aziz ebook... Please mail ...
http://users.ece.utexas.edu/~adnan/afi-samples.pdf is dis wat u al r lukin 4?? On Thu, Jun 7, 2012 at 3:01 PM, Abhishek Sharma abhi120...@gmail.comwrote: yes,it is helpful,but read it only if u have fully understood Introduction to algorithms or if u have strong foundation of algorithms/data structures On Thu, Jun 7, 2012 at 12:37 PM, BUBUN SHEKHAR dce.stu...@gmail.comwrote: Guys is this book useful for cracking interviews?? On Mon, Jun 4, 2012 at 1:31 AM, Dhaval Moliya moliyadha...@gmail.comwrote: If any one have algorithms for interviews by adnan aziz ebook... Please mail ... Thanks -- 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. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- 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] wrong output of C program
Good Question ,eagerly waiting for some good explanation to this one !!! On Fri, Jun 8, 2012 at 5:46 AM, Mad Coder imamadco...@gmail.com wrote: The following is a simple C program which tries to multiply an integer by 5 using the bitwise operations. But it doesn't do so. Explain the reason for the wrong behavior of the program. #include stdio.h #define PrintInt(expr) printf(%s : %d\n,#expr,(expr)) *int* FiveTimes(*int* a) { *int* t; t *=* a**2 *+* a; *return* t; } *int* main() { *int* a *=* 1, b *=* 2,c *=* 3; PrintInt(FiveTimes(a)); PrintInt(FiveTimes(b)); PrintInt(FiveTimes(c)); *return* 0; } -- 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] Simple Question ,Find Error
Answer: Compiler error: Lvalue required in function main This was the answer given along with the question..pls explain !! On Mon, Jun 4, 2012 at 10:04 PM, abhishek zeal.gosw...@gmail.com wrote: This code have issue. names[3]=names[4]; names[4]=t; -Original Message- From: algogeeks@googlegroups.com [mailto:algogeeks@googlegroups.com] On Behalf Of mahendra sengar Sent: Monday, June 04, 2012 4:13 AM To: Algorithm Geeks Cc: sengar.m...@gmail.com Subject: [algogeeks] Simple Question ,Find Error main() { static char names[5][20]={pascal,ada,cobol,fortran,perl}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i=4;i++) printf(%s,names[i]); } -- 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. -- 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.