🔁 Building an LRU Cache in JavaScript (The Right Way)
Imagine you're building a browser, an in-memory database, or any service where you want to store recently accessed items and automatic...
1534. Count Good TripletsDifficulty: EasyTopics: Array, EnumerationGiven an array of integers arr, and three integers a, b and c. You need to find the number of good triplets.A triplet (arr[i], arr[j]...
2179. Count Good Triplets in an ArrayDifficulty: HardTopics: Array, Binary Search, Divide and Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered SetYou are given two 0-indexed arrays nums...
2537. Count the Number of Good SubarraysDifficulty: MediumTopics: Array, Hash Table, Sliding WindowGiven an integer array nums and an integer k, return the number of good subarrays of nums.A subarray ...
2176. Count Equal and Divisible Pairs in an ArrayDifficulty: EasyTopics: ArrayGiven a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < ...
*Used in Amazon, Google, Microsoft Interviews 🚀
*Hey devs 👋
If you’ve ever struggled with finding the maximum sum of a subarray, this is the trick you were probably missing: Kadane’s Algorit...
Finding the maximum depth (or height) of a binary tree is one of the most classic problems in tree data structures. In this post, we’ll explore three powerful approaches:
✅ Recursive DFS
✅ Iter...
38. Count and SayDifficulty: MediumTopics: StringThe count-and-say sequence is a sequence of digit strings defined by the recursive formula:
countAndSay(1) = "1"
countAndSay(n) is the run-length enco...
Problemtc :O(n) where n is no. of nodes in the original linked list
Iterative approach:
⛶/*
// Definition for a Node.
class Node {
int val;
Node next;
Node random;
public Node(int v...