## Find a Path in a Matrix (Java)

Given a 2d matrix, find a path from the top left corner to the bottom right corner. Assume there exists at least one path, and you only need to find…

## Find K Pairs with Smallest Sums (Java)

You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from the first array…

## Sparse Matrix Multiplication (Java)

Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is equal to B's row number. 1. Naive Method We can…

## Implement a Stack Using an Array in Java

This post shows how to implement a stack by using an array. The requirements of the stack are: 1) the stack has a constructor which accepts a number to initialize…

## Implement a Queue using an Array in Java

There following Java code shows how to implement a queue without using any extra data structures in Java. We can implement a queue by using an array. import java.lang.reflect.Array; import…

## Kth Smallest Element in a Sorted Matrix (Java)

Given an n x n matrix where each of the rows and columns is sorted in ascending order, find the kth smallest element in the matrix. Note that it is…

## Best Meeting Point (Java)

A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1…

## Walls and Gates (Java)

You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an obstacle.0 - A gate.INF - Infinity means an empty…

## Number of Connected Components in an Undirected Graph (Java)

Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number…

## Find the number of Unique Paths (Java)

A robot is located at the top-left corner of a m x n grid. It can only move either down or right at any point in time. The robot is…