Meta DE mainly tests basic SQL skills such as aggregation queries, grouping, sorting, CTEs, filtering logic, and time window functions. This interview was for a Senior-level position. The technical screen included 5 SQL questions and 5 Python questions, and the time was extremely tight. In most cases, completing 3 SQL + 3 Python is considered relatively safe, while 4 SQL + 4 Python should almost guarantee moving on to the onsite/loop interviews. Sharing a recent Meta Data Engineer interview experience from a couple of days ago.
Meta DE Interview Experience: SQL
Q1
- Num_copies_not_returned: The number of copies of books that are in "good" status and have not been returned yet.
- Pct_renewed: In the above batch of copies, the current borrowing renewal_count > 2 proportion, range 0~100
SELECT
COUNT(*) AS num_copies_not_returned,
CASE
WHEN COUNT(*) = 0 THEN 0
ELSE 100.0 * SUM(CASE WHEN ch.renewal_count > 2 THEN 1 ELSE 0 END) / COUNT(*)
END AS pct_renewed
FROM copies c
JOIN checkouts ch
ON c.copy_id = ch.copy_id
WHERE c.condition = 'good'
AND ch.returned_date IS NULL;
Q2
The definition of lifetime_value: the total number of days a book has been lent. Constraints need to be met: unreturned borrowing records (returned_date IS NULL) are not counted and only books with more than 10 copies are considered. Find the top 3 books with the highest lifetime_value.
SELECT
b.book_id,
SUM(ch.returned_date - ch.checkout_date) AS lifetime_value
FROM books b
JOIN copies c ON b.book_id = c.book_id
JOIN checkouts ch ON c.copy_id = ch.copy_id
WHERE ch.returned_date IS NOT NULL
GROUP BY b.book_id
HAVING
(SELECT COUNT(*) FROM copies c2 WHERE c2.book_id = b.book_id) > 10
ORDER BY lifetime_value DESC
LIMIT 3;
Q3
Library members can reserve copies of books (queue to borrow) and find out which member has the largest difference in reservation number from their inviter.
SELECT
m.member_id,
m.invited_by_member_id,
ABS(
COUNT(c.copy_id) -
COUNT(ic.copy_id)
) AS diff_num_reserved_copies
FROM members m
LEFT JOIN copies c
ON c.reserved_by_member_id = m.member_id
LEFT JOIN members im
ON im.member_id = m.invited_by_member_id
LEFT JOIN copies ic
ON ic.reserved_by_member_id = im.member_id
GROUP BY
m.member_id,
m.invited_by_member_id
ORDER BY diff_num_reserved_copies DESC, m.member_id
LIMIT 1;
Q4
Find the members who have borrowed books for two consecutive full weeks in 2024, and then find among these people the one who borrowed the most books in the first week.
WITH member_week_checkouts AS (
SELECT
member_id,
EXTRACT(WEEK FROM checkout_date)::INT AS week_idx,
COUNT(*) AS num_copies
FROM checkouts
WHERE EXTRACT(YEAR FROM checkout_date) = 2024
AND EXTRACT(WEEK FROM checkout_date) BETWEEN 1 AND 52
GROUP BY
member_id,
EXTRACT(WEEK FROM checkout_date)
),
consecutive_weeks AS (
SELECT
w1.member_id,
w1.week_idx AS first_week_index,
w1.num_copies AS first_week_num_copies
FROM member_week_checkouts w1
JOIN member_week_checkouts w2
ON w1.member_id = w2.member_id
AND w2.week_idx = w1.week_idx + 1
)
SELECT
member_id,
first_week_index,
first_week_num_copies
FROM consecutive_weeks
ORDER BY first_week_num_copies DESC, member_id, first_week_index
LIMIT 1;
Meta DE 面经:Code
Q1
You can select up to 3 books. Each book must be from a different category. Each book must have (category, points), find the maximum total score
Def get_max_score(books):
# Keep the highest score for each category
best = {}
for category, score in books:
if category not in best or score > best[category]:
best[category] = score
# Get the highest score of all categories
scores = sorted(best.values(), reverse=True)
# Take at most 3
return sum(scores[:3])
Q2
The library will generate a log every time a book is borrowed or returned. The log contains the book's ID and operation type (borrowing/returning). Verify whether the log sequence is legal and return if the following two illegal situations are encountered: False.
From dataclasses import dataclass
@dataclass
class LogEntry:
book_id: int
is_checkout: bool # True = checkout, False = return
def are_log_entries_valid(log_entries):
checked_out = set()
for entry in log_entries:
book_id = entry.book_id
if entry.is_checkout:
#checkout
if book_id in checked_out:
return False
checked_out.add(book_id)
else:
# return
if book_id not in checked_out:
return False
checked_out.remove(book_id)
return True
Q3
The library has 4 branches (A/B/C/D). When some branches are closed, employees will go to alternate branches or work from home. Given a set of closed branches, return the actual total number of employees at each open branch.
Take A as an example: "A": {"A": 80, "B": 10, "C": 15, "D": 5}
- There are 80 people in Hall A
- If A is closed: 10 people go to B, 15 people go to C, 5 people go to D, and the remaining 50 people are at home (80-10-15-5=50, not included in any library)
Def get_num_employees(location_employees: dict[str, dict[str, int]],
closed_locations: set[str]) -> dict[str, int]:
result = {}
# First initialize all unclosed offices to 0
for loc in location_employees:
if loc not in closed_locations:
result[loc] = 0
# Traverse each "employee's original office"
for src, dist in location_employees.items():
if src in closed_locations:
# src Closing: Employees will be diverted to other unclosed offices
for dst, cnt in dist.items():
if dst != src and dst not in closed_locations:
result[dst] += cnt
else:
# src is not closed: employees of this office are still working in the original office
result[src] += dist[src]
return result
Q4
From Original_name Can I get the result by deleting some letters from New_name? If possible, return how many letters were deleted; if not, return -1. Ignoring whitespace and case, new_name must be a subsequence of original_name.
Def get_num_letters(original_name: str, new_name: str) -> int:
# Ignore case + remove spaces
original = original_name.replace(" ", "").lower()
new = new_name.replace(" ", "").lower()
i = 0
j = 0
# Double pointer check subsequence
while i < len(original) and j < len(new):
if original[i] == new[j]:
j += 1
i += 1
# If new does not match exactly
if j != len(new):
return -1
# Delete number of characters
return len(original) - len(new)
In summary, it was okay, but within one hour, the time was very tight. I started the SQL session without asking any more questions at the beginning. I did a total of 4+4 questions. The prompts given were in place and the questions were completed. The interviewer was very sure of the students' ability. Meta has a lot of SDE topics recently, and DS was no problem. It was difficult to solve.
After the entire interview, it can be found that the Meta questions are more basic and the time is very limited. It is generally difficult to complete 4 SQL + 4 codes. If you are also worried about encountering similar situations in interviews with Meta or other big companies, it is better to learn about our VO remote assistance service , has so far helped hundreds of students get offers successfully, making interviews less confusing, thinking clearly, and greatly improving the success rate.