Writing down the questions from my DatologyAI interviews back in January at the start of the year. At the time I couldn't find anything about them online 😂 so I'm filling in the gap.
Jan 6: The first round was with an interviewer who works on frontend. The question was to implement a text editor:
Implement a TextEditor supporting:
type_in(char): type a character at the cursorbackspace(): delete the character immediately before the cursor__str__(): return the text with | representing the cursor
Follow-up:
- add
move_cursor(direction)and allow the cursor to move left and right - allow the cursor to move up and down
Jan 21: The second round was also with another interviewer, and the question was to mock Spark RDD: use the provided functions to implement new functions.
Given:
from collections import defaultdict
class SimpleRDD:
def __init__(self, items):
self.items = items
def flatMap(self, func):
"""Apply func to each item, flatten the results, and return a new SimpleRDD"""
new_items = []
for item in self.items:
new_items.extend(func(item))
return SimpleRDD(new_items)
def groupByKey(self):
"""Group (key, value) pairs by key and return a SimpleRDD of (key, [values])"""
grouped = defaultdict(list)
for key, value in self.items:
grouped[key].append(value)
return SimpleRDD(list(grouped.items()))
def union(self, other_rdd):
"""Return a new SimpleRDD containing items from self and other_rdd"""
return SimpleRDD(self.items + other_rdd.items)
def collect(self):
"""Return a list copy of the RDD items"""
return list(self.items)
- Implement a word_count function which reads in 1 rdd and returns an rdd that groups each word with its count. For example:
sentences = SimpleRDD([
"hello world",
"hello spark",
"hello world"
])
wc_rdd = word_count(sentences)
print(wc_rdd.collect()) # Output: [('hello', 3), ('world', 2), ('spark', 1)]
- Implement an intersect function which takes 2 rdds and returns an rdd. For example:
rdd1 = SimpleRDD([1, 3, 3])
rdd2 = SimpleRDD([3, 4, 3])
result = intersect(rdd1, rdd2)
print(result.collect()) # Output: [3, 3]
In the second round my brain froze and I didn't manage to write intersect 😂
Discussion
Loading comments…