FastPrepCount Pasture Animal Arrangements
Problems/Count Pasture Animal Arrangements

Count Pasture Animal Arrangements

Intuit logoIntuit● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Intuit new grad online assessment. The report says that adjacent grass blocks form one pasture, and each pasture can have one sheep or one cow. The author says they did not read the task carefully.

Here, G marks grass, neighbors share a side, and every pasture gets exactly one sheep or cow. Animal positions do not change an arrangement. No grass gives one empty arrangement. The field is at most 10 by 10, so the exact count fits a 64-bit integer.

Our version is about 60% the same as the reported question.

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[]) → long

Examples

Example 1

field = ["G.G","...","G.G"]return = 16
field
0120G.G1...2G.G

The 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 = 2
field
010GG1.G

All 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 G or ..
  • 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

Interview reports that mention this question

  • Intuit OA: What It Tests (2026)

Intuit interview experiences

  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public long countPastureArrangements(String[] field) {
        // Write your code here
    }
}
Checking account…