FastPrepPaint Fence Work Split
Problems/Paint Fence Work Split

Paint Fence Work Split

Nutanix logoNutanix● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2019 Nutanix intern report named the first question of its coding challenge only as Paint Fence. The statement used here comes from another 2019 Nutanix online assessment report: cut a fence into pieces for several painters and count the ways. It is not the better-known puzzle with the same name about coloring fence posts.

Readers of that other report disagreed about whether one piece may hold several neighbouring parts that need paint. Here every piece holds exactly one. Its rule for when two splits count as different was also unclear. So here two splits are different when they cut in different places. Every part must belong to a piece, and the count is returned modulo 10^9 + 7. As in that report, a fence with nothing to paint gives 0. The limits are our choice: 1 to 10^5 parts, each 0 or 1.

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

A fence is made of n parts in a row, numbered 0 to n - 1. fence[i] = 1 means part i needs paint, and fence[i] = 0 means it does not.

The painting work is shared by cutting the fence between neighbouring parts into contiguous pieces, one piece per painter. A split is valid when:

  • every part belongs to exactly one piece, and
  • every piece contains exactly one part that needs paint.

Two splits are different when they cut the fence in different places.

Return the number of valid splits modulo 10^9 + 7. If no part needs paint, there is no valid split, so return 0.

Function

countFenceSplits(fence: int[]) → int

Examples

Example 1

fence = [1,0,0,1,0,1]return = 6

Parts 0, 3 and 5 need paint, so there are three pieces. The first cut must fall somewhere between parts 0 and 3: right after part 0, 1 or 2, which is 3 choices. The second cut must fall right after part 3 or part 4, which is 2 choices. That gives 3 * 2 = 6 splits:

  • 1 | 001 | 01
  • 1 | 0010 | 1
  • 10 | 01 | 01
  • 10 | 010 | 1
  • 100 | 1 | 01
  • 100 | 10 | 1

Example 2

fence = [1,1,0,1]return = 2

Parts 0 and 1 both need paint and sit next to each other, so a cut must go between them. The next cut goes right after part 1 or right after part 2. The two splits are 1 | 1 | 01 and 1 | 10 | 1. A piece such as 11 is not allowed because it holds two parts to paint.

Example 3

fence = [0,0,0]return = 0

No part needs paint, so there is no way to give every piece exactly one part to paint. The answer is 0.

Example 4

fence = [0,1,0,0]return = 1

Only part 1 needs paint, so the whole fence is one piece and there is exactly 1 way.

Constraints

  • 1 <= fence.length <= 10^5
  • fence[i] is 0 or 1

More Nutanix Online Assessment questions

  • Good SubsequencesOA · Seen Jul 2026
  • Min Cost to Connect All PointsOA · Seen Jun 2026
  • Digit Changes for a Multiple of 9OA · Seen Aug 2025
  • Gas Station Loop StartOA · Seen Aug 2025
  • Number of Players (for MTS2)OA · Seen Oct 2024
  • Work Schedules (for MTS2)OA · Seen Oct 2024
  • Minimum Operations to Convert ArrayOA · Seen Apr 2024
  • No Adjacent CharactersOA · Seen Apr 2024
  • Build a BST From a ListOA · Seen Nov 2022
  • Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022

Similar questions at other companies

  • Get Triplet CountIBM · OAIBM interview questions
  • Sum of Pipeline Response TimesBloomberg LP · OABloomberg LP interview questions
  • Count Reverse-Digit PairsVisa · OAVisa interview questions
  • Get Triplet CountPoint72 · OAPoint72 interview questions
  • Product of Subset MaximaArcesium · OAArcesium interview questions
  • Find Maximum Number of Balanced CombinationsAmazon · OA
  • Counting Triplets Divisible by DAT&T · OAAT&T interview questions
  • Count Valid TeamsWells Fargo · OAWells Fargo interview questions
  • Next Pascal Row CoefficientIntuit · OAIntuit interview questions
  • Minimum Operations to Flip Exactly K BitsGoogle · OAGoogle interview questions

Interview reports that mention this question

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences

Nutanix interview experiences

  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public int countFenceSplits(int[] fence) {
        // Write your code here.
    }
}
Checking account…