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 / 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):
@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 / Randomized Set Implementation.md
Created January 16, 2024 05:15
The code snippet is a class that implements a randomized set. It allows for searching, inserting, and removing elements. The getRandom() method returns a random element from the set.

Randomized Set Implementation

Preview:
class RandomizedSet {
    private ArrayList<Integer> list;
    private Map<Integer, Integer> map;

    public RandomizedSet() {
        list = new ArrayList<>();
 map = new HashMap&lt;&gt;();
@coderRohan123
coderRohan123 / Insert Delete GetRandom O(1) - LeetCode Snippet.md
Created January 16, 2024 05:14
The code snippet defines a class called RandomizedSet that implements a set data structure with the ability to insert, remove, search for an element, and get a random element from the set. The set is implemented using a list and a dictionary for efficient

Insert Delete GetRandom O(1) - LeetCode Snippet

Preview:
import randomclass RandomizedSet:
​
    def __init__(self):
        self.lst = []
        self.idx_map = {}
@coderRohan123
coderRohan123 / Find Players With Zero or One Losses.md
Last active January 15, 2024 11:51
YouTube Video Explanation: Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

Find Players With Zero or One Losses

Preview:
class Solution:
    def findWinners(self, matches):
        losses = [0] * 100001

        for winner, loser in matches:
            if losses[winner] == 0:
                losses[winner] = -1
@coderRohan123
coderRohan123 / Find Players With Zero or One Losses.md
Created January 15, 2024 11:46
The code snippet takes in a 2D array of matches, where each match is represented by an array of two integers (winner and loser). It determines the winners in three categories: zero losses, one loss, and more than one loss. It

✅☑Beats 98.22% Users || [C++/Java/Python/JavaScript] || EXPLAINED🔥 - LeetCode Discuss Snippet

Preview:
import java.util.*;

class Solution {
    public int[][] findWinners(int[][] matches) {
        Set<Integer> zeroLoss = new HashSet<>();
        Set<Integer> oneLoss = new HashSet<>();
        Set<Integer> moreLoss = new HashSet<>();
@coderRohan123
coderRohan123 / Max Ancestor Difference in Binary Tree.md
Created January 11, 2024 14:04
The code snippet defines a class TreeNode representing a node in a binary tree. The Solution class has a method maxAncestorDiff that calculates the maximum difference between a node and any of its ancestors in the tree, and returns the result. The method uses

Max Ancestor Difference in Binary Tree

Preview:
import java.util.*;
​
class TreeNode {
    int val;
    TreeNode left, right;
    TreeNode(int x) {
        val = x;
@coderRohan123
coderRohan123 / Max Ancestor Difference in Binary Tree.md
Created January 11, 2024 14:03
This code snippet defines a class Solution with a method maxAncestorDiff that calculates the maximum difference between any node value and its ancestor value in a binary tree. It uses a helper method to recursively traverse the tree and update the minimum and maximum values encountered

Max Ancestor Difference in Binary Tree

Preview:
# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution(object):
@coderRohan123
coderRohan123 / Binary Tree Max Distance.md
Created January 10, 2024 13:26
The code snippet defines a class Solution that calculates the maximum distance between a given node and any leaf node in a binary tree. The amountOfTime method takes a root node and a starting value, and returns the maximum distance. The traverse method recursively travers

Binary Tree Max Distance

Preview:
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
@coderRohan123
coderRohan123 / Leaf Similarity Check.md
Created January 9, 2024 03:55
The code snippet defines a class Solution with a method leafSimilar that takes in two binary trees as input. It uses depth-first search (DFS) to traverse the trees and accumulate the leaf values. It then compares the leaf value sequences of both trees and

Leaf Similarity Check

Preview:
from typing import Optional

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right