| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
| Name |
|---|



Can someone pls explain D1? Shayan's solution is very elegant but I'm not able to grasp. Thnx alot in advance
Not exactly the same explanation in the video (as I didn't get it fully myself), but here is my understanding (might be wrong):
Idea: Keep track of which nodes of the tree have correctly placed children (think
bool[n]). If in a permutation, all nodes have their children in the correct positions, then it is a valid DFS order.Note: We can ignore leaf nodes as they don't have children => "Always valid".
We start by checking which nodes have correctly placed children. I.e. For each non-leaf/parent node, we check that:
2**lto the right. Wherelis the level of the parent (0 being the bottom/leaf level).After each swap, we don't need to re-check the whole tree. We can just check, for each of the two swapped nodes (w/ some exceptions for root and leaf nodes) if:
After each swap, if at least one non-leaf node has a misplaced child, the answer is "NO", else, it's a "YES".
Ohh nice! Thanks for the explanation.
Also, I now understand what Shayan meant in the video. A text reference helps a lot. Thnx for taking out the time.
Why so many downvotes? He's doing great work. Taking out time, helping us understand & follow his thinking process & consistent streams for all rounds, with recent weekly topic streams as well. Such good contents & that too for free.
Upvoting and appreciation is the best that we can do! Pls don't downvote guys!
d2 sumbission link?