Quick Overview

This question evaluates fluency with graph traversal, set operations, deduplication, and frequency-based ranking in Python, targeting manipulation of directed "follows" relationships represented as dictionaries and is categorized under Data Manipulation (SQL/Python).

Recommend two-hop follows in Python

Company: Meta

Role: Data Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

Given a directed "follows" graph as a Python dict[str, list[str]], implement recommend_two_hop(graph, user) that returns the set (or a sorted list) of accounts followed by the user’s followees that the user does not already follow, excluding the user themself. Deduplicate recommendations; if you return a list, sort by descending frequency among two-hop neighbors, then lexicographically. Example: graph = {"A": ["B","C"], "B": ["C","D"], "C": ["E"]} ⇒ recommend_two_hop(graph, "A") = {"D","E"}.

Quick Answer: This question evaluates fluency with graph traversal, set operations, deduplication, and frequency-based ranking in Python, targeting manipulation of directed "follows" relationships represented as dictionaries and is categorized under Data Manipulation (SQL/Python).

Loading coding console...