Find the K closest points to the origin.
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
Input: points = [[3,3],[5,-1],[-2,4]], k = 2
Output: [[3,3], [-2,4]]
Explanation: The squared distances are 18, 26, and 20 respectively. Th…
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…
Find the longest increasing path in a matrix.
Given an m x n integers matrix, return the length of the longest strictly increasing path in the matrix. From each cell, you can either move in four directions: left, right, up, or down.
Input: matrix = [[1,2],[3,4]]
Output: 3
Explanation: The longest strictly increasing path is 1 -> 3 ->…