FastPrepLargest Island After One Land Conversion
Problems/Largest Island After One Land Conversion

Largest Island After One Land Conversion

Amazon logoAmazon● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon intern onsite interview. The report describes a disjoint-set problem like making one large island. Our version uses four-direction neighbors and allows at most one change from 0 to 1.

Given a rectangular binary grid, you may change at most one 0 into 1. An island is a four-directionally connected group of ones. Return the largest island area obtainable after the optional conversion.

Function

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

Examples

Example 1

grid = [[1,0],[0,1]]return = 3
grid
01010101

Converting either zero joins both diagonal land cells through the converted cell.

Example 2

grid = [[1,1],[1,0]]return = 4
grid
01011110

Converting the only zero makes the complete grid one island.

Constraints

  • 1 <= grid.length, grid[i].length <= 500
  • grid[i][j] is 0 or 1
  • four-directional adjacency defines an island

More Amazon Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Largest Island After One Land ConversionGoogle · ONSITE INTERVIEWGoogle interview questions
  • Making a Large IslandMeta · ONSITE INTERVIEWMeta interview questions
  • Largest Island After One Land ConversionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Evaluate DivisionPlaud · ONSITE INTERVIEW
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Redundant ConnectionMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Count Connected Components in an Undirected GraphNutanix · ONSITE INTERVIEWNutanix interview questions
  • Connected GroupsFivetran · ONSITE INTERVIEWFivetran interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Minimum Unreachable WarehousesVisa · OAVisa interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int largestIsland(int[][] grid) {
        // Write your code here.
    }

}
Checking account…