3 practice questions for Apple technical interviews
No verified questions yet for Apple.
system designSeniorcaching
[OA] LRU Cache — Design a memory efficient cache for Apple Music
Apple Music needs a fast caching layer to store recently played songs and their metadata, enhancing user experience by minimizing load times while playing music. Class LRUCache: - LRUCache(int capacity): Initializes the LRU cache with a positive size cap. - int get(int key): Returns the value of the key if the key exists, otherwise returns -1. - void put(int key, int value): Updates the value of the key if it exists, or adds the key-value pair if it doesn't. When the cache reached its capacity, it should invalidate the least recently used item before inserting the new item.Example 1: Input: cache = LRUCache(2), cache.put(1, 1), cache.put(2, 2), cache.get(1) Output: 1 Explanation: Returns 1 and makes key 1 the most-recently used.Example 2: Input: cache.put(3, 3), cache.get(2) Output: -1 Explanation: Key 2 was already evicted due to reaching the capacity limit. Constraints: - 1 <= capacity <= 3000 - 0 <= key, value <= 10^4
codingHardtwo pointers
[OA] Two Pointers — Manage borrowed books in Apple Books
In order to track the number of borrowed books, Apple Books needs an effective way to manage the list of borrowed books based on different genres and their borrowing time. Problem statement: You are given an array of integers books representing the borrowing times in days for different genres of books. Return the number of unique genres that have been borrowed for k or more days.Example 1: Input: books = [3, 1, 4, 1, 5, 9, 2], k = 3 Output: 4 Explanation: The unique genres with a borrowing time of 3 days or more are 3, 4, 5, and 9.Example 2: Input: books = [1, 2, 3, 4, 5, 6], k = 5 Output: 2 Explanation: The unique genres with a borrowing time of 5 days or more are 5 and 6. Constraints: - 1 <= books.length <= 10^4 - 1 <= books[i] <= 10^5 - 1 <= k <= 10^5
codingHardsliding window
[OA] Sliding Window — Optimize video streaming experience on Apple TV
Apple is known for its high-quality media streaming services. The goal of this problem is to create a dynamic viewing experience that adapts to varying bandwidth conditions. Problem statement: Given an array of integers representing the bandwidth availability over time, find the maximum sum of continuous k bandwidth values that can ensure a smooth streaming experience.Example 1: Input: bandwidth = [10, 1, 2, 3, 4, 5, 6], k = 3 Output: 15 Explanation: The maximum bandwidth from indices 4 to 6 is 5 + 6 + 4 = 15.Example 2: Input: bandwidth = [12, 5, 4, 1, 3], k = 2 Output: 17 Explanation: The maximum bandwidth from indices 0 to 1 is 12 + 5 = 17. Constraints: - 1 <= bandwidth.length <= 10^4 - 1 <= bandwidth[i] <= 100 - 1 <= k <= bandwidth.length
Start practicing Apple questions
Sign up for free to access walkthroughs, AI-generated questions, and more.