Ordered Book Displays with a Featured Book
Updated
Problem statement
A library owns n distinct books. Create a display by choosing k different books and arranging them in a specific order.
After arranging the display, choose exactly one of its books as the featured Book of the Month. Two results differ if their ordered display differs or their featured book differs.
Return the number of possible display-and-feature choices. A book cannot appear twice in a display, and the featured book must belong to the display.
For this exercise, assume n and k generalize the thirty-book, four-position case in the first example. If k = 0 or k > n, return 0: no featured displayed book can be selected.
Complete countBookDisplays(n, k) and return the exact count as a signed 64-bit integer.
Function
countBookDisplays(n: int, k: int) → longExamples
Example 1
n = 30k = 4return = 2630880The four ordered positions have 30 * 29 * 28 * 27 = 657720 possible assignments. Each has four possible featured books, so the count is 657720 * 4 = 2630880.
Example 2
n = 3k = 2return = 12The ordered pairs are [A,B], [A,C], [B,A], [B,C], [C,A], and [C,B]. Each pair has two featured choices, giving 12.
Example 3
n = 4k = 0return = 0An empty display contains no book to feature.
Example 4
n = 2k = 3return = 0Three distinct displayed books cannot be selected from only two books.
Constraints
- For this exercise, assume
0 <= n <= 50and0 <= k <= 10. - Books are distinct and may be selected only once.
- The exact answer and the intermediates in the presented solutions fit in signed 64-bit arithmetic.
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Enough Muffins for the LineSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- 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
- Find Max Number of PairsRoblox · OARoblox interview questions
- Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions