When and how whiteboarding practice is implemented will be up to your teacher. Below is a recommended prompt.
For this section's whiteboarding lesson, we'll focus on using arrays and loops to assess a string.
As the interviewee:
As the interviewer:
Prompt 1: Write a method that takes in a string and counts each instance of each letter in the string. It should return an array of integers, where each integer represents the number of occurrences of a letter. The array should start with the number of a
s, and end with number of z
s. This means that if the array is called letters
, then letters[0]
should represent the number of a
s, and letters[25]
should represent the number of z
s).
Example:
"As you know, Morty, I've got a lot of enemies in the universe that consider my genius a threat"
[ 5, 0, 1, 1, 10, 1, 2, 3, 6, 0, 1, 1, 3, 6, 7, 0, 0, 4, 5, 8, 3, 2, 1, 0, 3, 0 ]
Prompt 2 (More difficult): Write a method that takes in a string (word
) and an array of strings (dictionary
). The method should check to see if the word
contains any of the words in the dictionary
. The method should segment the word
into the words that are found in the dictionary
and return an array of those words.
Example:
"applepie"
, [ "app", "apple", "bunny", "carrot", "pie", "pies"]
[ "app", "apple", "pie"]
"a"
as a key and give a value 1
, that would be written as follows:let letter = "a"; let letters={}; letters[letter] = 1;`.
"As you know, Morty, I've got a lot of enemies in the universe that consider my genius a threat"
{ a:5, c:1, d:1, e:10, f:1, g:2, h:3, i:6, k:1, l:1, m:3, n:6, o:7, p:0, r:4, s:5, t:8, u:3, v:2, y:3 }
true
if the string is a pangram and false
if it is not a pangram. A pangram is a sentence that contains at least one instance of each letter of the alphabet."applepie"
, [ "app", "apple", "bunny", "carrot", "pie", "pies"]
[ "apple", "pie"]