FastPrepPaint the Ceiling
Problems/Paint the Ceiling

Paint the Ceiling

Snowflake logoSnowflake● MediumINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You want to build yourself a house. The building company you hired can only build houses with sides from their specific set s. That means they can build you a square house or a rectangular one but if and only if its length and width belong to the sets.

This month, they have a special promotion: they will paint the ceiling of a new house for free... but only if its area is not more than a. You want them to do it for free but you also want to be sure that the house will be comfortable and not too small. How many possible house configurations can you create to have the ceiling painted for free given the side lengths offered?

There is a method to how the company decides what lengths of sides to produce. To determine n lengths of wall segments to offer, they start with a seed value s0, some variables k, b and m, and use the following equation to determine all other side lengths s_i:

s_i = (( k * s_{i-1} + b)mod m+1+s_{i-1}) for 1 <= i < n

Function

paintTheCeiling(s0: int, n: int, k: int, b: int, m: int, a: long) → long

Complete the function paintTheCeiling in the editor.

paintTheCeiling has the following parameters:

  1. s0: an integer, the seed value for side lengths
  2. n: an integer, the number of side lengths to produce
  3. k: an integer
  4. b: an integer
  5. m: an integer
  6. a: a long integer, the maximum area for a free paint job

Returns long integer: the number of possible house configurations

Examples

Example 1

s0 = 2n = 3k = 3b = 3m = 2a = 15return = 5
Example 1 illustration

Now that we have our set of lengths, we can brute force the solution using the following tests assuming a=15:

s=[2,4,6]

s1 s2 s1xs2 s1xs2≤a

2 2 4 True

2 4 8 True

2 6 12 True

4 2 8 True

4 4 16 False

4 6 24 False

6 2 12 True

6 4 24 False

6 6 36 False

There are 5 combinations that will result in a free paint job. Brute force will not meet the time constraints on large sets.

Constraints

  • 1 ≤ n ≤ 6 x 10^6
  • 1 ≤ s_i ≤ 10^9
  • 1 ≤ k, b, m ≤ 10^9
  • 1 ≤ a ≤ 10^18

More Snowflake interview questions

  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
  • Safest Shortest Path Through a GridOA · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
  • Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
  • Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
  • Piecewise Linear Interpolation and ExtrapolationCitadel · PHONE SCREENCitadel interview questions
  • Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
  • Pressing Buttons for Boxes of MoneySusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Find Minimum TimeAlphaSense · OA
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public long paintTheCeiling(int s0, int n, int k, int b, int m, long a) {
      // write your code here
    }

}
Checking account…