[algogeeks] Bread Butter Brain
The mega event Bread, Butter and Brain is going to be held tonight at 7.30pm. This is an individual online event. There will be 15 levels with one question per level The difficulty of the questions increases as you advance to the next level. Questions will involve puzzles, logic, programming, mathematics or a combination of all the above. For further details do visit, http://prayatna.org.in/BB_brain/ Cheers ~ Jeeva ~ -- 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 question
No.. They are not uniform.. They will give you distance between two adjacent stations.. Cheers ~ Jeeva ~ On Sun, Aug 7, 2011 at 9:13 PM, iama mailroo...@gmail.com wrote: I think you are missing some part of the question Are the petrol pumps placed uniformly? How many do we have to select exactly? (you have added a 'say' in the statement above. Is it upto the us to choose?) -- 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/-/ucNp9A5bFY8J. 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: Directi question-centre of the tree
5 /\ 6 7 / 8 Here the centre is both 5 and 6 . we need to find both of them..:) Cheers ~ Jeeva ~ -- 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: Fwd: SORTING ARRAYS
This problem is termed as nut and bolts problem..:) We've to use a modification of quick sort..:) Cheers ~ Jeeva ~ On Wed, Jul 27, 2011 at 9:16 AM, siva viknesh sivavikne...@gmail.comwrote: Given two arrays a[] = {1,3,2,4} b[] = {4,2,3,1} both will have the same numbers but in different combination. We have to sort them . The condition is that you cannot compare only elements within the same array.You can compare element of one array with another only. On Jul 27, 8:45 am, sivaviknesh s sivavikne...@gmail.com wrote: -- Forwarded message -- From: Padmaja Sridharan padmaja...@yahoo.in Date: Wed, Jul 27, 2011 at 5:15 AM Subject: SORTING ARRAYS To: mitcse08i...@googlegroups.com Given two arrays a[] = {1,3,2,4} b[] = {4,2,3,1} both will have the same numbers but in different combination. We have to sort them . The condition is that you cannot compare only elements within the same array.You can compare element of one array with another only. ~With Regards Padmaja -- 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 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] MS interview
consider two matrices A B Its solution is based on transposing a matrix B, so that its solution can be computed easily. Here I gave the solution in which each node has three variables index i,j and value. #includeiostream using namespace std; struct node { int val,i,j; node *next; }; node *mul(node *head1,node *head2,node *head3) { node *head=head1,*t1,*t2,*t3,*t4=head1; for(t1=head1,t2=head2,t3=head3;t1!=NULL;) { t3-val=0; while((t2-next!=0) (t2-next-j=t2-j)) { t3-val+=t2-val * t1-val; t1=t1-next; t2=t2-next; } t3-val+=t1-val*t2-val; coutt3-val\n; int ll=0; if(t2-next==0) { t1=t1-next; t4=t1; ll=1; } else if(t2-next-j t2-j) t1=t4; t3=t3-next; if(t2-next!=0) t2=t2-next; else t2=head2; } return head3;//output list } node *transpose(node *head)//transposing list B { int g; node *head1=head,*temp,*head2; head2=head1-next; temp=head; while((temp-next-j)!=(temp-j) || (temp-next-i)=(temp-i)) { couttemp-val\n; if(temp-next!=0) { if(temp-next-j temp-j) { node *t,*t1; t1=temp-next-next; t=temp-next; temp-next=t1; t-next=head1-next; head1-next=t; head1=t; head2=head1-next; } temp=temp-next; if(temp==0 || temp-next==0) { head1=head1-next; head2=head1-next; temp=head2; } } } int i=0,j=0,o; for(temp=head;temp!=NULL;temp=temp-next) { o=1; if(temp-next!=0 temp-j != temp-next-j) { o=0; } if(!o) { temp-i=i; temp-j=j; i++;j=0; } else { temp-i=i; temp-j=j; } j++; } return head; } node *create_matrix_list(int n,int x) { node *head,*temp; for(int i=0;in;i++) { for(int j=0;jn;j++) { if(i==0 j==0) { head=new node(); if(x!=3) cinhead-val; head-next=NULL; head-i=i; head-j=j; temp=head; } else { temp-next=new node(); temp=temp-next; if(x!=3) cintemp-val; temp-i=i; temp-j=j; temp-next=0; } } } return head; } int main() { node *h1=NULL,*h2=NULL,*h3=NULL; coutEnter the size of matrix :; int m; cinm; coutEnter values for matrix A :; h1=create_matrix_list(m,1); coutEnter values for matrix B :; h2=create_matrix_list(m,2); h3=create_matrix_list(m,3); h2=transpose(h2); h3=mul(h1,h2,h3); for(temp=h3;temp!=NULL;temp=temp-next) couti :temp-i\tj :temp-j\tval :temp-val\n; return 0; } sample input: A : 1-2-3-4-5-6-7-8-9 B : 5-6-2-1-3-7-8-2-1 C : 31-18-19-73-51-49-115-84-79 Cheers ~ Jeeva ~ -- 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 15 june ] Engineer Physicist Mathematician puzzle
The mathematician made a small fence around himself and declared himself to be on the outside the fence... :-) Cheers ~ Jeeva ~ On Wed, Jun 15, 2011 at 5:40 PM, amit kumar amitthecoo...@gmail.com wrote: @anika jain: will u plz xplain?? On Wed, Jun 15, 2011 at 4:02 PM, Anika Jain anika.jai...@gmail.comwrote: earth is a sphere i.e consisiting of infinite circles.. so mathematician had put the fence around that circle of the sphere where fence's length is equal to the circle's perimeter. On Wed, Jun 15, 2011 at 12:44 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: Engineer Physicist Mathematician puzzle - 15 june * * ** ** ** *A farmer challenges an engineer, a physicist, and a mathematician to fence off the largest amount of area using the least amount of fence. The engineer made his fence in a circle and said it was the most efficient. The physicist made a long line and said that the length was infinite. Then he said that fencing half of the Earth was the best. The mathematician laughed at the others and with his design, beat the others. What did he do? * * * *Update Your Answers at* : Click Herehttp://dailybrainteaser.blogspot.com/2011/06/engineer-physicist-mathematician-puzzle.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. -- 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] 5th largest element
@Gaurav Aggarwal Obviously O(n^2) worst case if we use ordinary quick sort with slight modification(Best case O(n))... But quick sort can also be done by taking median as element for partition instead of taking first or last element which will take O(nlgn) worst case complexity... But to do the given problem median of median algorithm is best.. It will take O(n) in worst case... 1. Divide the n elements of input into n/5 groups 2. Find median of each group by insertion sort(performs well for small inputs) and pick the median for each each group. 3. Repeat steps (1) and (2) repeatedly to find a single median 4.partition the array using that median. such that k elements are in lower partition and n-k elements are in higher side of partition.(use the partition insuch a way that smallest elements are on higher side of partition and largest elements are on lower side of partition) 5. If index i==k(ith largest element) then return a[i].. else recurse steps 1 to 5 such that (if ik then use k to r) (else use p to k)(p is the starting index and r is ending index).. I hope It explains the code given by piyush sinha.. Cheers ~ Jeeva ~ -- 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: Odd Even Sort array
#includestdio.h #includealgorithm using namespace std; int heap_size1,heap_size2; int main() { int n,a[100],j,k; scanf(%d,n); for(int i=1;i=n;i++) scanf(%d,a[i]); if(n%2) { heap_size2=n/2+1; k=n-1; } else { heap_size2=n/2; k=n; } heap_size1=n/2; for(j=1;jk;j+=2,k-=2) // diving even positions and odd positions of array with even elements at partition1 and odd elements at partition2 swap(a[k],a[j]); heapsort(a,1,heap_size1); // where 1- for root of heap1 ; Use min heap for sorting inverse_heapsort(a,heap_size1+1,heap_size2); //where heap_size1+1 - for root of heap2 ; use max heap for sorting for(int i=1;i=n;i++) printf(%d ,a[i]); return 0; } Cheers ~ Jeeva ~ -- 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] Odd Even Sort array
I hope merge sort is not an inplace sorting.. It'll take extra space (in function merge) and since it uses recursion it'll also take stack space.. I think this sol will work. 1. partition the array by holding the even elements on first space(n/2 or n/2-1 depends on odd sized and even sized array) of array and odd elements in last n/2 space of array. 2. Do heapsort by using both min heap and maxheap by having 0 and (sizeof even elements) as root of heap. 3. Heap don't use extra space and time complexity is O(nlgn). Cheers ~ Jeeva ~ -- 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] spoj--two squares problem
Fermat's theorem will be better for this problem..:) Cheers ~ Jeeva ~ On Thu, May 26, 2011 at 12:42 AM, Saikat Debnath crazysai...@gmail.comwrote: I think your problem is you are using int. Use long long. On Thu, May 26, 2011 at 12:29 AM, ricky moon.afr...@gmail.com wrote: can anyone help me out with this problem: https://www.spoj.pl/problems/TWOSQRS/ It runs on my machine with this code but it gives wrong ans on their site. #includeiostream #includemath.h using namespace std; int main() { int i=0,j=0,X=0,t=0,count=0; cint; while(t--) { cinX; i=sqrt(X); j=sqrt(X-i*i); while(i=0 i=j) { if((i*i)+(j*j)==X) {count++;} i--; j=sqrt(X-i*i); } if(count0) coutYes; else coutNo; count=0; coutendl; } 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. -- 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] spoj--two squares problem
see http://en.wikipedia.org/wiki/Fermat%27s_theorem_on_sums_of_two_squares Hope it'll help...:) Cheers ~ Jeeva ~ On Thu, May 26, 2011 at 9:17 AM, Balaji S balaji.ceg...@gmail.com wrote: Fermat's little theroem ??? -- 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: LARGEST NUMBER PUZZLE 6 MAY
(9! pow 9! ) ! :) Cheers ~ Jeeva ~ On Fri, May 6, 2011 at 6:22 PM, sourabh jakhar sourabhjak...@gmail.comwrote: @manjeet you are genious go for google On Fri, May 6, 2011 at 5:09 PM, ps.raghuchan...@gmail.com ps.raghuchan...@gmail.com wrote: @manjeet ...heheheheheh On Fri, May 6, 2011 at 5:08 PM, Manjeet Chayel chayel.manj...@gmail.comwrote: 1/0 On Fri, May 6, 2011 at 5:06 PM, sourabh jakhar sourabhjak...@gmail.comwrote: what about 9!pow9! On Fri, May 6, 2011 at 5:04 PM, RAghu ps.raghuchan...@gmail.comwrote: What about (9 pow 9) ! On May 6, 4:30 pm, uday kumar uda...@gmail.com wrote: 9 pow 9. On Fri, May 6, 2011 at 3:41 PM, Bala cmb...@gmail.com wrote: 99! Thanks Bala On Fri, May 6, 2011 at 2:48 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: * LARGEST NUMBER PUZZLE What is the largest number you can get using only 2 digits? Update Your Answers at : Click Here http://dailybrainteaser.blogspot.com/2011/05/largest-number-puzzle-6-.. . 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. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- 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. -- Cheers!! Manjeet Chayel -- 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. -- P.S.Raghu Chandra, IIIT Allahabad, B.Tech 8th sem. ps.raghuchan...@gmail.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. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- 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] BISHOPS
Use python for arithmetic operation of large numbers.. :) Cheers ~ Jeeva ~ On Fri, Feb 4, 2011 at 8:32 PM, Manmeet Singh mans.aus...@gmail.com wrote: C/C++ user : Take input in a char array or string(if using C++) : a now do string addition. : a = a + a; now do string substraction. : a = a - 2. Java user : Use BigInt class On Fri, Feb 4, 2011 at 8:12 PM, Logic King crazy.logic.k...@gmail.comwrote: please help me solve the problem on SPOJ https://www.spoj.pl/problems/BISHOPS/ The logic of the problem is very easy i.e. 2*n-2 but i am getting WA bcoz i am not able to deal with the large inputs.[?] plz help me how to get this AC. #includestdio.h int main() { long long int n,bmax; while(scanf(%lld,n)!=EOF) { if(n==1) printf(%d\n,1); else { bmax=(2*n)-2; printf(%lld\n,bmax); } } 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.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 algogeeks@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 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. 325.png
Re: [algogeeks] Re: Easy problem but unable to handle large input
Else you are not familiar with above means, use string multiplication,addition subtraction... :) Cheers ~ Jeeva ~ On Fri, Feb 4, 2011 at 9:02 PM, juver++ avpostni...@gmail.com wrote: Java, python or written big integer class. -- 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.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 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] Spoj Problem : Small Factorials
Use string multiplication. :) Cheers ~ Jeeva ~ On Fri, Feb 4, 2011 at 9:49 PM, Rahul Verma rahulverma@gmail.comwrote: Hi Group, Let me help to solve this problem of SPOJ https://www.spoj.pl/problems/FCTRL2/ The approach to solve the problem is very easy and I'm confused that how to store such a large no. like 100! in a variable using C++ Language. Thanx Regards, Rahul Verma -- 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.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 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] FINDSR in spoj
I've did the problem http://www.spoj.pl/problems/FINDSR with brute force approach.. It is showing TLE.. Anyone tell the approach to solve that problem... -- 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.