GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesTwo-Ocean Rainfall

Gamified challenge · Reverse DFS

Two-Ocean Rainfall

heights[r][c] is the height of the island at row r, column c. The west ocean touches the top row and the left column; the east ocean touches the bottom row and the right column. Rain on a cell can flow up, down, left or right to a neighbour that is no higher (equal heights are fine), and from any edge cell straight into the ocean beside it.

Write bothOceans(heights) that returns every cell whose rain can reach both oceans, as a list of [row, col] pairs in any order, each cell once.

Example: [[1, 2, 2, 3], [3, 2, 3, 4], [2, 4, 5, 3], [6, 7, 1, 4]] → [[0, 3], [1, 3], [2, 2], [3, 0], [3, 1]].

Sign in to play Two-Ocean Rainfall

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account