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

Maximum Fish in a Grid

NVIDIA logoNVIDIA● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA onsite interview for a full-time role. The report names the well-known grid-fishing exercise without repeating its statement. We followed that exercise. We wrote examples and a runnable interface to make the rules clear.

Our version is about 95% the same as the reported question.

A rectangular integer matrix grid describes land and water: 0 is land, and each positive value is the fish count in a water cell.

Choose any water cell as a starting point. You may collect all fish in a visited cell and move repeatedly between water cells sharing an edge. A cell’s fish can be collected only once.

Return the largest total obtainable from one starting point, or 0 if every cell is land. Diagonal movement and movement through land are forbidden.

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 component with 3 and 4 fish totals 7, more than each other component.

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 positive cells are disconnected; either start collects 1.

Example 3

grid = [[2,0,3],[4,5,0]]return = 11
grid
01202031450

The connected cells 2,4 and 5 total 11; the 3-fish cell is isolated.

Constraints

  • 1 <= grid.length <= 10.
  • 1 <= grid[r].length <= 10; all rows have equal length.
  • 0 <= grid[r][c] <= 10.

More NVIDIA Onsite Interview questions

  • Check Endianness Of A Byte ArrayONSITE INTERVIEW · Seen Sep 2026
  • Implement MallocONSITE INTERVIEW · Seen Sep 2026
  • Implement PrintfONSITE INTERVIEW · Seen Sep 2026
  • Merge Two Arrays Into Sorted OrderONSITE INTERVIEW · Seen Sep 2026
  • Middle Node Of A Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Ping Reply TrackingONSITE INTERVIEW · Seen Sep 2026
  • Reverse A StringONSITE INTERVIEW · Seen Sep 2026
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • First Register Overflow TickONSITE INTERVIEW · Seen May 2024
  • Two-Egg DroppingONSITE INTERVIEW · Seen May 2024

Similar questions at other companies

  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Bridge Between Two IslandsCompass International Holdings · ONSITE INTERVIEWCompass International Holdings interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Number of Closed IslandsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Foreground Region SizesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • The MazeGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int findMaxFish(int[][] grid) {
        return 0;
    }
}
Checking account…