I don't remember the exact statements, but here's the core idea of each problem.
You are given a set of hated digits d (digits from 1 to 9).
A positive integer is invalid if any digit in its decimal representation belongs to d.
Find the nth valid positive integer.
Example 1
d = [5]
n = 5
Valid numbers:
1 2 3 4 6 ...
Answer = 6Example 2
d = [3, 4]
n = 13
Invalid numbers:
3, 4, 13, 14, 23, 24, ...
Valid numbers:
1 2 5 6 7 8 9 10 11 12 15 16 17 ...
Answer = 171 <= |d| <= 81 to 91 <= n <= 10^18Given:
n nodes (0 to n-1)cost[i] is the cost of visiting node isrcdestLFind a path such that:
If no such path exists, output -1.
Initially, there are two channels, each having energy 1.
Each instruction consists of two operations, one for each channel.
Example:
I 3 A 8where:
I x → Increase the channel's energy by xA x → Multiply the channel's energy by x-1After performing both operations, you may perform one transfer:
0 immediately resets to 1.Your goal is to maximize the total energy after processing all instructions.
I don't remember the exact statement because I found it quite confusing.
The only thing I remember is that it was a Tree DP problem with the classic constraint:
You cannot choose both a parent and its child.
It reminded me of LeetCode 337 (House Robber III).