InterviewDB Question

Buy Books: Compute Minimum Cost to Purchase a Reading List Given Volume Discounts

Question Details

Problem A bookstore sells a series of 8 books. If you buy k distinct books in one purchase, you get a discount: 1 book: 0%, 2 books: 5%, 3 books: 10%, 4 books: 20%, 5: 25%. Each book costs $8. Given a list of books (by index 1-8) a customer wants to buy (with repetition), compute the minimum total cost. Example: Approach Greedy with frequency counts tends to over-optimize; dynamic programming on the count vector is more reliable. Count frequency of each title, then use DP over possible group siz…

Full Details

🔒

Unlock all Square/Block questions

Full insider details, leaked discussions, and candidate experiences.

or every company, $100/year →

About This Question

This is a reported interview question from a square/block interview.

It covers the following topics: Data Scientist, Coding, Greedy, Dynamic Programming .