LinkedIn Internship | OA
Anonymous User
2969

I don't remember the exact question but it goes something like this:
You have some comic books and some coins, you can trade comic books for a fiction book or you can sell a comic book + coins needed to get a fiction book.
coinsOffered is the number of coins offered if you sell a comic book.
You want to get as many fiction books as possible.

You had 10 comic books, coins you have 10, coinsNeeded: 1, coinsOffered: 1.
You can trade all your comic books for fiction books in this case, you don't need to sell any.

You have 4 comic books, coins you have: 8, coinsNeeded: 4, coinsOffered: 3
You can trade 2 comic books for fiction books. If you try to sell one comic book, your coins will go up to 11 which is not enough for 3rd fiction book - so the answer is 2.

It seems like it needs a greedy solution but I couldn't get to it during the assessment. If you have seen the question before or were able to solve it, any pointers will be helpful

Comments (5)