Hey everyone! Giving back to the community—
If you have an upcoming Karat interview, here’s what to expect:
The interviewer will read the question aloud, which can take a lot of time. This might leave you confused and waste valuable minutes. (I had a bad experience with this!)
In the first 10 minutes, you’ll be asked to choose 2 topics from the following list:
OOPS (Object-Oriented Programming)
Troubleshooting in Production
REST APIs
Testing
Databases
Web Development
Important Tip: Karat expects you to write fully executable code that passes all test cases successfully. Be prepared to code efficiently and manage your time well!
/* Q1
You are with your friends in a castle, where there are multiple rooms named after flowers. Some of the rooms contain treasures - we call them the treasure rooms.
Each room contains a single instruction that tells you which room to go to next.
*** instructions_1 and treasure_rooms_1 ***
lily* --------- daisy sunflower
| | |
v v v
jasmin --> tulip* violet* ----> rose* -->
^ | ^ ^ |
| | | | |
------ iris ---------
This is given as a list of pairs of (source_room, destination_room)
instructions_1 = [
["jasmin", "tulip"],
["lily", "tulip"],
["tulip", "tulip"],
["rose", "rose"],
["violet", "rose"],
["sunflower", "violet"],
["daisy", "violet"],
["iris", "violet"]
]
treasure_rooms_1 = ["lily", "tulip", "violet", "rose"]
Write a function that takes two parameters as input:
and returns a collection of all the rooms that satisfy the following two conditions:
filter_rooms(instructions_1, treasure_rooms_1) => ["tulip", "violet"]
Additional inputs
treasure_rooms_2 = ["lily", "jasmin", "violet"]
filter_rooms(instructions_1, treasure_rooms_2) => []
*** instructions_2 and treasure_rooms_3 ***
lily --------- --------
| | |
v v |
jasmin --> tulip ---> violet*--^
instructions_2 = [
["jasmin", "tulip"],
["lily", "tulip"],
["tulip", "violet"],
["violet", "violet"]
]
treasure_rooms_3 = ["violet"]
filter_rooms(instructions_2, treasure_rooms_3) => ["tulip"]
All the test cases:
filter_rooms(instructions_1, treasure_rooms_1) => ["tulip", "violet"]
filter_rooms(instructions_1, treasure_rooms_2) => []
filter_rooms(instructions_2, treasure_rooms_3) => ["tulip"]
Complexity Analysis variables:
T: number of treasure rooms
I: number of instructions given
*/
/* Q2:
A new singer is looking for songs to perform. To be able to perform a song all the notes in the song must be within the singer's range, which is given by the lowest and highest notes the singer is able to sing.
A note is represented by:
For example, C5 is a note with pitch C and octave 5.
A note with a larger octave number is always higher than a note with a smaller octave number. If the octave number is the same, then a note with a later pitch letter is higher.
For example, here are some notes in order from lower to higher:
... G3 A3 B3 C4 D4 E4 F4 G4 A4 B4 C5 D5 …
A3 is higher than G3 because A comes after G in the ordering above
C4 is higher than B3 because its octave number is larger
The lowest possible note is C0 and the highest possible note is B7.
You will be given as input a list of notes in a song, the lowest note the singer can sing, and the highest note the singer can sing. Write a function that returns whether the singer can sing the song.
Examples:
song1 = ["F4", "B4", "C5"]
singable(song1, "F4", "C5") => True
Every note in the song is between F4 and C5, so the singer can sing this song.
Note that B4 is higher than F4, since notes are ordered C D E F G A B
singable(song1, "A4", "C5") => False
F4 is lower than A4, so the singer cannot sing this song
song2 = ["C3", "E3", "G3", "C4", "E4", "G4", "C5"]
singable(song2, "B2", "C5") => True
singable(song2, "C3", "B4") => False
B2 is lower than C3. A note with a smaller octave number is always lower than a note with a larger octave number. Similarly, B4 is lower than C5
Additional input data:
song3 = [ "B4", "F5", "B5" ]
song4 = ["B4", "E4", "G4", "G4", "A4", "B4", "E4",
"B4", "E4", "G4", "G4", "A4", "C5", "B4",
"E5", "G4", "G4", "A4", "B4", "C5", "D5",
"C5", "B4", "C5", "E5", "D5", "C5", "C5",
"B4", "B4", "E5", "E4", "G4", "G4", "A4",
"B4", "B4", "B4", "C5", "E5", "A5", "E5",
"C5", "A4", "E5", "D5", "C5", "B4"]
song5 = [ "F4" ]
All test cases:
singable(song1, "F4", "C5") => True
singable(song1, "A4", "C5") => False
singable(song2, "B2", "C5") => True
singable(song2, "C3", "B4") => False
singable(song3, "B4", "B5") => True
singable(song3, "B4", "C5") => False
singable(song4, "D4", "A5") => True
singable(song4, "D4", "G5") => False
singable(song4, "D4", "C6") => True
singable(song4, "F4", "C6") => False
singable(song5, "D4", "E4") => False