Geek's Paint Shop is one of the famous shop in Geekland, but 2014 Earthquake caused disarrangement of the items in his shop. Each item in his shop is a 40-digit alpha numeric code .
Now Chunky wants to retain the reputation of his shop, for that he has to arrange all the distinct items in lexicographical order.
Your task is to arrange the all the distinct items in lexicographical ascending order and print them along with their count.
Example 1:
Input:
N = 3
A[] =
["2234597891 zmxvvxbcij 8800654113 jihgfedcba",
"1234567891 abcdefghij 9876543219 jihgfedcba",
"2234597891 zmxvvxbcij 8800654113 jihgfedcba"]
Output:
1234567891 abcdefghij 9876543219 jihgfedcba 1
2234597891 zmxvvxbcij 8800654113 jihgfedcba 2
Explanation:
We have 3 items (40 digit alphanumeric codes) 
here. We arrange the items based on the 
lexicographical order of their alpha-numeric 
code. Distinct items are printed only once. 
The count of the items describes how many 
such items are there, so items that appear 
more than once have their count greater than 1.
Example 2:
Input:
N = 2
A[] =
["3122049353 onafrnbhtr 9822827304 yzfhdgzcvx", 
"2992299540 lpvkgykmlk 6946169466 vdqwvywwgg", 
Output:
2992299540 lpvkgykmlk 6946169466 vdqwvywwgg  1
3122049353 onafrnbhtr 9822827304 yzfhdgzcvx  1
Explanation:
Out of the 2 items here no one is repeated.
Your Task:
You don't need to read input or print anything. Your task is to complete the function sortedStrings() which takes an integer N and an array of strings A[ ] and returns the array in sorted order along with the frequency of each distinct string.
Expected Time Complexity:O(NlogN)
Expected Auxillary Space:O(N)
Constraints:
1 ≤ N ≤ 10000

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



class alphanumeric:

    def __init__(self,name,count):

        self.name=name

        self.count=count

class Solution:

    def sortedStrings(self,N,A):

        #code here

Solutions:
from collections import defaultdict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		store = defaultdict(lambda : 0)
		for item in A:
			store[item] += 1
		output = []
		items = sorted(store.keys())
		for item in items:
			output.append(alphanumeric(item, store[item]))
		return output


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		res = []
		d = {}
		for i in A:
			try:
				d[i] = d[i] + 1
			except:
				d[i] = 1
		for k in sorted(d.keys()):
			res.append(alphanumeric(name=k, count=d[k]))
		return res


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		py_dict = sorted(Counter(A).items())
		return [alphanumeric(name=key, count=value) for (key, value) in py_dict]


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		d = {}
		for i in A:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		t = sorted(d.keys())
		l = []
		for i in t:
			l.append(alphanumeric(i, d[i]))
		return l


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		ret_list = []
		dic = dict()
		for item in A:
			dic[item] = dic.get(item, 0) + 1
		for key in sorted(dic.keys()):
			obj1 = alphanumeric(name=key, count=dic[key])
			ret_list.append(obj1)
		return ret_list


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		map = dict()
		res = []
		for i in A:
			if i not in map:
				map[i] = 0
			map[i] += 1
		for i in sorted(map.keys()):
			res += [alphanumeric(i, map[i])]
		return res


from collections import defaultdict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		res = list()
		bucket = defaultdict(int)
		for s in A:
			bucket[s] += 1
		for key in sorted(bucket.keys()):
			res.append(alphanumeric(name=key, count=bucket[key]))
		return res


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		from collections import Counter
		ans = [alphanumeric(key, value) for (key, value) in Counter(A).items()]
		ans.sort(key=lambda x: x.count)
		ans.sort(key=lambda x: x.name)
		return ans


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		mp = {}
		for el in A:
			if el not in mp:
				mp[el] = 1
			else:
				mp[el] += 1
		ans = [alphanumeric('', 0) for _ in range(len(mp))]
		i = 0
		for el in sorted(mp):
			ans[i].name = el
			ans[i].count = mp[el]
			i += 1
		return ans


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		d = {}
		for i in A:
			try:
				d[i] += 1
			except:
				d[i] = 1
		p = sorted(list(d.keys()))
		x = []
		for i in p:
			x.append(alphanumeric(i, d[i]))
		return x


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		my_dict = {}
		A.sort()
		for item in A:
			if item in my_dict:
				my_dict[item] += 1
			else:
				my_dict[item] = 1
		return [alphanumeric(name=i, count=my_dict[i]) for i in sorted(my_dict.keys())]


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		return sorted([alphanumeric(k, v) for (k, v) in Counter(A).items()], key=lambda x: x.name)


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		l = []
		m = {}
		for i in A:
			if i in m.keys():
				m[i] = m[i] + 1
			else:
				m[i] = 1
		for i in sorted(m):
			x = alphanumeric(i, m[i])
			l.append(x)
		return l


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		a = []
		c = sorted(Counter(A).items())
		for (k, v) in c:
			a.append(alphanumeric(name=k, count=v))
		return a


from collections import OrderedDict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		hm = OrderedDict()
		for s in A:
			hm[s] = hm.get(s, 0) + 1
		sorted_keys = list(hm.keys())
		sorted_keys.sort()
		res = []
		for ele in sorted_keys:
			res.append(alphanumeric(ele, hm.get(ele)))
		return res


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		dic = dict()
		l = []
		for i in A:
			if i not in dic:
				dic[i] = 1
			else:
				dic[i] += 1
		for i in sorted(dic):
			l.append(alphanumeric(name=i, count=dic[i]))
		return l


from collections import OrderedDict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A.sort()
		dic = OrderedDict()
		li = []
		for i in A:
			if i not in dic:
				dic[i] = 1
			else:
				dic[i] += 1
		for i in dic:
			li.append(alphanumeric(i, dic[i]))
		return li


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		dic = dict()
		for a in A:
			if a in dic:
				dic[a] += 1
			else:
				dic[a] = 1
		return [alphanumeric(k, dic[k]) for k in sorted(dic.keys())]


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A.sort()
		d = {}
		for i in range(N):
			if A[i] in d:
				d[A[i]] += 1
			else:
				d[A[i]] = 1
		A.sort()
		d1 = {}
		l = []
		for x in A:
			if x not in d1:
				p = alphanumeric(x, d[x])
				l.append(p)
				d1[x] = 1
		return l


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		l = []
		A.sort()
		prev = A[0]
		c = 1
		for i in range(1, len(A)):
			if A[i] == prev:
				c += 1
			else:
				l.append(alphanumeric(prev, c))
				c = 1
				prev = A[i]
		l.append(alphanumeric(prev, c))
		return l


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		d = {}
		for item in A:
			d[item] = d.get(item, 0) + 1
		sd = sorted(d)
		ans = [alphanumeric('', 0) for _ in range(len(d))]
		i = 0
		for el in sd:
			ans[i].name = el
			ans[i].count = d[el]
			i += 1
		return ans


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, n, arr):
		result = []
		freq = {}
		for i in range(n):
			if arr[i] not in freq:
				freq[arr[i]] = 0
			freq[arr[i]] += 1
		A = list(set(arr))
		A.sort()
		for item in A:
			obj = alphanumeric(item, freq[item])
			result.append(obj)
		return result


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		dt = Counter(A)
		A = list(set(A))
		A.sort()
		res = []
		for a in A:
			res.append(alphanumeric(a, dt[a]))
		return res


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		output = []
		coun = {}
		for i in A:
			if i in coun:
				coun[i] += 1
			else:
				coun[i] = 1
		for i in sorted(coun.keys()):
			output.append(alphanumeric(name=i, count=coun[i]))
		return output


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		d = {}
		for i in A:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		d1 = sorted(list(d.keys()))
		return [alphanumeric(name=i, count=d[i]) for i in d1]


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		res = []
		c = Counter(A)
		d = sorted(c.items())
		return [alphanumeric(name=key, count=value) for (key, value) in d]


