Skip to content

Instantly share code, notes, and snippets.

View coderRohan123's full-sized avatar
🎯
Focusing

Rohan Mallick coderRohan123

🎯
Focusing
View GitHub Profile
@coderRohan123
coderRohan123 / Unique Number of Occurrences - LeetCode Snippet.md
Created January 17, 2024 13:57
This code snippet checks if the occurrences of elements in the given array are unique. It uses a hashmap to count the occurrences of each element and a hashset to keep track of the counts encountered so far. If any count is found to be repeated,

Unique Number of Occurrences - LeetCode Snippet

Preview:
class Solution(object):
    def uniqueOccurrences(self, arr):
        hashMap = {}
        
        # Count occurrences of each element in arr
        for num in arr:
            if num in hashMap:
@coderRohan123
coderRohan123 / Count occurrences of unique elements in a list..md
Created January 17, 2024 14:02
This code snippet checks if the occurrences of elements in the given list are unique. It sorts the list, counts the occurrences of each element, and checks if there are any duplicate occurrence counts. If there are, it returns False; otherwise, it returns

Count occurrences of unique elements in a list.

Preview:
class Solution:
    def uniqueOccurrences(self, arr: List[int]) -> bool:
        arr.sort()
        v = []
​
        i = 0
        while i < len(arr):