Rank Name Score Finish Time Q1 (3) Q2 (4) Q3 (5) Q4 (6)
323 / 12700 YoungForest 18 1:00:46 0:11:32 🐞1 0:27:23 0:42:54 🐞1 0:50:46

After 6 weeks of cruel daily check in, I am finally free from solve the daily problem everyday in cruel group. The condition of free is that the contest rank is within top 500 in the world and solving all 4 problems in weekly contest. Congratulations on me.

## 2047. Number of Valid Words in a Sentence

Sign on problem.
It is more difficult than usual. The corner case needs to be careful of. For example, ‘-‘ is not a valid word.

Time complexity: O(N),
Space complexity: O(N).

A easier solution is `re`, aka regular expression.

Time complexity: O(N),
Space complexity: O(N).

## 2048. Next Greater Numerically Balanced Number

Many people’s solutions are “Accepted” using brute force. Iterate every number greater than n, and check if it is numerically balanced.
I proposed a better solution in contest. Because of `0 <= n <= 10^6`, I manually enumerate all numerically balanced numbers and find the next greater one. The possible balance numbers is countable. One trick here is using `permutations` to iterate all permutations of a string.

Time complexity: O(13 * 6!),
Space complexity: O(6!).

## 2049. Count Nodes With the Highest Score

1. We could use `DFS` to calculate every subtrees’ size.
2. Calculate the score of each node. 3 possible states when deleting a node: two children, one child, no child. A corner case is the root node. It do not have the parent.
3. Find the highest score and its frequency.

A corner case is that the products could overflow `int`. It is `10^5 * 10^5` maximally. `long long` could avoid this runtime error easily.

Time complexity: O(n),
Space complexity: O(n).

## 2050. Parallel Courses III

Typical topo sort.
With `priority_queue`, we could iterate every course end events from time increasing.

Time complexity: O(N * logN),
Space complexity: O(N).

Welcome to my other publishing channels