Skip to content

Commit 45a9581

Browse files
committed
Adding Efficient Solution - Problem - 1207 - Unique Number Occurences
1 parent b4d7bad commit 45a9581

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 1207
6+
## Problem Name: Unique Number of Occurrences
7+
##===================================
8+
#
9+
#Given an array of integers arr, write a function that returns true
10+
#if and only if the number of occurrences of each value in the array is unique.
11+
#
12+
#Example 1:
13+
#
14+
#Input: arr = [1,2,2,1,1,3]
15+
#Output: true
16+
#Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
17+
#Example 2:
18+
#
19+
#Input: arr = [1,2]
20+
#Output: false
21+
#Example 3:
22+
#
23+
#Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
24+
#Output: true
25+
from collections import Counter as c #Import Counter module
26+
class Solution:
27+
def uniqueOccurences(self, arr):
28+
tmp = c(arr) #Initialize tmp which count the occurrences
29+
tmpVal = [] #Initialize tmpVal empty list
30+
for key, val in tmp.items(): #Loop through dictionary
31+
tmpVal.append(val) #Append the val in tmpVal list
32+
count = c(tmpVal) #Initialize count which count the occurrences of values
33+
for key, val in count.items(): #Loop through dictionary
34+
if val != 1: #Condition-check: If val is not equal to 1 such that any value occurrence twice or more than that
35+
return False #We return false
36+
return True #Return true otherwise

0 commit comments

Comments
 (0)