[LeetCode] Maximize Total Tastiness of Purchased Fruits

2431. Maximize Total Tastiness of Purchased Fruits

You are given two non-negative integer arrays price and tastiness, both arrays have the same length n. You are also given two non-negative integers maxAmount and maxCoupons.

For every integer i in range [0, n - 1]:

  • price[i] describes the price of ith fruit.
  • tastiness[i] describes the tastiness of ith fruit.

You want to purchase some fruits such that total tastiness is maximized and the total price does not exceed maxAmount.

Additionally, you can use a coupon to purchase fruit for half of its price (rounded down to the closest integer). You can use at most maxCoupons of such coupons.

Return the maximum total tastiness that can be purchased.

Note that:

  • You can purchase each fruit at most once.
  • You can use coupons on some fruit at most once.
Read more
[LeetCode] Number of Good Paths

2421. Number of Good Paths

There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.

You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.

A good path is a simple path that satisfies the following conditions:

  1. The starting node and the ending node have the same value.
  2. All nodes between the starting node and the ending node have values less than or equal to the starting node (i.e. the starting node’s value should be the maximum value along the path).

Return the number of distinct good paths.

Note that a path and its reverse are counted as the same path. For example, 0 -> 1 is considered to be the same as 1 -> 0. A single node is also considered as a valid path.

Read more
[AtCoder] D - XOR WorldRead more
[AtCoder] A - Colorful SubsequenceRead more
[AtCoder] D - Decayed BridgesRead more
[AtCoder] C - Synthetic KadomatsuRead more
[AtCoder] B - ReversiRead more
[Codeforces] Round #173 (Div. 2) C. XOR and ORRead more
[Codeforces] Round #177 (Div. 1) B. Polo the Penguin and HousesRead more
[Codeforces] Round #173 (Div. 2) B. Painting EggsRead more