from collections import Counter
from collections import OrderedDict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		z = Counter(A)
		dict1 = OrderedDict(sorted(z.items()))
		res = []
		for (i, j) in dict1.items():
			res.append(alphanumeric(str(i), str(j)))
		return res


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A.sort()
		A.append('100')
		c = 1
		li = []
		for i in range(len(A) - 1):
			if A[i] == A[i + 1]:
				c = c + 1
			else:
				li.append(alphanumeric(A[i], c))
				c = 1
		return li


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		d = {}
		for i in A:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		res = [alphanumeric(name=i, count=d[i]) for i in sorted(d.keys())]
		return res


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		strings = {}
		output = []
		for i in range(N):
			if A[i] in strings:
				strings[A[i]] += 1
			else:
				strings[A[i]] = 1
		for i in sorted(strings.keys()):
			obj = alphanumeric(i, strings[i])
			output.append(obj)
		return output


import collections

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		my_dict = collections.defaultdict(lambda : 0)
		for string in A:
			my_dict[string] += 1
		ans = []
		for string in sorted(set(A)):
			ans.append(alphanumeric(string, my_dict[string]))
		return ans


from numpy import sort
from collections import OrderedDict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A.sort()
		cnt = OrderedDict()
		for i in range(N):
			if not cnt.get(A[i]):
				cnt[A[i]] = 1
			else:
				cnt[A[i]] = cnt[A[i]] + 1
		ans = []
		[ans.append(alphanumeric(k, cnt[k])) for k in cnt]
		return ans


