<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tanya Rajhans on Medium]]></title>
        <description><![CDATA[Stories by Tanya Rajhans on Medium]]></description>
        <link>https://medium.com/@tanyarajhans?source=rss-6206fad8ae6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bqeQv0i7UXYNyTgVcNcgyQ.jpeg</url>
            <title>Stories by Tanya Rajhans on Medium</title>
            <link>https://medium.com/@tanyarajhans?source=rss-6206fad8ae6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:50:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanyarajhans/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LeetCode Hard DP Problem [Asked in Google]]]></title>
            <link>https://tanyarajhans.medium.com/leetcode-hard-dp-problem-asked-in-google-f064fd547bfb?source=rss-6206fad8ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f064fd547bfb</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[leetcode-hard]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <dc:creator><![CDATA[Tanya Rajhans]]></dc:creator>
            <pubDate>Wed, 16 Mar 2022 05:48:35 GMT</pubDate>
            <atom:updated>2022-03-16T07:37:11.531Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s discuss an interesting interview problem on Dynamic Programming. ✅</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DENauUixUf2DS-VfgKCXlA.png" /></figure><p>An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p><ul><li>‘A’: Absent.</li><li>‘L’: Late.</li><li>‘P’: Present.</li></ul><p>Any student is eligible for an attendance award if they meet both of the following criteria:</p><ul><li>The student was absent (‘A’) for strictly fewer than 2 days total.</li><li>The student was never late (‘L’) for 3 or more consecutive days.</li></ul><p>Given an integer n, return <em>the number of possible attendance records of length</em> n<em> that make a student eligible for an attendance award. The answer may be very large, so return it modulo </em>10⁹ + 7.</p><p>Problem Link: <a href="https://leetcode.com/problems/student-attendance-record-ii/">https://leetcode.com/problems/student-attendance-record-ii/</a></p><p>Constraints: 1 &lt;= n &lt;= 10⁵</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHXU7uAFsjx0hukbQZsHqA.png" /></figure><p>Initial thoughts: 💭</p><p>We can go with the brute force recursive approach which will definitely TLE if we consider three cases of placing a ‘P’, an ‘A’, and an ‘L’ at the current index. We can sense there are going to be overlapping subproblems. What do I smell? Recursion with Memoization.</p><p>How can we achieve this? 🤔</p><p>We can maintain a cache, i.e, dp array which will store the number of attendance records according to the number of absent and consecutive late counts till index i. Initially, we fill this with -1 as all the states are unvisited.</p><p>If we ever encounter a number of absences greater than 1 or a number of consecutive late counts greater than 2, our answer is zero. If we find the current state is already visited, it means we have encountered the same state before so we return it as an answer. Otherwise, we have three cases to explore:</p><p>1. Put P at the current index, the consecutive late count will become 0 and the absent count will remain the same.</p><p>2. Put L at the current index, the consecutive late count will increase by 1 and the absent count remains the same.</p><p>3. Put A at the current index, the consecutive late count becomes 0, and the absent count increases by 1.</p><p>When our index reaches up to n, we can return 1 as we have found a valid order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1IF1bHf8xmCiSujFzJCNsQ.png" /></figure><p>Time Complexity: O(n)</p><p>Space Complexity: O(n*6) ~ O(n)</p><p>Solution link: <a href="https://leetcode.com/problems/student-attendance-record-ii/discuss/1853789/Top-Down-DP-or-C%2B%2B">https://leetcode.com/problems/student-attendance-record-ii/discuss/1853789/Top-Down-DP-or-C%2B%2B</a></p><p>Please drop any suggestions below, and follow me if you like my content :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f064fd547bfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>