Count Pasture Animal Arrangements
Updated
Problem statement
A field is given as an array of strings. G marks a grass cell and . marks a cell without grass. Grass cells connected through shared sides form one pasture. Diagonal contact does not join pastures.
Place exactly one animal in every pasture. For each pasture, choose either a sheep or a cow. Choices in different pastures are independent.
Return the number of different arrangements. Two placements count as the same arrangement when every pasture has the same species in both placements, regardless of the animal's position within that pasture.
For this exercise, assume shared-side connectivity, exactly one animal per pasture, and no distinction between positions within a pasture. If there is no grass, there is one arrangement: place no animals.
Function
countPastureArrangements(field: String[]) → longExamples
Example 1
field = ["G.G","...","G.G"]return = 16The four corner grass cells are four separate pastures. Each has two species choices, giving 2 * 2 * 2 * 2 = 16 arrangements.
Example 2
field = ["GG",".G"]return = 2All three grass cells belong to one connected pasture. It receives either one sheep or one cow, so there are two arrangements.
Constraints
- For this exercise, assume the field has between 1 and 10 rows.
- Each row has between 1 and 10 characters.
- All rows have the same length.
- Each character is
Gor.. - Return the exact count as a 64-bit integer; no modulus is used.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
- Shortest Path in a Binary MatrixGoogle · OAGoogle interview questions
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Minimum MovesHarness · OA
- Shortest Atom Action PathOpenAI · OAOpenAI interview questions
- Count Reachable Values by Halving and DecrementingInfosys · OAInfosys interview questions
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
- Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
- Rotten Oranges / Grid Infection BFSLyft · OALyft interview questions
- Count Islands with DFS and BFSVisa · OAVisa interview questions