Re: [algogeeks] [brain teaser] Sequence Puzzle 13april
next row: 3 1 2 2 1 1 just read the previous row: THREE 1 TWO 2 ONE 1 Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Wed, Apr 13, 2011 at 3:27 PM, vaibhav shukla vaibhav200...@gmail.comwrote: On Wed, Apr 13, 2011 at 1:02 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: * Sequence Puzzle * * * *The below is a number puzzle. It should be read left to right, top to bottom. Question 1 What is the next two rows of numbers. Question 2 How was this reached. 1 1 2 1 1 2 1 1 1 1 1 2 2 1* next two rows: *3 1 2 2 1 1 1 3 1 1 2 2 2 1 * *Update Your Answers at* : Click Herehttp://dailybrainteaser.blogspot.com/2011/04/sequence-puzzle-13april.html?lavesh=lavesh Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe 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. -- best wishes!! Vaibhav Shukla DU-MCA -- 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: [brain teaser] Sequence Puzzle 13april
@AKS: sure! See, first row is 1 1 We can clearly see that there are 2 ones in this row, so we read it aloud like TWO ONE. which id our next row: 2 1 Now we read this row as: ONE TWO ONE ONE (1 2 1 1) and so on... On 4/13/11, AKS abhijeet.k.s...@gmail.com wrote: @Akash : how , can u explain a bit more clearly ?? On Apr 13, 3:27 pm, Akash Agrawal akash.agrawa...@gmail.com wrote: next row: 3 1 2 2 1 1 just read the previous row: THREE 1 TWO 2 ONE 1 Regards, Akash Agrawalhttp://tech-queries.blogspot.com/ On Wed, Apr 13, 2011 at 3:27 PM, vaibhav shukla vaibhav200...@gmail.comwrote: On Wed, Apr 13, 2011 at 1:02 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: * Sequence Puzzle * * * *The below is a number puzzle. It should be read left to right, top to bottom. Question 1 What is the next two rows of numbers. Question 2 How was this reached. 1 1 2 1 1 2 1 1 1 1 1 2 2 1* next two rows: *3 1 2 2 1 1 1 3 1 1 2 2 2 1 * *Update Your Answers at* : Click Herehttp://dailybrainteaser.blogspot.com/2011/04/sequence-puzzle-13april Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe 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. -- best wishes!! Vaibhav Shukla DU-MCA -- 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, Akash Agrawal http://tech-queries.blogspot.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.
[algogeeks] Sort array with two subparts sorted
Given an array with two subparts sorted. How will you make a final sorted array. i/p: 1, 5, 7, 9, 11, 23, 2, 3, 8, 9, 21 o/p: 1, 2, 3, 5, 7, 8, 9, 9, 11, 21, 23 Regards, Akash Agrawal http://tech-queries.blogspot.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.
Re: [algogeeks] Sort array with two subparts sorted
This is obvious solution what if u have contant space? Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Tue, Apr 12, 2011 at 3:48 PM, rajul jain rajuljain...@gmail.com wrote: use merge sort On Tue, Apr 12, 2011 at 3:07 PM, Akash Agrawal akash.agrawa...@gmail.comwrote: Given an array with two subparts sorted. How will you make a final sorted array. i/p: 1, 5, 7, 9, 11, 23, 2, 3, 8, 9, 21 o/p: 1, 2, 3, 5, 7, 8, 9, 9, 11, 21, 23 Regards, Akash Agrawal http://tech-queries.blogspot.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. -- 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: Sort array with two subparts sorted
since we are bubbling up, it's again is a O(n^2). Is there anything possible like O(n) in constant space. I tried on swapping values but mees it somewhere... here are intermediate steps in my approach. 1, 5, 7, 9, 11, 2, 3, 8, 9, 21 1, 2, 7, 9, 11, *5*, 3, 8, 9, 21 1, 2, 3, 9, 11, *5, 7*, 8, 9, 21 1, 2, 3, 5, 11, 9, 7, 8, 9, 21 1, 2, 3, 5, 7, 9, 11, 8, 9, 21 1, 2, 3, 5, 7, 8, 11, 9, 9, 21 1, 2, 3, 5, 7, 8, 9, 11, 9, 21 1, 2, 3, 5, 7, 8, 9, 9, 11, 21 Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Tue, Apr 12, 2011 at 10:23 PM, powerideas arpitbhatnagarm...@gmail.comwrote: say we hav array {101,102,103,104(ptr1),1,2,3,4(ptr2)} 1.take end of 1 st array in ptr1end of 2nd array in ptr2 2.IF (ptr1ptr2) bubble up ptr1 to ptr2; ptr2-- ptr1-- ELSE ptr2--; 1.compare last element of both arrays ie 104 4 since 1044 bubble up 104 to end since it will be greater than whole 2 nd array so {101,102,103(ptr1),1,2,3,4(ptr2),104} moving on ex 2 : {1,3,5,7(ptr1),2,4,6,8(ptr2)} 78 so ptr2-- {1,3,5,7(pr1),2,4,6(ptr2), 8} {1,3,5(ptr1),2,4,6(ptr2),7,8} moving on.. -- 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] [brain teaser ] 6april
throw opposite to gravity... Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Wed, Apr 6, 2011 at 1:26 PM, balaji a peshwa.bal...@gmail.com wrote: when u throw it above u. On Wed, Apr 6, 2011 at 1:16 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: * The Ball Puzzle *How can you throw a ball as hard as you can and have it come back to you, even if it doesn't bounce off anything? There is nothing attached to it, and no one else catches or throws it back to you. Update Your Answers at : Click Herehttp://dailybrainteaser.blogspot.com/2011/04/6april.html?lavesh=lavesh Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe 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. -- A.Balaji -- 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] [brain teaser ] 5april
14 Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Tue, Apr 5, 2011 at 1:17 PM, DeboJeet Choudhury wildrahul.on...@gmail.com wrote: 34 roses @ the begining... On Tue, Apr 5, 2011 at 1:11 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *Roses Puzzle Solution* * *I have a number of roses for sale. The first buyer bought half of my roses then I gave him additional one for free. The second buyer bought half of the remaining roses then I gave him additional one also for free. The third buyer also bought half of the remaining roses then I gave him additional one also for free, this time all of my roses has been sold out. How many roses do I have? *Update Your Answers at *: Click Herehttp://dailybrainteaser.blogspot.com/2011/04/5april.html?lavesh=lavesh Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe 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. -- *Wishing you success in your endeavors * -- 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] [brain teaser ] 28march
7 races... Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Mon, Mar 28, 2011 at 3:50 PM, anand karthik anandkarthik@gmail.comwrote: Evertime you conduct a race, you eliminate 2 horses. So, 11. On Mar 28, 2011 1:24 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: *Horse Race Problem Solution* * *Ok, so there are 25 horses and the race track only allows 5 horses to race at a given time. Given that there is no stop watch available your task is to determine the fastest 3 horses. Assume that each horses speed is constant in different races, what is the minimum number of races to determine the fastest 3? Update Your Answers at : Click Here http://dailybrainteaser.blogspot.com/2011/03/28march.html?lavesh=lavesh Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe 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. -- 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: Find the first K smallest element from 1 million sized array ...Amazon Question..
http://tech-queries.blogspot.com/2009/05/find-largest-20-elements-from-billions.html Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Tue, Mar 22, 2011 at 10:13 AM, Rajeev Kumar rajeevprasa...@gmail.comwrote: http://flexaired.blogspot.com/2011/03/big-file-containing-billions-of-numbers.html On Mon, Mar 21, 2011 at 4:05 AM, Natansh Verma natansh.ve...@gmail.comwrote: @dave -was this a constraint since the beginning? In case it was, I am sorry I didn't notice. In that case, the heap method ought to work better. I dont think the quicksort method will work. Sent from my iPhone On 20-Mar-2011, at 23:00, Dave dave_and_da...@juno.com wrote: @Natansh: How do you do this with the constraint that your RAM is so small that you cannot accomodate all of the numbers at once? Dave On Mar 20, 9:04 am, Natansh Verma natansh.ve...@gmail.com wrote: There's another way... use the partitioning method for quicksort to find the k smallest elements. Then it should take expected time as O(n + klogk). Plus, it is in-place. On Wed, Mar 16, 2011 at 7:26 PM, asit lipu...@gmail.com wrote: I agree with munna -- 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.- Hide quoted text - - Show quoted text - -- 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. -- Thank You Rajeev Kumar -- 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] [brain teaser ] 14march
shadow... Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Mon, Mar 14, 2011 at 1:57 PM, Praveen praveen200...@gmail.com wrote: Wood On Mon, Mar 14, 2011 at 1:45 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: * Riddle Problem Solution* ** * *The part of the bird that is not in the sky, which can swim in the ocean and always stay dry. *Update Your Answers at *: Click Herehttp://dailybrainteaser.blogspot.com/2011/03/14march.html Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe 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. -- B. Praveen -- 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: Maximize the Time to see TV
U can always have a trackback array as we do in LIS. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Fri, Mar 4, 2011 at 5:48 PM, Vipin Agrawal vipin.iitr@gmail.comwrote: Solution is good, but its says only Max time that he can spend. How would he know that which program he should watch for Maximum utilization ? On Mar 4, 4:38 pm, Akash Agrawal akash.agrawa...@gmail.com wrote: http://tech-queries.blogspot.com/2011/03/avid-tv-watcher.html Regards, Akash Agrawalhttp://tech-queries.blogspot.com/ On Fri, Mar 4, 2011 at 2:25 PM, Akash Agrawal akash.agrawa...@gmail.com wrote: Example: Channel 1: Program id P1 P2 P3 Start time 8:00 9:00 10:30 End time 8:30 10:00 11:30 Channel 2: Program id P4 P5 P6 Start time 8:15 9:30 10:45 End time 9:15 10:15 11:15 Sort all programs based on their end time: Cnt 0 0 0 0 0 0 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 1st Iteration: Cnt 00:30 0 0 0 0 0 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 2nd Iteration: Cnt 00:30 01:00 0 0 0 0 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 3rd Iteration: Cnt 00:30 01:00 01:30 0 0 0 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 4th Iteration: Cnt 00:30 01:00 01:30 01:45 0 0 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 5th Iteration: Cnt 00:30 01:00 01:30 01:45 02:30 0 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 6th Iteration: Cnt 00:30 01:00 01:30 01:45 02:30 02:45 Pr id P1 P4 P2 P5 P6 P3 St time 8:00 8:15 9:00 9:30 10:45 10:30 End time 8:30 9:15 10:00 10:15 11:30 11:30 Answer will be 2:45 hrs as this is the biggest value in Cnt. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Fri, Mar 4, 2011 at 2:17 PM, Akash Agrawal akash.agrawa...@gmail.comwrote: Seems, it didn't preserve indentation. attached file. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Fri, Mar 4, 2011 at 2:16 PM, Akash Agrawal akash.agrawa...@gmail.comwrote: First try urself with thinking longest common subsequence if u r still not able to see below algo. I will write a blog post soon for the same. Funda is to see what is the max time I can spend on TV if I watch program X. 1. Merge all the programs of diff channels in sorted order of their end-time in prog[] array. (need O(nlogk)) 2. n ← length(prog) - 1 3. for i ← 1 to n a. do prog[i].cnt ← 0 b. max ← 0 c. j ← 0 d. while prog[j].end prog[i].start i. if max prog[j].cnt 1. do max ← proj[j].cnt ii. j ← j + 1 e. do prog[i].cnt ← max + prog[i].end – prog[i].start 4. do res ← 0 5. for i ← 1 to n a. if res prog[i].cnt i. do res ←prog[i].cnt 6. return res PS: Hope it saved indentation. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Tue, Feb 1, 2011 at 2:46 PM, Vikas Kumar dev.vika...@gmail.com wrote: @Snehal just a hint: there is no need of that channel 1 channel 2. just treat each program as independent program. On Mon, Jan 31, 2011 at 10:44 PM, snehal jain learner@gmail.comwrote: or provide some link On Mon, Jan 31, 2011 at 10:44 PM, snehal jain learner@gmail.comwrote: @ juver++ can you please share
Re: [algogeeks] Re: DP Problem: minimum Cost
Hi, Can u please explain. I couldn't get what do u mean by after processing K bundles? I wrote following code (which is inefficient) which is goving correct result for 140. But how to get the value 1400. #includeiostream using namespace std; //#define MAX 0x7FFF int main() { int weight[] = {8, 20, 70, 130}; int cost[] = {1025, 325, 475, 1050}; int ans[10]; for (int i=1; i 1; i++) ans[i] = 21474836; ans[0] = 0; int i; cout ans[1250] endl; for (i=1; i10; i++) { for (int j=0; j4; j++) { if((i-weight[j]) = 0) { int cos = ans[i-weight[j]] + cost[j]; if (cos ans[i]) { ans[i] = cos; // cout ans[i]iendl; } } } if (i=140 ans[i] INT_MAX) break; } cout ans[i] i endl; return 0; } Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Thu, Dec 30, 2010 at 6:03 PM, juver++ avpostni...@gmail.com wrote: DP[K][N] - minimal cost choosing N balls and after processing K bundles. -- 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.
Re: [algogeeks] Re: Strings search problem
http://tech-queries.blogspot.com/2010/12/finding-minimum-window-in-array-which.html just use words in place of chars... Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Fri, Dec 31, 2010 at 11:00 AM, Davin dkthar...@googlemail.com wrote: Find the area with less distance between words. Distance is measured words count in between two words. On Dec 30, 4:08 pm, 周翔 csepark...@gmail.com wrote: Distance is measured on number of words. what is your meaning ? can you explain it? 2010/12/29 Davin dkthar...@googlemail.com Given set of words, find an area of the text where these words are as close to each other as possible. Distance is measured on number of words. e.g. for words [rat”, “jat”, “pat”] and text “rat stop the pat blah blah jat by pat jat tra la la” such area is “cat by mat bat” -- 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 algogeeks%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.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.
[algogeeks] DP Problem: minimum Cost
You have different bundles of balls, which have different number of balls and different price tags. You have unlimited supplies of each of these bundles. Now if I want to get x number of balls, how should I choose bundles which cost me minimum. I am just looking for cost to be minimum, doesn't matter if I get more balls than x. But number of balls should not be less than x. Example: Bundle 1 Cost: 1050 no of balls: 130 Bundle 2 Cost: 475 no of balls: 70 Bundle 3 Cost: 325 no of balls: 20 Bundle 4 Cost: 1025 no of balls: 8 So if I want 125 balls, I will choose 2 packets of 70 balls each to minimize cost. Regards, Akash Agrawal http://tech-queries.blogspot.com/ -- 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.
Re: [algogeeks] Re: Pythagorean triples
http://tech-queries.blogspot.com/2010/12/find-pythagorean-triples-in-unsorted.html Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Mon, Dec 20, 2010 at 8:12 PM, Dave dave_and_da...@juno.com wrote: Unless sorting the array is forbidden, sort it and then use the obvious O(n^2) algorithm. This can be done with only O(1) extra space. If O(n) extra space is available, either use it to copy and sort the original array, or use it as a hash table, again achieving O(n^2) in either case. If sorting is forbidden and using extra space is forbidden, then I doubt that any algorithm less than O(n^3) exists. Dave On Dec 20, 4:41 am, bittu shashank7andr...@gmail.com wrote: can we find Pythagorean triples in an unsorted array in write program so that have minimum time complexity. regards Shashank -- 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.
Re: [algogeeks] Re: Amazon Question
2D matrix sum is a simple DP problem, but U need n*n extra space as well or have to change the i/p. (u can get the i/p back once if required) If this is acceptable, let me explain. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Sun, Dec 19, 2010 at 7:01 PM, juver++ avpostni...@gmail.com wrote: There is a linear solution in terms of the matrix's size. So in a whole it has O(n^2) time complexity. -- 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.
Re: [algogeeks] DP problem
Hey Amir, Can u please throw some more light on this. I am not able to find a good solution for subset sum problem as well. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Fri, Dec 17, 2010 at 7:29 PM, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: sort jewelries in decreasing order and then the problem can be solved in a way similar to subset sum problem On Mon, Dec 13, 2010 at 7:40 PM, Akash Agrawal akash.agrawa...@gmail.comwrote: You have been given a list of jewelry items that must be split amongst two people: Frank and Bob. Frank likes very expensive jewelry. Bob doesn't care how expensive the jewelry is, as long as he gets a lot of jewelry. Based on these criteria you have devised the following policy: 1) Each piece of jewelry given to Frank must be valued greater than or equal to each piece of jewelry given to Bob. In other words, Frank's least expensive piece of jewelry must be valued greater than or equal to Bob's most expensive piece of jewelry. 2) The total value of the jewelry given to Frank must exactly equal the total value of the jewelry given to Bob. 3) There can be pieces of jewelry given to neither Bob nor Frank. 4) Frank and Bob must each get at least 1 piece of jewelry. Given the value of each piece, you will determine the number of different ways you can allocate the jewelry to Bob and Frank following the above policy. For example: values = {1,2,5,3,4,5} Valid allocations are: BobFrank 1,2 3 1,3 4 1,4 5 (first 5) 1,4 5 (second 5) 2,3 5 (first 5) 2,3 5 (second 5)5 (first 5) 5 (second 5) 5 (second 5) 5 (first 5) 1,2,3,45,5Note that each '5' is a different piece of jewelry and needs to be accounted for separately. There are 9 legal ways of allocating the jewelry to Bob and Frank given the policy, so your method would return 9. Regards, Akash Agrawal http://tech-queries.blogspot.com/ -- 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.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.
[algogeeks] DP problem
You have been given a list of jewelry items that must be split amongst two people: Frank and Bob. Frank likes very expensive jewelry. Bob doesn't care how expensive the jewelry is, as long as he gets a lot of jewelry. Based on these criteria you have devised the following policy: 1) Each piece of jewelry given to Frank must be valued greater than or equal to each piece of jewelry given to Bob. In other words, Frank's least expensive piece of jewelry must be valued greater than or equal to Bob's most expensive piece of jewelry. 2) The total value of the jewelry given to Frank must exactly equal the total value of the jewelry given to Bob. 3) There can be pieces of jewelry given to neither Bob nor Frank. 4) Frank and Bob must each get at least 1 piece of jewelry. Given the value of each piece, you will determine the number of different ways you can allocate the jewelry to Bob and Frank following the above policy. For example: values = {1,2,5,3,4,5} Valid allocations are: BobFrank 1,2 3 1,3 4 1,4 5 (first 5) 1,4 5 (second 5) 2,3 5 (first 5) 2,3 5 (second 5)5 (first 5) 5 (second 5) 5 (second 5) 5 (first 5) 1,2,3,4 5,5Note that each '5' is a different piece of jewelry and needs to be accounted for separately. There are 9 legal ways of allocating the jewelry to Bob andFrank given the policy, so your method would return 9. Regards, Akash Agrawal http://tech-queries.blogspot.com/ -- 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.
Re: [algogeeks] file handling
use FILE * Can u elaborate on the probelm? Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Mon, Dec 13, 2010 at 1:03 PM, neeraj agarwal itsneerajagar...@gmail.comwrote: i am facing problem in file handling in C can any one suggest me how to implement them. -- 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.
Re: [algogeeks] Google questions
It is like finding the in order successor. See it here (using parent pointer) http://tech-queries.blogspot.com/2010/04/inorder-succesor-in-binary-tree.html w/0 Parent pointer: http://tech-queries.blogspot.com/2010/04/inorder-succesor-in-binary-tree-wo.html Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Thu, Dec 9, 2010 at 11:33 PM, GOBIND KUMAR gobind@gmail.com wrote: Code for question no.--2 #includestdio.h #includeconio.h #includetime.h struct test{ clock_t endwait; void (*print_ptr)(); }; void print() {printf(\nHello World\n);} void wait ( int seconds ) { struct test *g=(struct test *)malloc(sizeof(struct test)); g-endwait= clock () + seconds * CLOCKS_PER_SEC ; while (clock() g-endwait) {} (g-print_ptr)=print; (*(g-print_ptr))(); } int main(){ int sec; printf(Enter the time after which you want output:); scanf(%d,sec); wait(sec); getch(); return; } -- 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.
[algogeeks] matrix sum
You have given a matrix of n*m integer. A query will come to you with two co-ordinate (x1,y1) (x2,y2). You need to find sum of all elements which falls inside rectangle. As you will be bombarded with such query, you solution should be very very quick. Ans should be in O(1) Regards, Akash Agrawal http://tech-queries.blogspot.com/ -- 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.
Re: [algogeeks] find triplets in an integer array A[] which satisfy condition: a[i]^2 + a[j]^2 = a[k]^2
Thanks everyone; that O(n^2) is an awesome solution. Regards, Akash Agrawal http://tech-queries.blogspot.com/ On Thu, Dec 2, 2010 at 12:21 PM, fenghuang fenghaungyuyi...@gmail.comwrote: @anoop when you find some i and j(i j) meet the condition i.e. asq[i] + asq[j] == asq[k], you can merge the same value without rollback. in this sense, you are right. On Thu, Dec 2, 2010 at 2:26 PM, anoop chaurasiya anoopchaurasi...@gmail.com wrote: @fenghuang try this array: a[]={3,3,3,3,3,3,4,4,4,4,4,4,5} so asq[]={9,9,9,9,9,9,16,16,16,16,16,16,25} here as u can see the total number of requisite triple pairs are 6*6=36, in general for above array total number of pairs is (n/2)*(n/2) i.e. n^2/4 where n is the size of the array. by using O(n) algo and since you are choosing them one by one,u can't include all of them as they are of order O(n^2). so removing repetitions is the only option i think.. On Wed, Dec 1, 2010 at 11:37 PM, fenghuang fenghaungyuyi...@gmail.comwrote: @anoop in fact, it always work even if there are repeated elements, because they don't change the decision. in detail, assume ii, ,jj, kk is one of the answers, then a[ii]+a[jj]=a[kk]. since the array is sorted, so a[ii-1]+a[jj] = a[kk] and a[ii] + a[jj+1] = a[kk]. so when you try the pair of 'ii-1' and 'jj', the next step must be calculate a[ii] + a[jj] as long as a[ii-1]+a[jj] is not equal to a[kk]. the same to the pair 'ii' and 'jj+1'. the algorithm is correct and in the whole procedure, repeated elements don't affect the decision. I'm sorry for my poor English. Thank You! On Thu, Dec 2, 2010 at 12:14 PM, anoop chaurasiya anoopchaurasi...@gmail.com wrote: sorry for the interruption,we can make it work even if the elements are repeated, by removing the duplicacy in linear time(as the array is already sorted) and taking a count of no. of duplicates in the seperate array. On Wed, Dec 1, 2010 at 9:37 PM, Senthilnathan Maadasamy senthilnathan.maadas...@gmail.com wrote: A small correction to the algorithm above. In Step 3, instead of finding *any* pair (a,b) such that a+b = x we need to find *all* such pairs. However the complexity remains the same. -- 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. -- Anoop Chaurasiya CSE (2008-2012) NIT DGP -- 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.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Anoop Chaurasiya CSE (2008-2012) NIT DGP -- 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.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.