Home
← All questions

Image carousel with autoplay | Frontend Machine Coding

MediumPremiumMachine Coding

Asked at Netflix · Meta · Amazon

Frontend Machine Coding interview practice: Build an accessible carousel with autoplay, pause on hover, and swipe support.

Problem

Build an image carousel for a marketing hero section.

Requirements

  • Show one slide at a time with prev/next controls and dot indicators.
  • Autoplay every 4s; pause on hover and when tab is hidden (document.visibilityState).
  • Infinite loop (last → first).
  • (Bonus) touch swipe, lazy-load off-screen images, respect prefers-reduced-motion.

Hints / Approach

  • Index-based state % slides.length for looping.
  • useEffect + setInterval with cleanup; clear on pause.
  • visibilitychange listener to pause autoplay in background tabs.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium