1. String Patterns
Given the length of a word (wordLen) and the maximum number of consecutive vowels that it can contain (maxVowels), determine how many unique words can be generated. Words will consist of English alphabetic letters a through z only. Vowels are v {a, e, i, o, u}; consonants are c, the remaining 21 letters. In the explanations, v and c represent vowels and consonants.
Example 1
wordLen = 1
maxVowels = 1
Patterns: {v, c}
That means there are 26 possibilities, one for each letter in the alphabet.
V (5 possibilities) or C (21 possibilities)
Example 2
wordLen = 4
maxVowels = 1
Patterns: {cccc, vccc, cvcc, ccvc, cccv, vcvc, cvcv, vccv}
There are 412,776 possibilities – see below:
C C C C
21 × 21 × 21 × 21 = 194481
V C C C
(5 × 21 × 21 × 21) + (21 × 5 × 21 × 21) + (21 × 21 × 5 × 21) + (21 × 21 × 21 × 5) = 4 × 46305 = 185220
V C V C
(5 × 21 × 5 × 21) + (5 × 21 × 21 × 5) + (5 × 21 × 21 × 5) = 3 × 11025 = 33075
Total:
194481 + 185220 + 33075 = 412776
Example 3
wordLen = 4
maxVowels = 2
In this case, all of the combinations from the previous example are still valid.
- There are 5 additional patterns to consider, three with 2 vowels (vccv, cvvc, ccvv) and two with 3 vowels (vvcc, vvcv).
- Their counts are 3 × (5 × 5 × 21 × 21) = 3 × 11025 = 33075 and 2 × (5 × 5 × 5 × 21) = 2 × 2625 = 5250.
- The total number of combinations then is 412776 + 33075 + 5250 = 451101.
The result may be a very large number, so return the answer modulo (10⁹ + 7).
Note:
While the answers will be within the limit of a 32-bit integer, interim values may exceed that limit. Within the function, you may need to use a 64-bit integer type to store them.
2. Can you count the bit strings?
A bit string is a string of bits that have values of either 1 or 0. A super bit string is a bit string made by flipping zero or more of the 0s in the bit string to 1.
Given k decimal integers, convert each to a bit string that has a given length n. Generate all possible super bit strings of each of the k bit strings. Finally, perform a union of the super bit strings of all the bit strings and determine its size. This is the number to return.
Example
The required bit string length, n = 5, there are k = 2 decimal integers,
bitStrings = [10, 26]
which when converted to strings equal [01010, 11010].
Note that the value 10 had to be padded with a zero to make it the required length.
Original bit string = 01010
Decimal 10
- Flip 0: 01010
- Flip 1: 11010, 01110, 01011
- Flip 2: 11110, 11011, 01111
- Flip 3: 11111
Original bit string = 11010
Decimal 26
- Flip 0: 11010
- Flip 1: 11110, 11011
- Flip 2: 11111
Flipped zeros are highlighted in red.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
