Find the shortest distance from all buildings to an empty land in a grid.
You are given a grid of values 0, 1, or 2, where 0 is empty land, 1 is a building, and 2 is an obstacle. Find the shortest travel distance from all buildings to an empty land spot.
Input: grid = [[1,0],[0,1]]
Output: 2
Explanation: The empty lands are at (0,1) a…
Split Array into Consecutive Subsequences
Split an array into consecutive subsequences.
Input: nums = [1,2,3,4,4,5]
Output: FALSE
Explanation: The numbers can form [1,2,3,4], but the remaining leftover group [4,5] is too short to form a valid sequence of length 3.
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.
Find the median of two sorted arrays.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
Input: nums1 = [1, 2], nums2 = [3, 4]
Output: 2.5
Explanation: The merged array is [1, 2, 3, 4]. The median is the average of th…