Building a spaced repetition system that adapts to user pace in real-time (Kotlin/Compose)
I built a flashcard app for interview prep and wanted to share some of the more interesting technical problems I ran into. The app has 1500+ questions across DSA and System Design, and the core challenge was: how do you order cards intelligently without it feeling robotic? Problem 1: Slot Assignment for Spaced Repetition Standard SR (like Anki) just shows the most overdue card next. That works for vocabulary but feels terrible for algorithms because you get 3 Hard questions in a row and want to quit. My approach: generate a target difficulty pattern (Easy, Medium, Easy, Medium, Hard, repeat) based on a 40/40/20 distribution, then assign due cards to matching-difficulty slots. Most-overdue cards get placed first within their tier. Unseen cards fill remaining slots. This means a Hard card that's overdue still lands in a Hard slot, not position 1. You get difficulty variety while still seeing overdue cards at the right time. fun assignSlots(pool: List<Question>, dueCards: List<ProgressEntity>): List<Question> { val pattern = generatePattern(size = pool.size, distribution = "40/40/20") val dueByDifficulty = dueCards.groupBy { it.difficulty } val result = Array<Question?>(pattern.size) { null } // Place due cards in matching slots, most overdue first for ((difficulty, cards) in dueByDifficulty) { val sorted = cards.sortedBy { it.nextReviewDate } val availableSlots = pattern.indices.filter { pattern[it] == difficulty && result[it] == null } sorted.zip(availableSlots).forEach { (card, slot) -> result[slot] = findQuestion(card, pool) } } // Fill remaining with unseen // ... } Problem 2: Re-ranking after every swipe without jank After each swipe, the deck needs to re-rank. But the top visible card (position 0) is already animating into view, so you can't move it. Solution: lock position 0, re-rank positions 1+, then check for constraint violations across the boundary (e.g., if locked card is Hard and new position 1 is also Hard, swap position 1 with the first non-Hard card d