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 / stateful-vs-stateless-in-sysDesign.md
Created December 30, 2025 16:34
Stateful vs Stateless Systems in Design

Stateful vs. Stateless Systems in Design

elaborated by Grok

In system design, a stateful system maintains client-specific data (state) across requests on the server, like user sessions or shopping carts. This state is often stored in memory or local storage, making the server "remember" interactions. A stateless system treats each request independently, with no retained state on the server—any needed state is passed by the client (e.g., via tokens or headers) or fetched from external shared storage.

Statelessness is key for scalability, reliability, and simplicity, especially in distributed environments like microservices or cloud setups.

Problem: State Sticking to One Server in Horizontal Scaling

@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