Snowflake OA Backend Intern
Level: Internship
Education: Mid-bachelors
Years of Experience: 0
Questions Asked:
Problem 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.
Examples:
- wordLen = 1, maxVowels = 1 That means there are 26 possibilities, one for each letter in the alphabet.
- wordLen = 4, maxVowels = 1 Patterns: (cccc, vccc, cvcc, ccvc, cccv, vcvc, cvcv, vccv) There are 412,776 possibilities – see below: [Various pattern calculations shown in the image] (21 * 21 * 21 * 21) = 194481 (5 * 21 * 21 * 21) + (21 * 5 * 21 * 21) + (21 * 21 * 5 * 21) + (21 * 21 * 21 * 5) = 4 * 46305 = 185220 (5 * 21 * 5 * 21) + (21 * 5 * 21 * 5) + (5 * 21 * 21 * 5) = 3 * 11025 = 33075 194481 + 185220 + 33075 = 412776 possible solutions.
Problem 2: Vowel Substring
Given a string composed of lowercase letters within the ASCII range ‘a’-‘z’, determine the number of substrings that consist solely of vowels, where each vowel appears at least once. The vowels are (‘a’, ‘e’, ‘i’, ‘o’, ‘u’). A substring is defined as a contiguous sequence of characters within the string.
Example: s = ‘aeioaexaaeiou’
There is a substring to the left that is made of vowels, ‘aeioa’ which is followed by an ‘x’. Since ‘x’ is not a vowel, it cannot be included in the substring, and this substring does not contain all of the vowels. It is not a qualifying substring.
Moving to the right, there are four substrings that do qualify: ‘aeiou’, ‘aaeiou’, ‘aeiou’ and ‘eiou’.
Function Description: Complete the function vowelSubstring in the editor with the following parameter(s):
- string s: a string
Returns:
- int: the number of substrings that consist of vowels only (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) where every vowel appears at least once
Constraints:
- 1 ≤ size_of(s) ≤ 10⁵
- s[i] is in the range ascii(‘a’-‘z’) (where 0 ≤ i < size_of(s))
Problem 3: Maximum Order Volume
During the day, a supermarket will receive calls from customers who want to place orders. The supermarket manager knows in advance the number of calls that will be attempted, the start time, duration, and order volume for each call. Only one call can be in progress at any one time, and if a call is not answered, the caller will not call back. The manager must choose which calls to service in order to maximize order volume.
Example: start = [10, 5, 15, 18, 30] duration = [30, 12, 20, 35, 35] volume = [50, 51, 20, 25, 10]
The above data as a table:
Caller | Start time | Duration | Order volume |
---|---|---|---|
1 | 10 | 30 | 50 |
2 | 5 | 12 | 51 |
3 | 15 | 20 | 20 |
4 | 18 | 35 | 25 |
5 | 30 | 35 | 10 |
The first call will start at time = 10, and last until time = 40. The second call will start at time = 5, and last until time = 17. The third call will start at time = 15, and last until time = 35. The fourth call will start at time = 18, and last until time = 53. The fifth call will start at time = 30, and last until time = 65.
The first call completely overlaps the second and third calls, and partially overlaps the fourth and fifth calls. Choosing calls that do not overlap, and answering the 2nd and 4th calls leads to the maximum total order volume of 51 + 25 = 76.