Skip to content

Instantly share code, notes, and snippets.

View vedesh-padal's full-sized avatar
🎯
grind

Vedesh Padal vedesh-padal

🎯
grind
View GitHub Profile
@vedesh-padal
vedesh-padal / MinHeightTree.java
Created December 24, 2024 16:44
Minimum height tree - Topo Sort / Level order Traversal / Onion Peeling
class Solution {
// INTUITION:
// to get the min. height, find the diameter of the graph (tree)
// the middle node is your root of the min. height tree
// if diameter of tree is of length:
// odd: middle node in the diameter path is the only root node
// that is possible that forms the min. tree hight
// even: there are two root nodes possible that form the min. tree height
@vedesh-padal
vedesh-padal / RangeFreqQuery.java
Created December 24, 2024 07:04
LC - 2080 - Range Frequency Query - based on Segment tree and Hashtable - could use Binary search in some way to optimize maybe
class RangeFreqQuery {
private int[] arr;
private Map<Integer, Integer>[] segTree;
public RangeFreqQuery(int[] arr) {
this.arr = arr;
segTree = new HashMap[4*arr.length];
buildSegTree(0, 0, arr.length - 1, arr, segTree);
}
@vedesh-padal
vedesh-padal / HandOfStraights.java
Created October 2, 2024 06:50
847 - Hand of Straights LeetCode
// Alice has some number of cards and she wants to rearrange the cards into
// groups so that each group is of size groupSize, and consists of groupSize
// consecutive cards.
// Given an integer array hand where hand[i] is the value written on the ith
// card and an integer groupSize, return true if she can rearrange the cards, or
// false otherwise.
// Example 1:
// Input: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3