from collections import OrderedDict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		ans = []
		A.sort()
		count = OrderedDict()
		for sent in A:
			if sent in count:
				count[sent] += 1
			else:
				count[sent] = 1
		for sent in count:
			code = alphanumeric(sent, count[sent])
			ans.append(code)
		return ans


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		map = {}
		for i in A:
			if i in map:
				map[i] += 1
			else:
				map[i] = 1
		ans = []
		for i in sorted(map.keys()):
			ans.append(alphanumeric(i, map[i]))
		return ans


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		m = {}
		for elem in A:
			if elem in m:
				m[elem] += 1
			else:
				m[elem] = 1
		ans = []
		for k in sorted(m.keys()):
			ans.append(alphanumeric(k, m[k]))
		return ans


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		freq = Counter(A)
		ans = []
		for item in sorted(freq.keys()):
			obj = alphanumeric(item, freq[item])
			ans.append(obj)
		return ans


from collections import defaultdict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, n, a):
		hmap = defaultdict(int)
		for name in a:
			hmap[name] += 1
		result = []
		for name in sorted(hmap.keys()):
			result.append(alphanumeric(name, hmap[name]))
		return result


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		doc = dict()
		for i in A:
			if i in doc:
				doc[i] += 1
			else:
				doc[i] = 1
		return [alphanumeric(name=i, count=doc[i]) for i in sorted(doc.keys())]


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A.sort()
		D = {}
		for i in A:
			if i not in D:
				D[i] = 1
			else:
				D[i] += 1
		l = [alphanumeric('', 0) for i in range(len(D))]
		i = 0
		for j in sorted(D):
			l[i].name = j
			l[i].count = D[j]
			i += 1
		return l


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		m = {}
		for e in A:
			if e not in m:
				m[e] = 0
			m[e] += 1
		b = set(A)
		c = list(b)
		c.sort()
		return [alphanumeric(x, m[x]) for x in c]


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		dic = {}
		ans = []
		for x in A:
			if x not in dic:
				dic[x] = 1
			else:
				dic[x] += 1
		temp = list(dic.keys())
		temp.sort()
		for x in temp:
			ans.append(alphanumeric(x, dic[x]))
		return ans


from collections import Counter

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		count = sorted(list(Counter(A).items()))
		out = []
		for (el, c) in count:
			out.append(alphanumeric(el, c))
		return out


from collections import OrderedDict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A = sorted(A)
		table = OrderedDict()
		for item in A:
			if item not in table:
				table[item] = alphanumeric(item, 1)
			else:
				table[item].count += 1
		return [value for (key, value) in table.items()]


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		res = []
		freq = {}
		for i in A:
			if i not in freq:
				freq[i] = 0
			freq[i] += 1
		for i in sorted(freq):
			obj = alphanumeric(i, freq[i])
			res.append(obj)
		return res


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		mapp = {}
		for code in A:
			if code in mapp:
				mapp[code] += 1
			else:
				mapp[code] = 1
		return [alphanumeric(i, mapp[i]) for i in sorted(mapp.keys())]


class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, n, arr):
		d = {}
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		l = list(d.items())
		l.sort(key=lambda x: x[0])
		ans = []
		for i in l:
			ans.append(alphanumeric(i[0], i[1]))
		return ans


from collections import defaultdict

class alphanumeric:

	def __init__(self, name, count):
		self.name = name
		self.count = count

class Solution:

	def sortedStrings(self, N, A):
		A.sort()
		l = []
		d = defaultdict(int)
		for k in A:
			d[k] += 1
		for k in d:
			l.append(k)
			l.append(d[k])
		return [alphanumeric(name=i, count=d[i]) for i in sorted(d.keys())]