You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// For example, given the equivalency information from s1 = "abc" and s2 = "cde", "acd" and "aab" are equivalent strings of baseStr = "eed", and "aab" is the lexicographically smallest equivalent string of baseStr.
10
+
// Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.
// Explanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".
26
+
// Constraints:
27
+
// 1 <= s1.length, s2.length, baseStr <= 1000
28
+
// s1.length == s2.length
29
+
// s1, s2, and baseStr consist of lowercase English letters.
// 1443. Minimum Time to Collect All Apples in a Tree
2
+
// Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to spend to collect all apples in the tree, starting at vertex 0 and coming back to this vertex.
3
+
// The edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi. Additionally, there is a boolean array hasApple, where hasApple[i] = true means that vertex i has an apple; otherwise, it does not have any apple.
// Explanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.
// Explanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.
// 1519. Number of Nodes in the Sub-Tree With the Same Label
2
+
// You are given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has the label labels[i]).
3
+
// The edges array is given on the form edges[i] = [ai, bi], which means there is an edge between nodes ai and bi in the tree.
4
+
// Return an array of size n where ans[i] is the number of nodes in the subtree of the ith node which have the same label as node i.
5
+
// A subtree of a tree T is the tree consisting of a node in T and all of its descendant nodes.
// Explanation: Node 0 has label 'a' and its sub-tree has node 2 with label 'a' as well, thus the answer is 2. Notice that any node is part of its sub-tree.
10
+
// Node 1 has a label 'b'. The sub-tree of node 1 contains nodes 1,4 and 5, as nodes 4 and 5 have different labels than node 1, the answer is just 1 (the node itself).
// 2246. Longest Path With Different Adjacent Characters
2
+
// You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
3
+
// You are also given a string s of length n, where s[i] is the character assigned to node i.
4
+
// Return the length of the longest path in the tree such that no pair of adjacent nodes on the path have the same character assigned to them.
5
+
// Example 1:
6
+
// Input: parent = [-1,0,0,1,1,2], s = "abacbe"
7
+
// Output: 3
8
+
// Explanation: The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.
9
+
// It can be proven that there is no longer path that satisfies the conditions.
10
+
// Example 2:
11
+
// Input: parent = [-1,0,0,0], s = "aabc"
12
+
// Output: 3
13
+
// Explanation: The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned.
0 commit comments