Skip to content

Instantly share code, notes, and snippets.

@prithajnath
Created March 24, 2017 00:44
Show Gist options
  • Select an option

  • Save prithajnath/4f575f0f45bf1b85d7393095cc71caea to your computer and use it in GitHub Desktop.

Select an option

Save prithajnath/4f575f0f45bf1b85d7393095cc71caea to your computer and use it in GitHub Desktop.
#!/bin/python
import sys
from collections import Counter
n = int(raw_input().strip())
a = map(int,raw_input().strip().split(' '))
max_num = -1
freq = Counter(a)
new_arr = freq.keys()
new_arr.sort()
for i in xrange(len(new_arr)-1):
x,y = new_arr[i],new_arr[i+1]
if abs(x-y)<=1:
max_num = max(max_num,freq[x]+freq[y])
print max_num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment