1516. Move Sub-Tree of N-Ary Tree
Given the root of an N-ary tree of unique values, and two nodes of the tree p and q.
You should move the subtree of the node p to become a direct child of node q. If p is already a direct child of q, do not change anything. Node p must be the last child in the children list of node q.
Return the root of the tree after adjusting it.
There are 3 cases for nodes p and q:
- Node q is in the sub-tree of node p.
- Node p is in the sub-tree of node q.
- Neither node p is in the sub-tree of node q nor node q is in the sub-tree of node p.
In cases 2 and 3, you just need to move p (with its sub-tree) to be a child of q, but in case 1 the tree may be disconnected, thus you need to reconnect the tree again. Please read the examples carefully before solving this problem.
Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).
For example, the above tree is serialized as
[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].
1316. Distinct Echo Substrings
Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some string).
1585. Check If String Is Transformable With Substring Sort Operations
Given two strings s and t, transform string s into string t using the following operation any number of times:
- Choose a non-empty substring in s and sort it in place so the characters are in ascending order.
- For example, applying the operation on the underlined substring in “14234” results in “12344”.
Return true if it is possible to transform s into t. Otherwise, return false.
A substring is a contiguous sequence of characters within a string.
1449. Form Largest Integer With Digits That Add up to Target
Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:
- The cost of painting a digit (i + 1) is given by cost[i]
(0-indexed).- The total cost used must be equal to target.
- The integer does not have 0 digits.
Since the answer may be very large, return it as a string. If there is no way to paint any integer given the condition, return “0”.
952. Largest Component Size by Common Factor
You are given an integer array of unique positive integers nums. Consider the following graph:
- There are nums.length nodes, labeled nums[0] to nums[nums.length - 1],
- There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.