0

Mode

https://code.sololearn.com/cER0hw0GW0sa/?ref=app I post my code here, The concept is to find common repeated elements in array.. all fine, but logic problem may occur in this code... It prints repeated elements in array, but wants to prints common element from the repeated elements.. For eg., Input : size : 6 1 2 2 3 3 3 Calculated output : 2 3 3 but, Expected Output : 2 3 (common at once) What logic I should follow?

12/2/2019 8:06:51 AM

kumaresan

+1

After printing x[i] in line 45 put i++; to advance next element, to not check again.. take another array for printing, compare element in the array present or not if present dont assign. So print array with no duplicates.... kumaresan or else put simply like this after printing x[i] in if while(x[i]==x[i+1]) i++; it works for any inputs... https://code.sololearn.com/cl9Yc0UgswA7/?ref=app

+1

kumaresan I just want to tell you how I would approach this question. 1) First of all sort the array. 2) Initialize a counter variable which will count the repetition of elements. 3) Then increment the "i" value by i+(count-1) and in the inner loop put j=i so that you don't have to traverse from the beginning of the array.

+1

kumaresan Your code sorts in descending order of values. Kindly have a look a this and a part of your code is commented by me, use the logic 2 and 3 given by me in my previous answer to get your solution. https://code.sololearn.com/cyLC7Sp8rtdD/?ref=app

+1

Avinesh Thanks

0

Jaya krishna Thanks

0

kumaresan welcome...