Data Structures & AlgorithmsHardICPC regional · GATE CS top band
A 6 × 6 grid (rows top to bottom, '#' = land, '.' = water): .#.... / ..#.#. / ##...# / #...#. / ##...# / ..##.#. Land cells form an island when they are connected through sides only (up, down, left, right; diagonal contact does not connect). What is the number of cells in the largest island?
- A. 9
- B. 14
- C. 6
- D. 5
Correct answer: D. 5
The largest side-connected island has 5 cells; allowing diagonal contact would merge pieces and report 9, which is the common mistake.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–D (3), A–E (8), B–C (6), B–D (6), B–E (8), B–F (7), C–F (3), D–F (7)…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: A–B (1), A–D (1), A–F (1), B–E (1), A–E (1), A–C (1)…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–G (1), A–H (1), B–C (1), C–D (1), C–E (1), C–G (1), F–G (1)…
- Array A = [1, 16, 18, 4, 25, 5, 13, 21]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 23? (A trie with subtree counts answers this…
- 5 × 5 grid, rows top to bottom ('#' = blocked, '.' = open): ..... / ..#.. / ..... / ..#.. / #..... Count the paths from top-left to…
- Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–C (5), A–E (5), A–F (4), B–D (6), B–E (1), B–F (6), B–G (8), C–G…