2237. Count Positions on Street With Required Brightness
You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from
[max(0, positioni - rangei), min(n - 1, positioni + rangei)] (inclusive).The brightness of a position p is defined as the number of street lamps that light up the position p. You are given a 0-indexed integer array requirement of size n where requirement[i] is the minimum brightness of the ith position on the street.
Return the number of positions i on the street between 0 and n - 1 that have a brightness of at least requirement[i].
1666. Change the Root of a Binary Tree
Given the root of a binary tree and a leaf node, reroot the tree so that the leaf is the new root.
You can reroot the tree with the following steps for each node cur on the path starting from the leaf up to the root excluding the root:
- If cur has a left child, then that child becomes cur’s right child.
- cur’s original parent becomes cur’s left child. Note that in this process the original parent’s pointer to cur becomes null, making it have at most one child.
Return the new root of the rerooted tree.
Note: Ensure that your solution sets the Node.parent pointers correctly after rerooting or you will receive “Wrong Answer”.
1794. Count Pairs of Equal Substrings With Minimum Difference
You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions:
- 0 <= i <= j < firstString.length
- 0 <= a <= b < secondString.length
- The substring of firstString that starts at the ith character and ends at the jth character (inclusive) is equal to the substring of secondString that starts at the ath character and ends at the bth character (inclusive).
- j - a is the minimum possible value among all quadruples that satisfy the previous conditions.
Return the number of such quadruples.
Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. You can return the answer in any order.
Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.
A code snippet is valid if all the following rules hold:
- The code must be wrapped in a valid closed tag. Otherwise, the code is invalid.
- A closed tag (not necessarily valid) has exactly the following format :
<TAG_NAME>TAG_CONTENT</TAG_NAME>. Among them,is the start tag, and is the end tag. TheTAG_NAMEin start and end tags should be the same. A closed tag is valid if and only if theTAG_NAMEandTAG_CONTENTare valid.- A valid
TAG_NAMEonly contain upper-case letters, and has length in range [1,9]. Otherwise, the TAG_NAME is invalid.- A valid
TAG_CONTENTmay contain other valid closed tags, cdata and any characters (see note1) EXCEPT unmatched <, unmatched start and end tag, and unmatched or closed tags with invalidTAG_NAME. Otherwise, theTAG_CONTENTis invalid.- A start tag is unmatched if no end tag exists with the same
TAG_NAME, and vice versa. However, you also need to consider the issue of unbalanced when tags are nested.- A < is unmatched if you cannot find a subsequent >. And when you find a < or </, all the subsequent characters until the next > should be parsed as TAG_NAME (not necessarily valid).
- The cdata has the following format :
<![CDATA[CDATA_CONTENT]]>. The range of CDATA_CONTENT is defined as the characters between <![CDATA[ and the first subsequent ]]>.CDATA_CONTENTmay contain any characters. The function of cdata is to forbid the validator to parseCDATA_CONTENT, so even it has some characters that can be parsed as tag (no matter valid or invalid), you should treat it as regular characters.