Count Connect-Four Scoring Lines
Updated
Problem statement
Given a rectangular board grid, return the number of scoring lines on it. The board is never empty. A dot (.) is an empty cell, and each uppercase English letter is one piece type.
A scoring line is four cells next to each other in one straight line, all holding the same letter. The line can run horizontally, vertically, diagonally down-right, or diagonally down-left. Each set of four cells counts once. Overlapping sets count separately, so five equal letters in a straight run give two scoring lines.
The board may not match a real game with gravity or a move history. You do not need to check that.
Function
countScoringLines(grid: String[]) → intExamples
Example 1
grid = [".......",".......",".......",".......","AAAA...","BBBB..."]return = 2The row AAAA... and the row BBBB... each hold one horizontal line of four. There are no other lines, so the answer is two.
Example 2
grid = ["AAAAA"]return = 2The five A cells hold two overlapping lines of four: one starts at column 0 and one starts at column 1. So the answer is two.
Example 3
grid = ["X..Y..Z","X.Y...Z","XY....Z","Y.....Z"]return = 2The Y cells run diagonally down-left from the top row to the bottom-left corner, and the Z cells fill the last column. The X cells stop after three, so the answer is two.
Constraints
1 <= grid.length <= 1000.1 <= grid[r].length <= 1000.- Every row has the same length, and the board has at most
200000cells. - Every cell is
.or an uppercase English letter.
More Bloomberg LP Phone Screen questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Validate a Chess Bishop, Rook, or Queen MoveGlean · PHONE SCREENGlean interview questions
- Trace an Eight-Direction Robot Until BlockedPinterest · PHONE SCREENPinterest interview questions
- Excel Training Data and Model Response AuditMicrosoft · PHONE SCREENMicrosoft interview questions
- Mark a Queen’s Attack BoardMotive · PHONE SCREENMotive interview questions
- Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
- Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
- S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
- Zigzag Board Adjacent SwapsUber · PHONE SCREENUber interview questions
- Longest Consecutive Same-Color LineGoogle · PHONE SCREENGoogle interview questions