Quick summary
Summarize this blog with AI
Historical candidate account: Jake reported receiving and accepting a Facebook data engineer offer after a roughly two-month process. The original account said he applied in May through a friend’s referral, but did not provide an interview year. It reported level E5, five to ten years of experience, CS degrees, Menlo Park, two months of preparation, and approximate total compensation of $450,000. These are unverified historical details, not a current Meta hiring or salary guide.
The reported sequence was a Python/SQL screen, another SQL screen, and a final round covering Python, SQL, data modeling, and behavioral questions. The four Python prompts below came from that account; the solutions and explicit edge-case contracts are editorial practice additions. They are not employer-endorsed answers.
1. Fill None with the preceding observed value
Preserve leading None values when no earlier value exists, preserve zero and False, and return a new list. The function does not modify its input.
def forward_fill(values):
result = []
previous = None
for value in values:
if value is not None:
previous = value
result.append(previous)
return result
source = [1, None, 1, 2, None]
print(forward_fill(source))
assert source == [1, None, 1, 2, None]
assert forward_fill([None, 0, None, None]) == [None, 0, 0, 0]
The output is [1, 1, 1, 2, 2]. Work is linear in the number of elements, with a new output list of that size. Consecutive missing values carry the last observed value. This is a specified transformation, not a universal policy for missing analytical data.
2. Find case-sensitive words present in only one string
Clarify tokenization, duplicates, and order. Here whitespace separates words, punctuation remains attached, repeated words are returned once, and output follows first appearance in the left string and then the right string. This makes the previously underspecified output order deterministic.
def unmatched_words(left, right):
left_words, right_words = left.split(), right.split()
left_set, right_set = set(left_words), set(right_words)
result, seen = [], set()
for word in left_words + right_words:
if ((word in left_set) != (word in right_set)) and word not in seen:
result.append(word)
seen.add(word)
return result
print(unmatched_words("Facebook is an awesome place",
"Facebook Is an AWESOME place"))
assert unmatched_words("x x y", "y z z") == ["x", "z"]
The output is ['is', 'awesome', 'Is', 'AWESOME']. If the interviewer wants a multiset difference, punctuation normalization, or alphabetical order, the contract and solution must change. Set membership here answers presence, not frequency.
3. Count a character
Require a one-character Python string and use a case-sensitive count. This counts Unicode code points, not arbitrary user-perceived grapheme clusters.
def count_character(text, character):
if not isinstance(text, str) or not isinstance(character, str):
raise TypeError("text and character must be strings")
if len(character) != 1:
raise ValueError("character must contain one code point")
return text.count(character)
print(count_character("missisipi", "s"))
assert count_character("", "s") == 0
assert count_character("AaA", "A") == 2
The reported example returns 3. Rejecting an empty search string avoids the surprising boundary-count behavior of an unrestricted substring count.
4. Return the key at a ranked numeric position
For this solution, n is a one-based position among entries sorted by descending integer value, with string key as the tie-breaker. Equal values occupy separate positions. Restricting the fixture to integer values avoids unspecified ordering of missing or non-finite numbers.
def nth_key(values, n):
if not isinstance(n, int) or isinstance(n, bool) or not 1 <= n <= len(values):
raise ValueError("n must identify an entry")
if any(not isinstance(k, str) or type(v) is not int for k, v in values.items()):
raise TypeError("use string keys and integer values")
ranked = sorted(values, key=lambda key: (-values[key], key))
return ranked[n-1]
print(nth_key({'a': 1, 'b': 2, 'c': 100, 'd': 30}, 2))
assert nth_key({'b': 10, 'a': 10, 'c': 3}, 2) == 'b'
The output is d. If “second largest” means the second distinct value, this is a different question: group equal values and decide which matching keys to return. This sorting solution uses O(k log k) time for k entries and allocates the ordered key list.
Prepare the reported SQL and modeling topics
The account also listed the fraction of paid customers buying both A and B, sales during promotion boundaries, top co-purchased products, and a ridesharing warehouse. For the first, define the eligible paid-customer denominator and time window, deduplicate customer-product presence, and keep numerator membership within that population. For promotions, define whether the final date is inclusive and how overlapping promotions are attributed. For co-purchases, define order versus lifetime co-occurrence, exclude self-pairs, and choose a tie policy.
The separate data engineering preparation guide develops a warehouse and rerun contract rather than repeating this historical report. Practice the four Python functions on empty inputs, leading missing values, repeated tokens, and tied values. Explain the contract before optimizing. Python’s sorting guide documents key functions and stable sorting.