# Tagged: 2D Arrays

## Dynamic Programming — Maximum size square sub-matrix with all 1s

Objec­tive: Given a matrix of 0’s and 1’s (binary matrix). Find out Max­i­mum size square sub-matrix with all 1’s. Exam­ple: Approach: Base Cases: If only one row is given then cells with 1’s will be…

## Dynamic Programming — Subset Sum Problem

Objec­tive: Given a set of pos­i­tive inte­gers, and a value sum S, find out if there exist a sub­set in array whose sum is equal to given sum S. Exam­ple: int[] A = {…

## The Word Break Problem

Objec­tive : Given an string and a dic­tio­nary of words, find out if the input string can be bro­ken into a space-separated sequence of one or more dic­tio­nary words. Exam­ple: dic­tio­nary = [“I” , “have”,…

## Backtracking — Knight’s Tour Problem

Objec­tive : A knight’s tour is a sequence of moves of a knight on a chess­board such that the knight vis­its every square only once. If the knight ends on a square that is…

## Backtracking — Search a Word In a Matrix

Objec­tive : Given a 2D matrix of char­ac­ters. Check whether the word exist in the matrix or not. If it exists then print its path. All move­ments are allowed (right, left, up, down and…

## Backtracking — N Queens Problem — Better Solution

Objec­tive : In chess, a queen can move as far as she pleases, hor­i­zon­tally, ver­ti­cally, or diag­o­nally. A chess board has 8 rows and 8 columns. The stan­dard 8 by 8 Queen’s prob­lem asks…

## Backtracking — N Queens Problem

Objec­tive : In chess, a queen can move as far as she pleases, hor­i­zon­tally, ver­ti­cally, or diag­o­nally. A chess board has 8 rows and 8 columns. The stan­dard 8 by 8 Queen’s prob­lem asks…

## Backtracking — Rat In A Maze Puzzle

Given a maze, NxN matrix. A rat has to find a path from source to des­ti­na­tion. maze[0][0] (left top corner)is the source and maze[N-1][N-1](right bot­tom cor­ner) is des­ti­na­tion. There are few cells which are…

## Count All Paths from Top left to bottom right in Two Dimensional Array including Diagonal Paths

Objec­tive: Count all the paths from left top cor­ner to right bot­tom cor­ner in two dimen­sional array. Input: Two Dimen­sional array Out­put: No of paths. Approach : 1. Recur­sive Recur­sive solu­tion to this prob­lem is…

## Print All Paths from Top left to bottom right in Two Dimensional Array

Objec­tive: Print all the paths from left top cor­ner to right bot­tom cor­ner in two dimen­sional array. Input: Two Dimen­sional array Out­put: Print all the paths. Note: At the End of the arti­cle you will…

## Find an Element in 2 dimensional sorted array

Objec­tive : Write an algo­rithm to find an Ele­ment in 2 dimen­sional array where rows and columns are sorted respec­tively. Input: A two dimen­sional sorted array, arrA[][].   Out­put : True or false based…