shlogg · Early preview
Prashant Mishra @prashantrmishra

There is always a price for those who persevere.

Validating A Binary Search Tree In O(n) Time Complexity

Validating a Binary Search Tree (BST) in O(n) time complexity. A BST is valid if for every node, its value is greater than all values in its left subtree and less than all values in its right subtree.

Designing A Trie Data Structure For Word Dictionary Operations

Implementing a Word Dictionary using Trie data structure. The `WordDictionary` class uses a Trie to store words and provides methods for adding words and searching for words with wildcards (`.`).

Minimizing Robot's Maximum Collectable Values In Grid Game

Minimax algorithm for grid game: TC O(n), SC O(n). Robot 1 tries to minimize values collected by Robot 2, who maximizes. Prefix sums used to optimize calculations.

Counting Stars Between Pipes In A String

Count Stars Between Pipes: Given a string s and ranges a, count stars enclosed between first & last pipes for each range. Use prefix & suffix arrays to find nearest pipes & calculate star counts.

Optimizing Vowel Count Queries In O(n) Time Complexity

Calculate prefix[] in O(n) and get vowel counts in O(k). Solution: iterate words, update prefix[], then calculate result for each query using prefix[]. Vowel check: a,e,i,o,u.

Calculating Subarray Sum Using Prefix Sum In O(1) Time Complexity

Calculate prefix sums in O(n) time, then use them to find subarray sums in O(1) time with NumArray class. Prefix[i] stores sum till ith index, making range sum calculation efficient.

Optimizing String Substring Count With Efficient Algorithm

Solution: Count substrings with at least k distinct characters. Use sliding window approach, incrementing right pointer and decrementing left pointer when necessary hash values reach threshold.

Efficient Interval Intersection With O(nlogn) Time Complexity

Merge intervals from two lists in O(nlogn) time, where n is the total number of intervals. Use a single list to combine and sort both input lists, then greedily find overlapping intervals.