ByteDance logo

ByteDance Interview Questions

4 practice questions for ByteDance technical interviews

No verified questions yet for ByteDance.

system design Senior caching

[OA] LRU Cache — Implement the caching layer for ByteDance's real-time content delivery

For efficient performance on ByteDance's content delivery platform, we need a system that caches frequently accessed user data and drops the least recently used data when the capacity is exceeded.
You are to implement an LRU (Least Recently Used) cache.
Class Name: LRUCache
- Method Signature: def __init__(self, capacity: int):
- Initializes the LRU cache with positive size capacity.
- Method Signature: def get(self, key: int) -> int:
- Returns the value of the key if the key exists, otherwise returns -1.
- Method Signature: def put(self, key: int, value: int) -> None:
- Update or insert the value if the key is not already present. When the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.
Example 1:
Input: LRUCache(2);
cache.put(1, 1);
cache.put(2, 2);
cache.get(1);
Output: 1;
Example 2:
Input: cache.put(3, 3); // LRU key was 2, evicts key 2
cache.get(2);
Output: -1;
Constraints:
- capacity is a positive integer.
- All keys and values are in the range of 1 to 10000.
- The functions get and put are guaranteed to be called on existing keys.
system design Senior api design

[OA] Design User Preferences — Model user preferences for ByteDance's recommendation system

ByteDance aims to provide users with a highly personalized experience based on their preferences. You need to design a class to manage and query user preferences effectively.
Class Name: UserPreferences
- Method Signature: def add_preference(self, category: str, preference: str) -> None
- Adds a preference to the user's profile.
- Method Signature: def get_preferences(self, category: str) -> List[str]
- Returns a list of preferences for a given category.
- Method Signature: def delete_preference(self, category: str, preference: str) -> None
- Deletes a specific preference from a given category.
Example 1:
Input: user_prefs = UserPreferences() ;
user_prefs.add_preference('music', 'rock')
user_prefs.get_preferences('music')
Output: ['rock']
Example 2:
Input: user_prefs.add_preference('music', 'pop') ;
user_prefs.get_preferences('music')
Output: ['rock', 'pop']
Constraints:
- 1 <= len(category) <= 100
- 1 <= len(preference) <= 100
- The same preference may not be added multiple times within the same category.
coding Hard graph

[OA] Depth-First Search — Find the most relevant user connections in ByteDance's social platform

In ByteDance's social networking site, we need to model user relationships and find the most relevant connections for a given user in a depth-first manner.
You are to implement a function that takes the connections of users and a target user, returning all relevant connections.
Method Signature: def find_relevant_connections(connections: Dict[str, List[str]], user: str) -> List[str]:
- connections: a dictionary where keys are user IDs and values are lists of user IDs representing friendships.
- user: a string representing the target user's ID.
- Returns a list of user IDs that are reachable from the target user.
Example 1:
Input: connections = {'a': ['b', 'c'], 'b': ['d'], 'c': ['e'], 'd': [], 'e': []} and user = 'a'
Output: ['b', 'c', 'd', 'e']
Explanation: From user 'a', you can reach 'b', 'c', 'd', and 'e'.
Example 2:
Input: connections = {'x': ['y'], 'y': ['z'], 'z': []} and user = 'x'
Output: ['y', 'z']
Explanation: User 'x' can reach 'y' and 'z'.
Constraints:
- 1 <= len(connections) <= 10^4
- Each user ID has at most 100 characters.
coding Hard sliding window

[OA] Sliding Window — Implement a user feed for ByteDance's content platform

In the dynamic environment of ByteDance's content platform, we need to efficiently generate a user feed that displays trending content based on real-time user interactions.
You are to implement a function that takes a list of user interactions (likes or comments) and generates a list of trending content using a sliding window approach.
Method Signature: def generate_trending_feed(interactions: List[str], n: int) -> List[str]:
- interactions: a List of strings representing the IDs of content interacted with by a user.
- n: an integer representing the number of trending content items to return.
- Returns a List of strings containing the IDs of the trending content items.
Example 1:
Input: interactions = ['a', 'b', 'a', 'c', 'b', 'a']
Output: ['a', 'b', 'c']
Explanation: Item 'a' is interacted with 3 times, 'b' 2 times, and 'c' 1 time.
Example 2:
Input: interactions = ['x', 'y', 'y', 'x', 'x', 'z', 'y']
Output: ['x', 'y', 'z']
Explanation: 'x' has 3 interactions, 'y' has 3, and 'z' has 1.
Constraints:
- 1 <= len(interactions) <= 10^4
- 1 <= n <= 100
- interactions[i] is a string with length 1 to 100.

Start practicing ByteDance questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free