Lines of Two Kinds of Cookies
Updated
Problem statement
You have a sugar cookies and b ginger cookies. Cookies of the same kind look exactly alike. You pick k of these cookies and put them in a straight line.
Two lines are different if at least one spot holds a different kind of cookie. Swapping two cookies of the same kind does not make a new line.
Return the number of different lines you can make.
Function
countCookieLines(a: int, b: int, k: int) → longExamples
Example 1
a = 6b = 8k = 7return = 127This is the interview case. Each of the 7 spots holds a sugar or a ginger cookie, so without any limit there would be 2^7 = 128 lines.
There are 8 ginger cookies, more than 7, so ginger never runs out. There are only 6 sugar cookies, so the one line with 7 sugar cookies is impossible. The answer is 128 - 1 = 127.
Example 2
a = 2b = 2k = 3return = 6Without limits there are 2^3 = 8 lines. With only two cookies of each kind, the lines with three sugar cookies or three ginger cookies cannot be made. The answer is 8 - 2 = 6.
Example 3
a = 1b = 3k = 4return = 4There are only 3 ginger cookies, so a line of 4 must use the one sugar cookie. The only choice left is where it goes: one of the 4 spots. The answer is 4.
Constraints
0 <= a, b <= 501 <= k <= 50k <= a + b
More Susquehanna International Group (SIG) Online Assessment questions
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
Similar questions at other companies
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Subarray SumVisa · OAVisa interview questions
- Drawing EdgeWeRide · OAWeRide interview questions
- Drawing EdgeIBM · OAIBM interview questions
- Drawing EdgeSnowflake · OASnowflake interview questions
- Process SchedulingCitadel · OACitadel interview questions
- Unique Digits in RangeAgoda · OAAgoda interview questions
- Ordered Book Displays with a Featured BookIMC Trading · OAIMC Trading interview questions
- Find Max Number of PairsRoblox · OARoblox interview questions
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions