We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Greedy
- Mark and Toys
- Discussions
Mark and Toys
Mark and Toys
Sort by
recency
|
1037 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you also have a vidéo explanation here : https://youtu.be/DFQO52aB-qI
Recursive solution in python:
Java
public static int maximumToys(List prices, int k) {
Collections.sort(prices);
int totalPrice = 0; int numToBuy = 0;
while(totalPrice <= k){
} //subtracting 1 since while loop will run one additional time when the value should not be added before ending return numToBuy-1;
Java: