# Imagine you are given a plain text, ASCII, English document, something like a
# book from Project Gutenberg. Develop a concordance for the book -- the number
# of times each word appears -- and then print the top N most frequent words and
# how many times they occur. N can be either hardcoded or a parameter.
'''
# what is the input format of the string?
The input could be any ASCII string
Could you give some examples?
It could be a book, a news article, any possible ASCII string could be input.
So a csv file right? you can assume the input to the function will be a python str
Concordance: frequency of each word
Input: string
Output: top N most frequent words and their respective frequencies
Pseudocode:
1. extract words from string and get list of words
2. loop through words and count the frequency by recording in a dictionary: word -> frequency
3. use heap to extract top N most frequent words from the dictionary
4. return words extracted from the heap
Jeffrey: This sounds like a reasonable approach if you want to start coding it up
'''
def N_most_frequent_words(str, n):
# let n denote the length of the string
sentence = str.remove(',','.',':') # scans str once O(n)
words = sentence.split(' ') #enumeration here so O(n)
d = {}
for word in words: #iteration through list so O(m) where m is the length of the list
word = word.lower()
if word in d:
d[word] += 1
else:
d[word] = 1
heap = [(frequency, word) for word, frequency in d.items()] # dictionary iteration so O(k) where k is the number of keys
n_most_frequent_words = heapq.nlargest(n, heap) #heapify operation is O(n logn)
for frequency, word in n_most_frequent_words: #another iteration over a list so O(l) where l = len(n_most_frequent_words)
print(word, frequency)
# What if my input string is "The the THE ThE". Then the output should be "the: 4". But your current solution will not handle that
# to render words capital/lowercase invariant, one could utilise regular expressions, but I am not too familiar with regex commands
# Can you think of another way besides using regex to normalize the words?
# I know another solution
# transform all capital letters to lowercase using .toLowerCase() if I remember the method correctly
# Yes this is a good idea. I think the method in python is just .lower(). Can you modify your solution above to handle this?
# What if my input string is "The, the. THE; ThE?". Then the output should be "the: 4". But your current solution will not handle that
# in the event where the delimiters between words are all different, my approach would be to use .remove() to delete all non-letter instances
# and then use .split(' ') using white space as the delimiter
# Sounds good, do you want to modify your solution to handle this case?
# I don't remember if .remove() permits multiple arguments,
# That's fine, I get the idea.
# I think the solution works now! What is the time complexity of this solution?
# Time complexity analysis looks good! I have no further questions on this one, are you ready to move on to the next coding problem?
# Yes
# Ok, this next question is based off of the game Minesweeper.
# In the game of Minesweeper you are given a Two Dimensional grid with a variable number of
# mines randomly located within the grid.
# Write a function that generates a game grid with mines placed at random. The function should take arguments for
# Length, Width and Number of Mines.
# The function should return the constructed 2D grid. Place at most one mine per cell
'''
Input: length, width, number of mines
Output: matrix
Pseudocode:
let -1 denote that the matrix entry is a mine
let 0 denote that the matrix entry is not a mine
Let's use 0 for no mine and -1 for a mine. You will see why later. ok
The issue here is randomness, if the mine locations are indeterminate, then what approach should I take to simulate randomness?
There are built in functions in python to generate randomness. Are you familiar with python rand library?
The most I know is the random number generator. I could use that, but do not recall the name of the RNG method
I believe it is rand.randInt(lo, hi) which will generate a random number between lo (inclusive) and hi (exclusive)
1. generate random coordinates (x, y) for mines 1, ..., n
2. use list comprehension to intialize a matrix of zeros
3. change zeros to -1 for each mine coordinate given in step 1
Sounds good
'''
def generate_grid(length, width, n):
mines = set()
while len(mines) < n:
x = rand.randInt(0, width)
y = rand.randInt(0, length)
mines.add((x,y))
grid = [[0 for column in range(width)] for row in range(length)]
for row in range
required to run
-check if I/O slow by using the pidstat -d -p to check the io delay
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hi Daniel, given we have only 2 minutes left, let's stop here. Please use the remaining time for any questions you have for me :)
ok,
1. My question is about working on-call as a production engineer. Is it exhausting? or is it fun?
At Meta, every SWE or PE team member is oncall for the things their team owns. We have a "you write it, you own it" kinda philosophy, so PE and SWE have an oncall scenario that looks alike. Some PE teams do oncall jointly with their SWE partner teams, while some PE teams own a non-overlapping area that they do oncall independently for. Oncall load largely depends on the maturity state of the area your team owns, your alerting quality, documentation, etc and there is no one-size-fits-all answer to this question due to this reason. Most good teams make oncall maturity a priority and hence it is fun as you get to focus on challenging problems while automating the non-interesting parts of the oncall.
Any other questions?
In production engineering, what is the career growth like at Meta, are production engineers going to be working on maintaining the security and reliability of the Metaverse that is to come?
Career growth is same as that for SWEs, I believe it is easier to find lot of examples about SWE growth at Meta on public forums and you can imagine the same will apply to PE.
Yes there are PE teams in the Reality labs space, if you are specifically interested about the Metaverse work. In general, Metaverse will be powered by multiple teams/orgs including infra and product teams, and they all will eventually have some scope for reliability, scalability, efficiency, security work that PEs specialize in. PEs are already playing an important role in AI space that is crucial for Metaverse. There are also PE teams in AR/VR space.
Hope that answers the question. We are at time, so we can wrap up unless there are more questions.
Thank you for your answers. I was interested in working on the Metaverse so your previous answer definitely gave me some much needed motivation.
I wish you a wonderful rest of your evening.
Thank you, and hope you have a good rest of the day too! Thanks for taking the time to interview with us, and all the best! I will disconnect now.
Great, see you!