Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 B
Problem: In a grid of 0s and 1s, a connected region is a group of 1-cells that are connected when moving to 8 neighbours (up, down, left, right and the four diagonals). Count the regions in: 11000 11011 00100 01100 10001
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
With 8-connectivity, diagonal neighbours merge regions that 4-connectivity would split. Counting with only horizontal and vertical moves gives a larger number.
More Coding Interview Problems questions
- Problem: A rooted tree is given by parent array p = [-1, 0, 0, 1, 1, 2, 5, 5, 3] for nodes 0–8 (node 0 is the root). How many nodes are at…
- Problem: A max-heap starts with the values 9, 8, 6, 5, 4, 3, 1 (inserted in that order). Then three times in succession: pop the maximum…
- Problem: The string "abcbaxyzzyxq" is given. What is the minimum number of characters that must be deleted so the remaining string is a…
- Problem: A string is formed by writing the letters of "kayak" then "level" then "rotor". How many substrings of length 5 of…
- Problem: Starting from the string "00000" of five zeros, operations flip a substring: each operation chooses positions l ≤ r and flips…
- Problem: The number of ways to choose 3 vertices from a graph's vertex set of size n = 12 such that no two chosen vertices are adjacent in…