1071. Greatest Common Divisor of Strings
For two strings s and t, we say “t divides s” if and only if s = t + … + t (i.e., t is concatenated with itself one or more times).
Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.
2533. Number of Good Binary Strings
You are given four integers minLenght, maxLength, oneGroup and zeroGroup.
A binary string is good if it satisfies the following conditions:
- The length of the string is in the range [minLength, maxLength].
- The size of each block of consecutive 1’s is a multiple of oneGroup.
- For example in a binary string 00110111100 sizes of each block of consecutive ones are [2,4].
- The size of each block of consecutive 0’s is a multiple of zeroGroup.
- For example, in a binary string 00110111100 sizes of each block of consecutive ones are [2,1,2].
Return the number of good binary strings. Since the answer may be too large, return it modulo 109 + 7.
Note that 0 is considered a multiple of all the numbers.
2445. Number of Nodes With Value One
There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the tree is the node with the label 1.
- For example, if n = 7, then the node with the label 3 has the node with the label floor(3 / 2) = 1 as its parent, and the node with the label 7 has the node with the label floor(7 / 2) = 3 as its parent.
You are also given an integer array queries. Initially, every node has a value 0 on it. For each query queries[i], you should flip all values in the subtree of the node with the label queries[i].
Return the total number of nodes with the value 1 after processing all the queries.
Note that:
- Flipping the value of a node means that the node with the value 0 becomes 1 and vice versa.
- floor(x) is equivalent to rounding x down to the nearest integer.
2450. Number of Distinct Binary Strings After Applying Operations
You are given a binary string s and a positive integer k.
You can apply the following operation on the string any number of times:
- Choose any substring of size k from s and flip all its characters, that is, turn all 1’s into 0’s, and all 0’s into 1’s.
Return the number of distinct strings you can obtain. Since the answer may be too large, return it modulo 109 + 7.
Note that:
- A binary string is a string that consists only of the characters 0 and 1.
- A substring is a contiguous part of a string.
2510. Check if There is a Path With Equal Number of 0’s And 1’s
You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1).
Return true if there is a path from (0, 0) to (m - 1, n - 1) that visits an equal number of 0’s and 1’s. Otherwise return false.