Perform a depth-first search on a matrix to find connected components.
Given an n x n matrix where isConnected[i][j] = 1 if the ith node and the jth node are directly connected, and 0 otherwise, return the total number of connected components.
Input: isConnected = [[1,0,0],[0,1,0],[0,0,1]]
Output: 3
Explanation: There are no connectio…
Find the median from a continuous data stream.
Implement a data structure that allows you to add integers from a continuous data stream and find the median of all elements so far efficiently.
Input: addNum(2), addNum(3), findMedian(), addNum(4), findMedian()
Output: 2.5 then 3.0
Explanation: After adding 2 and 3, the median is 2.5. Af…
Find the node with the highest edge score in a directed graph.
You are given a directed graph. Calculate the edge score of each node, which is the sum of the labels of all nodes that have an edge pointing to it. Return the node with the highest edge score.
Input: edges = [1,0,1,1,1]
Output: 1
Explanation: Node 1 receives incoming edge…
Minimum Path Sum
Find the minimum path sum from top-left to bottom-right in a grid.
Input: grid = [[1,2,3],[4,5,6]]
Output: 12
Explanation: The optimal path moves along 1 -> 2 -> 3 -> 6, resulting in a minimum accumulated sum of 12.