Hi Aravind, I think it will not work in this array: {1,2,3,4,5,6,7,7,7,7} It would give currentelem=7 and c=3 but 7 is not repeated 6 times.
Best > Init c = 1; > Init elem = first character in the array. > for each element in the array (other than the first one): > if currentelem == elem: c++ > else: c--; > > if c == 0: elem = currentelem > > At the end of this loop, the current element specifies the element which > appears n/2+1 or more times, IF c is not 0. > If c is 0, no element occurs n/2 + 1 times. > > This takes just O(n) time, as it is just one iteration through the loop, and > only uses constant space. > > > > -- > Aravind Narayanan | [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---