with matrix this problem will be in O(n^2). We don' have to just check the max number present in matrix. We have to check as
array a[]= 1,2,3,4,5,6,8,10,12,14 diff[][]= 1 2 3 4 5 6 8 10 12 14 2 0 1 2 3 4 6 8 10 12 3 -1 0 1 2 3 5 7 9 11 4 -2 -1 0 1 2 4 6 8 10 5 0 6 0 8 0 10 0 12 0 14 0 now in this diff[][] you have to search for if the diff[2][3] =1 then there should be diff[3][i]=1 and then diff[i][j]=1 ...and so on ...this will give n A.P of 6 elements but check for diff[2][4]=2 then diff[4][6]=2 ....and so on...this will give an A.P of 7 and its solvable in O(n^2) On Mon, Jul 11, 2011 at 5:01 PM, sunny agrawal <sunny816.i...@gmail.com>wrote: > @Divye sir > yeah that will work fine if D is in reasonable limits ...... > > > On Mon, Jul 11, 2011 at 4:26 PM, DK <divyekap...@gmail.com> wrote: > >> @Ritu: Your solution is incorrect. >> >> Consider >> >> 1 3 41 43 47 49 90 100 110 >> >> Maximum repeated 'd' value: >> '2' for the pairs (1,3), (41,43), (47,49) = 3 repeats. However, the >> sequences themselves are not part of an AP. >> The longest AP is of size 3 - (90, 100, 110) with a d of 10. >> >> >> -- >> DK >> >> http://twitter.com/divyekapoor >> http://www.divye.in >> >> -- >> 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/-/FnebaYc_FbIJ. >> >> 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.