# hw to find maxm repeated values [Resolved]

Posted by Oswaldlily under C# on 12/1/2011 | Points: 10 | Views : 1343 | Status : [Member] | Replies : 5
1 2 1 3 1 2 1 3 2 3 1 3 which i have stored in list

how to find first maxm repaeated elements here
second maxm repaeated elements
3rd maximum repeated elements

#### Responses

Posted by: Blessyjees on: 12/1/2011 [Member] Bronze | Points: 50
 0 Hi, Try this ```var numberGroups = (from n in num group n by n into g orderby g.Count() descending select new { Numbers = g.Distinct() }).Take(1);``` Blessy Baby Digitalmesh Softech pvt Ltd https://blessybaby.wordpress.com/Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Sksingh on: 12/1/2011 [Member] Starter | Points: 25
 0 Hi, Try below code. ``` List num = new List(); // todo: add items to list as mentioned above ..... var numberGroups = from n in num group n by n into g orderby g.Count() descending select new {Numbers = g.Distinct() }; foreach (var g in numberGroups) { foreach (var n in g.Numbers) { Console.WriteLine(n); } }``` Printed result will be in order to max to min repeated num.Regards, SunilOswaldlily, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Oswaldlily on: 12/1/2011 [Member] Starter | Points: 25
 0 @Sksingh in ur code i m getting all unique values.... I need maximum repeated values (i.e) first maxm repeated values are 1 second-3 Third-2Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Blessyjees on: 12/1/2011 [Member] Bronze | Points: 25
 0 Hi, I have tried sksingh code. I got the correct result ```List num = new List(); num.Add(1); num.Add(2); num.Add(1); num.Add(3); num.Add(1); num.Add(2); num.Add(1); num.Add(3); num.Add(2); num.Add(3); num.Add(1); num.Add(3); // todo: add items to list as mentioned above ..... var numberGroups = from n in num group n by n into g orderby g.Count() descending select new { Numbers = g.Distinct() }; foreach (var g in numberGroups) { foreach (var n in g.Numbers) { Console.WriteLine(n); } }``` output 1 3 2Blessy Baby Digitalmesh Softech pvt Ltd https://blessybaby.wordpress.com/Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Oswaldlily on: 12/1/2011 [Member] Starter | Points: 25
 0 if i need to maximum number alone????...no need to get 2nd and 3rd element??Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator
Latest Posts