Glean's 2-Part Snack Bar Grid Question
Glean dresses a classic grid search in office comedy: get from your desk to a snack bar, then do it quietly enough that the noise never reaches a boss. It is two breadth-first searches with a twist that catches people who conflate reachability with noise. Here is the full question, Java for both parts, and a detailed rubric.
The question
An office grid has your desk D, snack bars S, bosses B, walls #, and empty spaces. You move up, down, left, or right, never through walls or bosses.
Part 1: can you reach any snack bar from your desk?
Part 2: snacks have a noise level K. Getting a snack spreads noise K steps in each direction, blocked by walls. Find a snack you can reach and grab without the noise ever reaching a boss (then return to your desk).
Part 1 · Reach a snack bar
Plain BFS from the desk over passable cells, treating walls and bosses as blocked. Return true the moment you step onto a snack bar.
import java.util.*;
class Office {
static final int[][] DIRS = {{-1,0},{1,0},{0,-1},{0,1}};
boolean canReachSnack(char[][] g) {
int[] start = find(g, 'D');
boolean[][] seen = new boolean[g.length][g[0].length];
Deque<int[]> q = new ArrayDeque<>();
q.add(start); seen[start[0]][start[1]] = true;
while (!q.isEmpty()) {
int[] c = q.poll();
if (g[c[0]][c[1]] == 'S') return true;
for (int[] d : DIRS) {
int r = c[0] + d[0], col = c[1] + d[1];
if (!inBounds(g, r, col) || seen[r][col]) continue;
if (g[r][col] == '#' || g[r][col] == 'B') continue; // walls and bosses block movement
seen[r][col] = true; q.add(new int[]{r, col});
}
}
return false;
}
private int[] find(char[][] g, char target) {
for (int r = 0; r < g.length; r++)
for (int c = 0; c < g[0].length; c++)
if (g[r][c] == target) return new int[]{r, c};
return null;
}
private boolean inBounds(char[][] g, int r, int c) {
return r >= 0 && r < g.length && c >= 0 && c < g[0].length;
}
}
Part 2 · Grab it quietly
Two different searches, and conflating them is the mistake. Movement avoids walls and bosses. Noise is a separate bounded BFS from the snack cell, over non-wall cells (walls block noise), out to distance K; if it reaches a boss, that snack is too loud. A snack works if you can reach it and its noise touches no boss. Because the grid does not change, being able to reach the snack means you can return.
boolean canSnackQuietly(char[][] g, int K) {
int[] desk = find(g, 'D');
boolean[][] reachable = reachable(g, desk); // cells you can walk to
for (int r = 0; r < g.length; r++)
for (int c = 0; c < g[0].length; c++)
if (g[r][c] == 'S' && reachable[r][c] && !noiseHitsBoss(g, r, c, K))
return true; // reachable AND quiet
return false;
}
private boolean[][] reachable(char[][] g, int[] start) {
boolean[][] seen = new boolean[g.length][g[0].length];
Deque<int[]> q = new ArrayDeque<>();
q.add(start); seen[start[0]][start[1]] = true;
while (!q.isEmpty()) {
int[] c = q.poll();
for (int[] d : DIRS) {
int r = c[0] + d[0], col = c[1] + d[1];
if (!inBounds(g, r, col) || seen[r][col]) continue;
if (g[r][col] == '#' || g[r][col] == 'B') continue;
seen[r][col] = true; q.add(new int[]{r, col});
}
}
return seen;
}
// Bounded BFS of the noise: walls block it, a boss within K steps is disturbed.
private boolean noiseHitsBoss(char[][] g, int sr, int sc, int K) {
boolean[][] seen = new boolean[g.length][g[0].length];
Deque<int[]> q = new ArrayDeque<>();
q.add(new int[]{sr, sc, 0}); seen[sr][sc] = true;
while (!q.isEmpty()) {
int[] c = q.poll();
if (g[c[0]][c[1]] == 'B') return true; // noise reached a boss
if (c[2] == K) continue; // noise fades after K steps
for (int[] d : DIRS) {
int r = c[0] + d[0], col = c[1] + d[1];
if (!inBounds(g, r, col) || seen[r][col]) continue;
if (g[r][col] == '#') continue; // walls block noise; bosses do not
seen[r][col] = true; q.add(new int[]{r, col, c[2] + 1});
}
}
return false;
}
The two searches differ on purpose: movement treats a boss as an obstacle, noise treats a boss as a target to avoid disturbing. Walls block both. Mixing them up is the single most common failure here.
How Glean scores it
| Dimension | Weak | Strong |
|---|---|---|
| Part 1 BFS | Walks through walls or bosses | Clean BFS over passable cells, stops at a snack |
| Two constraints | Reuses one rule for both searches | Movement avoids bosses, noise avoids disturbing them |
| Noise propagation | Ignores walls or the K bound | Bounded BFS that walls block and that fades at K |
| Completeness | Checks only the nearest snack | Considers every reachable snack |
| Complexity | Unsure of the cost | O(snacks x cells) worst case, stated clearly |
| Edge cases | Breaks with no snack or an adjacent boss | Handles no reachable snack and boss-next-to-snack |
This is one question of 14 pages
Get the full Glean question bank
The full Glean bank carries the coding and search-flavored rounds, each problem with its follow-ups and a rubric, compiled from people familiar with the process and cross-verified across sources.
Glean interview FAQ
What does the Glean coding interview ask?+
Clean algorithmic problems, frequently grid and graph search, string and search-relevance questions that fit Glean's product. The snack bar question is two layered BFS problems with a constraint that separates careful candidates from quick ones.
Is the Glean interview LeetCode-style?+
It overlaps with common patterns (BFS, grids, hashing) but rewards careful reading: the second part hinges on noticing that walls block noise and that you must avoid disturbing a boss, not just avoid walking into one.
How is the Glean coding round scored?+
On correct BFS reachability, a separate bounded BFS for noise propagation that respects walls, distinguishing the two constraints, complexity, and edge cases like no reachable snack or a boss adjacent to it.
Where can I find real Glean interview questions?+
Pichup maintains a 14-page Glean question bank compiled from people familiar with the process, with the coding and search rounds, their follow-ups, and rubrics. The question in this guide is one of them.