Problem Statement: Samurai has a grid of chocolates with dimensions m x n. Positioned at the top-left corner (0, 0) is Samurai's friend Charlie, and at the top-right corner (0, n - 1) is his other friend Jack.
Both friends can move downward, collecting chocolates from the cells they pass through. When a friend passes through a cell, all chocolates in that cell are picked, reducing the count to zero.
Charlie and Jack, when at coordinates (i, j), have the option to move to one of three adjacent cells in the row below:
They must stay inside the grid while moving. If both friends end up in the same cell, only one of them gets the chocolates.
Your task is to determine the maximum number of chocolates Samurai can collect with the help of Charlie and Jack, following these rules.
Example 1: Input:
m = 3, n = 3
grid = [[10, 20, 10],
[30, 20, 10]...
(Array continues based on standard matrix inputs)
Problem Statement: You are given a grid of dimension m by n of integers consisting of 0's and 1's. 1 represents land and 0 represents water.
Your task is to find the number of distinct islands where a group of connected 1s (horizontally or vertically) forms an island.
Note:
Example 1: Input:
m (rows) = 3, n (columns) = 3,
grid = { { 1, 0, 0 },
{ 1, 0, 1 },
{ 0, 0, 1 } }