Here is one Brute Force solution O(n^3) for each i and j in array(j > i) {where a[i] is first term of AP and a[j] is second term} compute d = a[j]-a[i] and now from j+1 to end of the array search for a+2d,a+3d,a+4d ................ and keep track of longest :)
On Fri, Jul 8, 2011 at 1:28 AM, Piyush Sinha <ecstasy.piy...@gmail.com>wrote: > Nopes....its about finding subsequence.... > > On 7/8/11, rajeev bharshetty <rajeevr...@gmail.com> wrote: > > Should the sequence beContinuos ??? > > > > On Fri, Jul 8, 2011 at 1:18 AM, sunny agrawal > > <sunny816.i...@gmail.com>wrote: > > > >> @rajiv > >> if Count = 2 means 3 elements isn't it a,a+d,a+2d > >> else according to you > >> for case 10 12 14 24 26 28 > >> diff 2 2 10 2 2 > >> diff 2 has count 4 so will you say ap of 4 elements with diff 2 > >> > >> On Fri, Jul 8, 2011 at 1:06 AM, rajeev bharshetty > >> <rajeevr...@gmail.com>wrote: > >> > >>> @sunny Keep count of longest repeated element in diff i.e 2 so count =2 > >>> so > >>> ap of 2 elem with diff 2 . > >>> > >>> On Fri, Jul 8, 2011 at 1:03 AM, sunny agrawal > >>> <sunny816.i...@gmail.com>wrote: > >>> > >>>> @rajiv > >>>> Fails i think > >>>> think for 10 12 24 26 > >>>> diff is 2 12 2 > >>>> so do you want to say there is an AP pf 3 elements with d = 2, i can't > >>>> see any :P > >>>> your solution fails because there can be many APs in the array with > the > >>>> same value of d and you will finish up by combining all those APs > >>>> > >>>> > >>>> On Fri, Jul 8, 2011 at 12:55 AM, rajeev bharshetty < > rajeevr...@gmail.com > >>>> > wrote: > >>>> > >>>>> > >>>>> Check the differences between the adjacent elements and store the > >>>>> differenecs in diff[i] array > >>>>> then scan through the array . > >>>>> then keep a count for all the repeated diff elements ,the sequence of > >>>>> indexes with max count is the solution . > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> On Thu, Jul 7, 2011 at 11:43 PM, Piyush Sinha < > ecstasy.piy...@gmail.com > >>>>> > wrote: > >>>>> > >>>>>> Given an array of integers A, give an algorithm to find the longest > >>>>>> Arithmetic progression in it, i.e find a sequence i1 < i2 < … < ik, > >>>>>> such that > >>>>>> > >>>>>> A[i1], A[i2], …, A[ik] forms an arithmetic progression, and k is the > >>>>>> largest possible. > >>>>>> > >>>>>> The sequence S1, S2, …, Sk is called an arithmetic progression if > >>>>>> > >>>>>> Sj+1 – Sj is a constant. > >>>>>> > >>>>>> -- > >>>>>> *Piyush Sinha* > >>>>>> *IIIT, Allahabad* > >>>>>> *+91-8792136657* > >>>>>> *+91-7483122727* > >>>>>> *https://www.facebook.com/profile.php?id=100000655377926 * > >>>>>> > >>>>>> -- > >>>>>> 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. > >>>>> > >>>> > >>>> > >>>> > >>>> -- > >>>> Sunny Aggrawal > >>>> B-Tech IV 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. > >>> > >> > >> > >> > >> -- > >> Sunny Aggrawal > >> B-Tech IV 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. > > > > > > > -- > *Piyush Sinha* > *IIIT, Allahabad* > *+91-8792136657* > *+91-7483122727* > *https://www.facebook.com/profile.php?id=100000655377926 * > > -- > 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 IV 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.