## 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…

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…

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…

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…

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, given the following matrix: [ [ 1,…

Java Solution This problem can be solved by BFS. We define one matrix for tracking the distance from each building, and another matrix for tracking the number of buildings that…

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has properties: 1) Integers in each row are sorted from left to right.…

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Java…

Design a Tic-tac-toe game that is played between two players on a n x n grid. Java Solution 1 - Naive We can simply check the row, column, and diagonals…

Write a program to solve a Sudoku puzzle by filling the empty cells. Java Solution public void solveSudoku(char[][] board) { helper(board); } private boolean helper(char[][] board){ for(int i=0; i<9; i++){…

Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are…