FastPrepMaximum Number of Fish in a Grid
Problems/Maximum Number of Fish in a Grid

Maximum Number of Fish in a Grid

Globalization Partners logoGlobalization Partners● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report links the well-known Maximum Number of Fish in a Grid task and describes a DFS solution. Our version is about 100% the same as the reported question.

You are given a zero-indexed integer matrix grid. A cell with value 0 is land; a positive cell is water containing that many fish.

A fisher may start at any water cell, catch all fish in the current cell, and move any number of times to an orthogonally adjacent water cell. Return the maximum number of fish obtainable by choosing the starting cell optimally, or 0 when the grid contains no water cell.

Function

findMaxFish(grid: int[][]) → int

Examples

Example 1

grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]return = 7
grid
012300210140032100430320

The water cells containing 3 and 4 on the right are connected, giving a component total of 7.

Example 2

grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]return = 1
grid
012301000100002000030001

The two water cells are disconnected and each contains one fish, so the best component has total 1.

Example 3

grid = [[5,1,0],[0,2,3]]return = 11
grid
01205101023

All four positive cells are joined orthogonally, so the component totals 5 + 1 + 2 + 3 = 11.

Constraints

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 10
  • 0 <= grid[i][j] <= 10

More Globalization Partners Onsite Interview questions

  • Binary Tree Maximum Path SumONSITE INTERVIEW · Seen Jun 2026
  • Recover Binary Search TreeONSITE INTERVIEW · Seen Jun 2026

Similar questions at other companies

  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Max Area of IslandGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Max Area of IslandRoku · ONSITE INTERVIEWRoku interview questions
  • Number of IslandsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Max Area of IslandBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Maximum Area of IslandSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
  • Count Connected IslandsTwitch · ONSITE INTERVIEWTwitch interview questions
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Count Islands with Eight-Direction AdjacencyAmazon · PHONE SCREEN
See Globalization Partners hiring insights
Saved
class Solution {
    public int findMaxFish(int[][] grid) {
        // write your code here
    }
}
Checking account…