Company-style OA practice sets with full problem statements, sample test cases, and solutions.
Have you recently taken Apple's Online Assessment or coding test? Share the questions, test cases, or assessment patterns you encountered. Earn SWE180 Coins for every verified submission and use them to unlock other company OA sets and premium tools for free!
iOS background application management uses a Least Recently Used (LRU) cache policy to evict processes when RAM limits are reached.
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.
Implement the LRUCache class:
- LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
- int get(int key) Return the value of the key if the key exists, otherwise return -1.
- void put(int key, int value) Update the value of the key if that key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
The functions get and put must each run in O(1) average time complexity.
Example 1
Input
LRUCache(2) put(1, 1) put(2, 2) get(1) put(3, 3) get(2) put(4, 4) get(1) get(3) get(4)
Output
1 -1 -1 3 4
Explanation
put(1, 1) and put(2, 2) add items.
get(1) returns 1 and marks key 1 as most recently used.
put(3, 3) evicts key 2 (least recently used).
get(2) returns -1 (not found).
Given an array of strings words and an integer k, return the k most frequent strings.
Return the answer sorted by frequency from highest to lowest.
Sort the words with the same frequency by their lexicographical order.
Example 1
Input
6 2 i love leetcode i love coding
Output
i love
Explanation
"i" and "love" appear 2 times each. Since "i" comes before "love" lexicographically, "i" is placed first.
Gain complete transparency into the Apple online assessment process. Prepare effectively with real, verified coding challenges, test patterns, and platform details.
Wondering what top companies are actually asking in their initial screening rounds? We provide exact Data Structures, Algorithms, and logical reasoning questions reported by candidates who recently took the Apple online tests. Stop guessing and start practicing the right problems.
Understand exactly how many questions to expect, the typical time limits, and the platforms used (e.g., HackerRank, Codility, CodeSignal). Knowing the format in advance is the first step to clearing the Apple OA.