-
Sliding Window Median
Today, I will talk about https://leetcode.com/problems/sliding-window-median/description/ When I looked at this problem, I thought it should be just an extension to “Median in Data Stream”, But I tried hard to use 2 heap solution and could not find a way to do. So, I started back with a brute force solution and few other ideas.…
-
Custom Comparators
Generally in sorting, we may have to deal with custom sort functions, so what is the intutution behind those and how a custom compartor can actually work, we will see the stl solution and then hook the compartor in merge sort (our own version of merge sort, working merge sort, which doesn’t give a TLE…
-
Graphs
These are few questions 1 should do while doing graphs BFS https://www.geeksforgeeks.org/problems/bfs-traversal-of-graph/1 DFS https://www.geeksforgeeks.org/problems/depth-first-traversal-for-a-graph/1 https://leetcode.com/problems/number-of-islands/description/ https://leetcode.com/problems/number-of-provinces/description/ https://www.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1 In undirected graphs, need to track of parent and skip when A-B, so skip pushing parent in queue https://leetcode.com/problems/01-matrix/description/ distance from all zeros, multi source bfs, push all zeros to queue https://leetcode.com/problems/course-schedule/description/ Topological sort https://leetcode.com/problems/course-schedule-ii/description/ Cycle detection via…
-
Binary Search
Binary search is a simple algo, check mid value, compare, ignore invalid half, move to the valid half until completed / element is found.But the code has many variable, low, high, midShould the loop be while (low < high) or while (low <= high)?or high = mid -1 or high = mid ;What exactly these…
-
Find Median from Data Stream
In this post, we will talk about leetcode 295: https://leetcode.com/problems/find-median-from-data-stream/description/ Problem looks simple, we need to find a Median of data stream, we can sort at each getMedian call. In short we have a such algo: Maintain a dynamic array or list.On every new number:Insert it into the list.To get the median:Sort the list.Return the…
-
Finding the Median of Two Sorted Arrays
We will talk about the problem leetcode 4, https://leetcode.com/problems/median-of-two-sorted-arrays/description/ What is Median The median of a list is the “middle” value: So, if Array is [1,2,3], middle element is 2.if it is [1,2,3,4], middle elements are 2,3 so (2 + 3) / 2 = 2.5 Brute Force At first, we can think to simply merge…
Subscribe
Enter your email below to receive updates.