{"id":1011,"date":"2026-11-15T09:47:00","date_gmt":"2026-11-15T08:47:00","guid":{"rendered":"https:\/\/grindloop.ai\/blog\/?p=1011"},"modified":"2026-11-14T16:11:59","modified_gmt":"2026-11-14T15:11:59","slug":"seen-the-coding-interview-question-before","status":"publish","type":"post","link":"https:\/\/grindloop.ai\/blog\/seen-the-coding-interview-question-before\/","title":{"rendered":"Seen the Coding Interview Question Before? Say So, Then Win the Follow-Up"},"content":{"rendered":"<p>If you&#8217;ve seen the coding interview question before, say so in one sentence before you start. Then show what you remember. Keep it short and factual. Something like &#8220;I&#8217;ve solved this one before, so I know the standard approach&#8221; is enough. Some interviewer guides tell them to ask anyway. If they ask after you&#8217;ve rushed to a perfect answer, the truth costs more. Saying it first also changes what the round measures. A known problem no longer tells the interviewer much. So they&#8217;ll either give you a new problem or keep this one and change it. Your score then rests on how you handle that change. A memorized solution often breaks on the twist. So practice saying why the standard answer works. Below, one Android engineer handles a familiar LRU cache problem in Kotlin. You&#8217;ll see the disclosure line, the twist, the bug it exposes and a full script to adapt.<\/p>\n<h2>Interviewer guides say to ask if you&#8217;ve seen the coding interview question before<\/h2>\n<p>The question comes from interviewer checklists. The <a href=\"https:\/\/www.techinterviewhandbook.org\/interviewer-cheatsheet\/\" target=\"_blank\" rel=\"noopener\">Tech Interview Handbook&#8217;s interviewer cheatsheet<\/a> lists it as a step right after the problem is given. Yangshun Tay wrote the handbook. He&#8217;s a former Meta staff engineer. The page was last updated in August 2026. The site also promotes a paid front-end prep platform. The checklist item reads &#8220;Ask if the candidate has seen the question before.&#8221;<\/p>\n<p>Not every interviewer asks. Some forget. Some ask halfway through. That timing is the problem. Say you hide it and code a clean answer in eight minutes. Then the interviewer asks. Now a yes sounds like a confession. A no is a lie you have to defend for the rest of the hour. Saying it at minute one avoids both.<\/p>\n<h2>A memorized answer shows up when the problem changes<\/h2>\n<p>Interviewers have a simple test for recall. They change one rule and watch what happens. In a <a href=\"https:\/\/interviewing.io\/blog\/how-hard-is-it-to-cheat-with-chatgpt-in-technical-interviews\" target=\"_blank\" rel=\"noopener\">study of cheating with ChatGPT<\/a>, interviewing.io had interviewers alter well-known LeetCode problems. One interviewer said they usually add one or two twists. The goal is to catch candidates who&#8217;d heard a question before. Mike Mroczka wrote the post. He&#8217;s a former Google engineer. The page shows no date. interviewing.io sells mock interviews, so it has a stake in how prep works.<\/p>\n<p>The pattern is easy to see from the interviewer&#8217;s chair. A candidate writes the standard answer fast. Then one rule changes. The candidate stalls, because they never knew why the original worked. That gap reads as memorization. You&#8217;ll still get the twist after disclosing. But the interviewer expects it then, so a stall costs less trust.<\/p>\n<h2>Say it in one sentence, then show what you remember<\/h2>\n<p>Take an Android engineer we&#8217;ll call Nadia. Her coding round is in Kotlin. The interviewer asks for an LRU cache with <code>get<\/code> and <code>put<\/code> and a fixed capacity. Nadia built this exact cache twice last month in practice. Here&#8217;s her opening.<\/p>\n<blockquote>\n<p>Before I start, I&#8217;ve solved this one before. I&#8217;d use a LinkedHashMap in access order, so a read moves an entry to the end. Then I evict the eldest entry when the size goes over capacity. Happy to code that, or to take a different problem. Which is more useful for you?<\/p>\n<\/blockquote>\n<p>That&#8217;s four sentences. The first is the disclosure. The second and third show she understands why the approach works. The last hands the choice back. There&#8217;s no apology in it, because practicing common problems is normal prep.<\/p>\n<h2>The interviewer swaps the problem or keeps it and adds a twist<\/h2>\n<p>Either reply is fine. On a swap, you lose nothing. You get a fresh problem. The interviewer also trusts what you say next. Our post on <a href=\"https:\/\/grindloop.ai\/blog\/hint-in-a-coding-interview\/\">how hints are scored in a coding interview<\/a> covers working through an unseen problem.<\/p>\n<p>Nadia&#8217;s interviewer keeps the problem. They ask her to code the standard version quickly. She does it in about five minutes.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">class LruCache&lt;K, V&gt;(private val capacity: Int) :\n    LinkedHashMap&lt;K, V&gt;(16, 0.75f, true) {\n    override fun removeEldestEntry(eldest: MutableMap.MutableEntry&lt;K, V&gt;?) =\n        size &gt; capacity\n}<\/pre>\n<p>The <code>true<\/code> in the constructor turns on access order. Nadia says so as she types it. She runs a quick case out loud. Capacity is 2. She puts x and y, reads x, then puts z. The cache keeps x and z and drops y. That&#8217;s correct. Then the twist arrives.<\/p>\n<h2>The twist breaks the one-eviction rule<\/h2>\n<p>The interviewer says the cache holds image bytes now. Capacity is a byte budget. Each entry has a different size. Android&#8217;s own <a href=\"https:\/\/developer.android.com\/reference\/android\/util\/LruCache\" target=\"_blank\" rel=\"noopener\">LruCache<\/a> works this way. Its docs say to override <code>sizeOf<\/code> to size the cache in other units. The docs&#8217; example measures bitmaps in bytes.<\/p>\n<p>The memorized answer has a hidden limit. <code>removeEldestEntry<\/code> runs once per <code>put<\/code>. So it can remove at most one entry per insert. With equal-sized entries, one is always enough. With byte sizes, it isn&#8217;t.<\/p>\n<p>We ran the naive change in Kotlin. It tracks a byte total and still evicts through <code>removeEldestEntry<\/code>. The budget is 100 bytes. Put a at 40 bytes, b at 40, then c at 90. The cache evicts a and stops. It keeps b and c at 130 bytes. That&#8217;s 30 over budget. Nothing fails or throws. A count-based test would never catch it.<\/p>\n<p>The fix is a loop. Evict from the eldest end until the total fits. Android&#8217;s LruCache does the same in <code>trimToSize<\/code>. Its docs say it removes the eldest entries until the total is at or below the limit.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">class ByteLru(private val maxBytes: Int) {\n    private val map = LinkedHashMap&lt;String, ByteArray&gt;(16, 0.75f, true)\n    var bytes = 0\n        private set\n\n    fun get(key: String): ByteArray? = map[key]\n\n    fun put(key: String, value: ByteArray) {\n        map.put(key, value)?.let { bytes -= it.size }\n        bytes += value.size\n        val it = map.entries.iterator()\n        while (bytes &gt; maxBytes &amp;&amp; it.hasNext()) {\n            val eldest = it.next()\n            bytes -= eldest.value.size\n            it.remove()\n        }\n    }\n}<\/pre>\n<p>Run the same three puts. The loop evicts a, then b. The cache keeps c at 90 bytes. The put also handles a replaced key. It subtracts the old value&#8217;s size before adding the new one.<\/p>\n<h2>A full script for the twist<\/h2>\n<p>Here&#8217;s what Nadia says once the interviewer changes capacity to bytes. Adapt the problem, keep the shape.<\/p>\n<blockquote>\n<p>OK, so capacity is now a byte total. My current version breaks on that. <code>removeEldestEntry<\/code> runs once per put, so it removes one entry at most. One large image could need several evictions.<\/p>\n<p>I&#8217;ll keep the LinkedHashMap for the ordering. I&#8217;ll track a running byte total myself. After each put, I&#8217;ll evict from the eldest end in a loop until the total fits.<\/p>\n<p>Let me check it. Budget 100. Put a at 40, b at 40, c at 90. The loop drops a, then b. We end with c at 90.<\/p>\n<p>Two edge cases. A replaced key has to subtract the old size first. And one item bigger than the whole budget would evict everything, itself included. I&#8217;d ask whether to reject that item up front instead.<\/p>\n<\/blockquote>\n<h2>Each part of the script shows the interviewer something recall can&#8217;t<\/h2>\n<p>The first lines name the exact rule that breaks. Nadia doesn&#8217;t start rewriting. She explains why the old code fails. That shows she knew how it worked. A candidate who only recalled the answer can&#8217;t say which line is wrong.<\/p>\n<p>The second part keeps what still holds. The access order is still right. Only the eviction step changes. That&#8217;s a small, specific edit. It shows judgment about what to reuse.<\/p>\n<p>The trace uses numbers that would break the old code. Nadia picks a case where one insert needs two evictions. That&#8217;s the test her first version would fail.<\/p>\n<p>The edge cases end with a question. The oversize item is a product decision. Asking about it shows she sees the requirement behind the code.<\/p>\n<h2>When it only looks familiar, name the part you recognize<\/h2>\n<p>Often you haven&#8217;t seen the exact problem. You&#8217;ve seen its pattern. Don&#8217;t claim more than that. Say which piece you recognize. For example: &#8220;This looks like an LRU cache with a size rule. I&#8217;ve built the count-based version. I haven&#8217;t done one weighted by bytes.&#8221; That tells the interviewer where the new work starts.<\/p>\n<p>If the interviewer asks you directly, answer truthfully either way. A partial match deserves a partial yes. Then do what Nadia did. Explain why the known part works, so you&#8217;re ready when a rule changes. Practicing in Kotlin? Our post on <a href=\"https:\/\/grindloop.ai\/blog\/algorithm-round-android-inter\/\">the algorithm round in Android interviews<\/a> covers that practice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seen the coding interview question before? Say so in one sentence, then prepare for the twist. A Kotlin LRU cache example, its bug and a full script.<\/p>\n","protected":false},"author":3,"featured_media":1012,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Seen the Coding Interview Question Before? Say So, Then Win the Follow-Up","rank_math_description":"Seen the coding interview question before? Say so in one sentence, then prepare for the twist. A Kotlin LRU cache example, its bug and a full script.","rank_math_focus_keyword":"seen the coding interview question before","footnotes":""},"categories":[20],"tags":[15,44,52,16,12,73,45],"class_list":["post-1011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-strategy","tag-android","tag-coding-interview","tag-hiring-process","tag-interview-prep","tag-kotlin","tag-live-coding","tag-technical-interview"],"_links":{"self":[{"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/posts\/1011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/comments?post=1011"}],"version-history":[{"count":1,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/posts\/1011\/revisions"}],"predecessor-version":[{"id":1013,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/posts\/1011\/revisions\/1013"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/media\/1012"}],"wp:attachment":[{"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/media?parent=1011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/categories?post=1011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grindloop.ai\/blog\/wp-json\/wp\/v2\/tags?post=1011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}