PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Apple

Implement rotation, LRU cache, streaming median, cycle detection

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of array/matrix manipulation, cache and data structure design, streaming algorithms for median maintenance, and graph theory for cycle detection, with emphasis on algorithmic complexity analysis and handling of edge cases.

  • Medium
  • Apple
  • Coding & Algorithms
  • Software Engineer

Implement rotation, LRU cache, streaming median, cycle detection

Company: Apple

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Complete the following coding tasks. For each, provide code, justify time/space complexity, and describe edge cases: 1) Image rotation: Given an n×n integer matrix representing an image, rotate it 90 degrees clockwise in place using only O( 1) extra space. 2) LRU cache: Design an in-memory cache with capacity cap that supports get(key) and put(key, value) in O( 1) average time and evicts the least recently used entry. Describe your data structures and how you'd handle concurrency and optional TTL expiration. 3) Streaming median: Build a data structure that supports add(num) and median() queries over a stream of integers, with O(log n) insertion and O( 1) median retrieval. Specify how you handle both odd and even counts. 4) Graph cycle detection: Given a graph expressed as adjacency lists, determine whether it contains a cycle. Provide an algorithm for directed graphs and note how it differs for undirected graphs. Optionally return one example cycle if present.

Quick Answer: This question evaluates understanding of array/matrix manipulation, cache and data structure design, streaming algorithms for median maintenance, and graph theory for cycle detection, with emphasis on algorithmic complexity analysis and handling of edge cases.

Related Interview Questions

  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)
  • Rotate a Matrix In Place - Apple (medium)
  • Encode and Rebuild a Binary Tree - Apple (hard)
  • Wrap Matching Substrings in Bold Tags - Apple (medium)
Apple logo
Apple
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
9
0

Complete the following coding tasks. For each, provide code, justify time/space complexity, and describe edge cases:

  1. Image rotation: Given an n×n integer matrix representing an image, rotate it 90 degrees clockwise in place using only O(
  2. extra space.
  3. LRU cache: Design an in-memory cache with capacity cap that supports get(key) and put(key, value) in O(
  4. average time and evicts the least recently used entry. Describe your data structures and how you'd handle concurrency and optional TTL expiration.
  5. Streaming median: Build a data structure that supports add(num) and median() queries over a stream of integers, with O(log n) insertion and O(
  6. median retrieval. Specify how you handle both odd and even counts.
  7. Graph cycle detection: Given a graph expressed as adjacency lists, determine whether it contains a cycle. Provide an algorithm for directed graphs and note how it differs for undirected graphs. Optionally return one example cycle if present.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Apple•More Software Engineer•Apple Software Engineer•Apple Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.