#3529
Count Cells in Overlapping Horizontal and Vertical Substrings
expert · 1155 · lc medium +32 · 27% accepted · 62 likes · top 5%
Description
Given character matrix grid (size m x n) and string pattern:
- A horizontal match reads left-to-right, wrapping to the next row\'s start when reaching the end of a row (no wrap from last row to first).
- A vertical match reads top-to-bottom, wrapping to the next column\'s top when reaching a column\'s bottom (no wrap from last column to first).
Count cells that belong to at least one horizontal match of pattern and at least one vertical match of pattern.
Return that count.
Code
1
2
3