FastPrepLargest Diamond of Ones in a Grid
Problems/Largest Diamond of Ones in a Grid

Largest Diamond of Ones in a Grid

Rippling logoRippling● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Here a diamond is filled: you pick a center cell and a size k, and every cell whose row distance plus column distance from the center is at most k must be inside the grid and equal 1. You return 2k + 1, the number of cells along its diagonal, or 0 when the grid has no 1. Building the diamond from 1s, the limits and the examples are our own choices.

The only question this review lists is about the biggest diamond shape in a 0/1 grid, reported by its diagonal. The author was a campus candidate in Bengaluru who left after the first live algorithm round. The date shows only a month, September 2021.

The review does not say whether the diamond is filled or only an outline, how its diagonal is measured, or what to return when there is none.

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

You are given an m x n grid grid of 0s and 1s.

A diamond of size k (with k >= 0) around a center cell (r, c) is the set of cells (i, j) with |i - r| + |j - c| <= k. In words: every cell you can reach from the center in at most k steps up, down, left or right. A diamond of size 0 is just the center cell.

A diamond counts only if all of its cells are inside the grid and equal to 1. Its diagonal is the line of cells through the center from its top cell to its bottom cell, which has 2k + 1 cells.

Return the diagonal length of the largest diamond that counts, or 0 if the grid has no 1.

Function

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

Examples

Example 1

grid = [[1,0,1,0,0],[0,1,1,1,0],[1,1,1,1,1],[0,1,1,1,1],[0,0,1,0,1]]return = 5
grid
01234010100101110211111301111400101

Take the center at row 2, column 2 and size 2. The 13 cells whose row distance plus column distance from it is at most 2 are all 1 and inside the grid. Its diagonal runs from (0, 2) down to (4, 2), so it is 5 cells long. A diamond of size 3 would need 7 rows, and the grid has only 5.

Example 2

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

A diamond of size 1 needs a center whose 4 neighbors (up, down, left, right) are inside the grid and equal to 1. Only (1, 1) and (1, 2) have all 4 neighbors inside the grid. (1, 2) is 0, and (1, 1) has a 0 below it at (2, 1). So the best is a single 1 cell, a diamond of size 0 with diagonal 1.

Example 3

grid = [[0,0,0,0,0],[0,0,0,0,0]]return = 0
grid
01234000000100000

There is no 1 in the grid, so there is no diamond. The answer is 0.

Constraints

  • m == grid.length and n == grid[i].length for every row
  • 1 <= m, n <= 100
  • grid[i][j] is 0 or 1

More Rippling Phone Screen questions

  • Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
  • Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
  • Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
  • Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
  • Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
  • Factory Cost — Minimum Cost Across StagesStripe · PHONE SCREENStripe interview questions
  • Maximum Rocks on a North-or-East Grid PathGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Maximal SquareAirwallex · PHONE SCREENAirwallex interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions

Interview reports that mention this question

  • Rippling New Grad SDE Interviews: 11 Experiences

Rippling interview experiences

  • Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
  • Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
  • Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
  • Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
  • Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
All Rippling interview questionsSee Rippling hiring insights
Saved
class Solution {
    public int largestDiamond(int[][] grid) {
        // Write your code here.
    }
}
Checking account…