Reported October 2026
Googlesimulation

Fountain Safety

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

The Google OA reported in October 2026, Fountain Safety, looks like a simple simulation until one edge case wrecks your output. Fountains don't water their own position, and a position can be hit by two fountains at once. If you have this OA in the next day or two, know that the real work is scanning outward from each fountain and stopping at the first strictly taller cell. That's an array problem with a sharp boundary rule. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the logic below is short enough to carry in your head.

The problem

You are given an integer array terrain of length n, where terrain[i] is the height at position i. You are also given a strictly increasing integer array fountains containing the positions of the fountains.
A fountain at position f emits water at level terrain[f] in both directions. In either direction, its water crosses consecutive positions whose height is less than or equal to that level and stops before the first position whose height is strictly greater.

Examples
Example 1
terrain = [2, 1, 3, 2, 1, 1]
fountains = [0, 3]
return = [0, 1, 0, 0, 1, 1]
Fountain 0 waters position 1, then stops before the higher position 2. Fountain 3 waters positions 4 and 5. Neither fountain waters its own position.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core move is a two-direction scan from each fountain. Start at f, read level = terrain[f], walk left while terrain[j] <= level, then walk right the same way. Mark each reached position, but skip f itself, since the example shows a fountain doesn't water its own position. The edge case that breaks a naive solution is the comparison. Water crosses heights less than or equal to the level, and stops only at strictly greater. Use <= for crossing, not <. Another trap is overwriting: if two fountains reach one cell, the result must stay 1, not toggle or add. Use a boolean or set it to 1. The brute force costs O(n * k), which is fine if constraints are small. If they're large, precompute next-greater positions with a monotonic stack. If you freeze during the live OA, StealthCoder is the hedge that reads the problem and hands you the scan.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Fountain Safety cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Fountain Safety FAQ

What's the trick in Fountain Safety?+

Scan left and right from each fountain using the fountain's own height as the water level. Keep going while the next height is less than or equal to the level, and stop at the first strictly greater one. Mark reached cells as 1, and leave the fountain's own cell alone.

Does a fountain water its own position?+

No. In the example, fountain 0 and fountain 3 both leave their own positions at 0 in the output. Start your scan one step away from the fountain, or skip the index when marking. This is the detail most people miss when they skim the statement.

What happens when two fountains reach the same cell?+

The cell is just watered, so the answer stays 1. Don't add or toggle. Assign 1 directly. Note a fountain's own cell can still be watered by a different fountain, since the rule only says a fountain doesn't water itself.

Is brute force good enough, or do I need a stack?+

Brute force is O(n * k) in the worst case, which is fine for small inputs. If the constraints look big, a monotonic stack gives the nearest strictly greater position on each side, then you fill ranges with a difference array. Check the constraints before choosing.

How do I prepare for this in 48 hours?+

Write the two-pointer style outward scan from memory and test it on the example. Then test equal heights, a fountain at index 0, and a fountain at n-1. Those cases cover the strict versus non-strict comparison and boundary handling, which is where this problem actually bites.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it