# Fractional knapsack

https://practice.geeksforgeeks.org/problems/fractional-knapsack/0 class Solution { public: double fractionalKnapsack(int W, Item arr[], int n) { sort(arr, arr + n, [](const Item &a, const Item &b) { return ((double)a.value / a.weight) > (double)b.value / b.weight; }); int currWeight = 0; double cost = 0; for (int i = 0; i < n; i++) { if (arr[i].weight + currWeight <= W) { currWeight += arr[i].weight; cost += arr[i].value; } else { cost += (arr[i].value / (double)arr[i].

# Find minimum number of coins

https://practice.geeksforgeeks.org/problems/coin-piles/0 class Solution { public: int coinChange(vector<int> &coins, int amount) { int n = coins.size(); int dp[n + 1][amount + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= amount; j++) { if (j == 0) { dp[i][j] = 0; } if (i == 0) { dp[i][j] = INT_MAX - 1; } } } dp[0][0] = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= amount; j++) { if (coins[i - 1] <= j) { dp[i][j] = min(dp[i - 1][j], 1 + dp[i][j - coins[i - 1]]); } else { dp[i][j] = dp[i - 1][j]; } } return dp[n][amount] == INT_MAX - 1 ?