Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int pickingNumbers(List<int> a)
- {
- SortedDictionary<int, int> freqTable = new SortedDictionary<int, int>();
- int maxCount = 0;
- foreach (int i in a)
- {
- if (freqTable.ContainsKey(i) == true)
- {
- freqTable[i]++;
- }
- else
- {
- freqTable.Add(i, 1);
- }
- }
- if (freqTable.Count == 1) return a.Count;
- // foreach(var elem in freqTable)
- // Console.WriteLine(String.Concat(elem.Key.ToString(), " ", elem.Value.ToString()));
- for (int i = 0; i < freqTable.Keys.Count-1; i++)
- {
- int val = freqTable.ElementAt(i + 1).Key - freqTable.ElementAt(i).Key;
- // Console.WriteLine(val);
- if (val == 1){
- int tempCount = freqTable.ElementAt(i).Value + freqTable.ElementAt(i + 1).Value;
- if (tempCount > maxCount) maxCount = tempCount;
- }
- }
- return maxCount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement