FastPrepCount Starts Reaching a Grid Maximum
Problems/Count Starts Reaching a Grid Maximum

Count Starts Reaching a Grid Maximum

Duolingo logoDuolingo● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes always climbing to the best of the eight neighbors, and asks how many starting cells reach a global maximum. Our version is about 99% the same as the reported question.

You are given a rectangular height matrix. From a cell, inspect all eight neighboring cells and move to the strictly higher neighbor with greatest height. If several eligible neighbors have that height, choose the one with smaller row, then smaller column. Stop when no higher neighbor exists.

Return the number of starting cells whose path ends at any cell whose value equals the global maximum of the matrix.

Function

countStartsReachingMaximum(heights: int[][]) → int

Examples

Example 1

heights = [[1,2],[3,4]]return = 4
heights
01012134

Every cell moves directly or indirectly to the global maximum 4.

Example 2

heights = [[9,1,8],[1,7,1],[6,1,5]]return = 7
heights
012091811712615

Seven starts reach 9; the cell 8 and the adjacent 1 that chooses it stop at the non-global local maximum.

Constraints

  • 1 <= heights.length, heights[0].length
  • heights.length * heights[0].length <= 200000
  • -1000000000 <= heights[r][c] <= 1000000000
  • All rows have equal length.

More Duolingo Phone Screen questions

  • Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
  • Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
  • Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
  • Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
  • Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
  • Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
  • User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
  • Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
  • Validate a Mahjong Hand PartitionPHONE SCREEN · Seen Nov 2025
  • Directional Tiles: Find a Valid Reconfiguration PathPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Longest Consecutive Decreasing Grid PathGoogle · PHONE SCREENGoogle interview questions
  • Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
  • Find a Word Path Moving Right or DownIntuit · OAIntuit interview questions
  • Longest Increasing Path in a MatrixVisa · ONSITE INTERVIEWVisa interview questions
  • Longest Increasing Path in a MatrixNutanix · OANutanix interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions

Duolingo interview experiences

  • Duolingo interviews · November 2026
  • Duolingo SWE Interview Questions: 3 Experiences
All Duolingo interview questionsSee Duolingo hiring insights
Saved
class Solution {
    public int countStartsReachingMaximum(int[][] heights) {
        // Write your code here.
    }

}
Checking account…