[LeetCode] Find Subtree Sizes After Changes

3331. Find Subtree Sizes After Changes

You are given a tree rooted at node 0 that consists of n nodes numbered from 0 to n - 1. The tree is represented by an array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.

You are also given a string s of length n, where s[i] is the character assigned to node i.

We make the following changes on the tree one time simultaneously for all nodes x from 1 to n - 1:

  • Find the closest node y to node x such that y is an ancestor of x, and s[x] == s[y].
  • If node y does not exist, do nothing.
  • Otherwise, remove the edge between x and its current parent and make node y the new parent of x by adding an edge between them.

Return an array answer of size n where answer[i] is the size of the subtree rooted at node i in the final tree.

A subtree of treeName is a tree consisting of a node in treeName and all of its descendants.

Read more
[LeetCode] Find the Original Typed String I

3330. Find the Original Typed String I

Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.

Although Alice tried to focus on her typing, she is aware that she may still have done this at most once.

You are given a string word, which represents the final output displayed on Alice’s screen.

Return the total number of possible original strings that Alice might have intended to type.

Read more
[AtCoder] F - MST QueryRead more
[AtCoder] C - Sum of Abs 2Read more
[AtCoder] F - Useless for LISRead more
[AtCoder] G - Merchant TakahashiRead more
[AtCoder] E - Jump Distance SumRead more
[Codeforces] Round 977 (Div. 2, based on COMPFEST 16 - Final Round) C1. Adjust The Presentation (Easy Version)Read more
[Codeforces] Round 977 (Div. 2, based on COMPFEST 16 - Final Round) C2. Adjust The Presentation (Hard Version)Read more
[Codeforces] Round 976 (Div. 2) and Divide By Zero 9.0 D. Connect the DotsRead more