Last Updated: 22 Aug, 2025

City Block Partition

Hard
Asked in company
JUSPAY

Problem statement

In the city of Gridopolis, the layout is a 2xN grid of blocks. Each block can be either open for passage (.) or closed for construction (x).

A neighborhood is defined as a set of open blocks that are all connected. Two open blocks are connected if you can travel from one to the other by moving between adjacent blocks, either horizontally or vertically.

You are given that the initial city grid contains at most one connected neighborhood.

Your task is to identify and count the number of critical blocks. A critical block is an open block that, if it were to be closed for construction (changed from . to x), would cause the city to split into exactly 3 separate neighborhoods.


Input Format:
The first line contains a single integer 'n', the number of blocks (columns) in each of the two streets.

The next two lines each contain a string of length 'n', representing the two rows of the city grid. . denotes an open block, and x denotes a closed block.


Output Format:
Print a single integer representing the total count of critical blocks in the grid.


Note:
Only open blocks (.) can be considered for closure to become critical blocks.

The initial grid is guaranteed to have 0 or 1 neighborhood.

A neighborhood requires at least one open block.