<?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 Leonard Yeo on Medium]]></title>
        <description><![CDATA[Stories by Leonard Yeo on Medium]]></description>
        <link>https://medium.com/@leonardyeo-xl?source=rss-42b5efdab50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ey9c5vdp33uqutA54FgNYg@2x.jpeg</url>
            <title>Stories by Leonard Yeo on Medium</title>
            <link>https://medium.com/@leonardyeo-xl?source=rss-42b5efdab50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:38:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leonardyeo-xl/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[Navigating Education Systems: A Comparative Guide to Singapore and U.S. Schooling]]></title>
            <link>https://leonardyeo-xl.medium.com/navigating-education-systems-a-comparative-guide-to-singapore-and-u-s-schooling-c4ab91cef6ad?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4ab91cef6ad</guid>
            <category><![CDATA[education-comparison]]></category>
            <category><![CDATA[singapore-vs-us-schooling]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[singapore]]></category>
            <category><![CDATA[united-states]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 07:38:14 GMT</pubDate>
            <atom:updated>2023-11-16T07:38:14.821Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeVwdQWy-PfMC0Xay4kpEQ.png" /><figcaption>East Meets West in Education: A Visual Comparison of Singaporean and American Schooling Systems, Highlighting Key Aspects from Textbooks to Tradition</figcaption></figure><h3>Introduction: Understanding Diverse Educational Landscapes</h3><p>Are you curious about how the education system in Singapore stacks up against that of the United States? With the global community becoming more interconnected, understanding these differences is not just intriguing but essential for parents, educators, and students navigating international education. In this comprehensive guide, we’ll delve into a detailed comparison of the primary, secondary, and post-secondary education landscapes in Singapore and the U.S.</p><h3>Primary School and Elementary Education: Laying the Foundations</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12525228ce1db3add054543f907b5640/href">https://medium.com/media/12525228ce1db3add054543f907b5640/href</a></iframe><ul><li>Singapore’s focus on core subjects like Mathematics and Science.</li><li>The U.S. system’s broad range of subjects and emphasis on creativity.</li></ul><h3>Secondary School, Middle and High School Education: Shaping Future Pathways</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bb4dcabb7988c9ed0e027579e6a0f80/href">https://medium.com/media/3bb4dcabb7988c9ed0e027579e6a0f80/href</a></iframe><blockquote>*Note: In Singapore, Secondary 5 is an additional year for students in the Normal (Academic) stream, preparing them for the GCE ‘O’ Level examinations. Students in the Express stream typically complete their secondary education in 4 years (Secondary 1 to 4).</blockquote><h4>Educational Structures and Objectives</h4><ul><li>Singapore’s seamless progression from Secondary 1 to 4 or 5.</li><li>The U.S.’s division into middle school and high school.</li></ul><h3>Post-Secondary Education: Diverse Pathways to Success</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/209b0cefc8885fc6c357bc50bcddb32b/href">https://medium.com/media/209b0cefc8885fc6c357bc50bcddb32b/href</a></iframe><h4>Singapore’s Unique Institutions vs. U.S. Equivalents</h4><ul><li>Junior College (JC): Bridging high school and college.</li><li>Polytechnic: Career-oriented education akin to community colleges.</li><li>Institute of Technical Education (ITE): Practical skills for specific industries, similar to U.S. vocational schools.</li></ul><h3>Conclusion: Embracing Educational Diversity</h3><p>Through this comparative journey, we’ve seen how Singapore and the U.S. offer distinct yet equally enriching educational experiences. Whether you’re a student considering international education, a parent planning your child’s educational future, or an educator seeking broader perspectives, understanding these differences is key to making informed decisions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4ab91cef6ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master of Science in Security by Design (MSSD) in SUTD After 1 Year (As a Part Time Student)]]></title>
            <link>https://leonardyeo-xl.medium.com/master-of-science-in-security-by-design-mssd-in-sutd-after-1-year-as-a-part-time-student-97e0dae94f52?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/97e0dae94f52</guid>
            <category><![CDATA[stem]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[university]]></category>
            <category><![CDATA[master-of-science]]></category>
            <category><![CDATA[masters-degree]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Tue, 27 Sep 2022 13:06:40 GMT</pubDate>
            <atom:updated>2022-09-27T13:06:40.785Z</atom:updated>
            <content:encoded><![CDATA[<h3>Master of Science in Security by Design (MSSD) in SUTD After 1 Year (As a Part Time Student) in 2022</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cNOfUZ-t2i_hurKW" /><figcaption>Photo by <a href="https://unsplash.com/@jefflssantos?utm_source=medium&amp;utm_medium=referral">Jefferson Santos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Background Context</h3><p><strong>Master of Science in Security by Design</strong> is one-of-a-kind in that it focuses on bringing cybersecurity at the design stage of critical infrastructure and enterprise networks.</p><p>This focus enables the training of a special type of engineer who can not only contribute to the security of organizations that do online business, but also to the security of large scale public infrastructures such as power grid, water treatment and distribution, transportation, and oil and natural gas processing.</p><p>Students can either decide to finish the programme in 1 year (full-time) or 2 years (part-time).</p><h3>Curriculum</h3><ul><li>Foundations of CyberSecurity (core)</li><li>Computer Networks (core)</li><li>System Security (core)</li><li>Secure Software Engineering (core)</li><li>Security Tools Lab 1 (core)</li><li>Security Tools Lab 2 (core)</li><li>Cyber Crime (elective)</li><li>Machine Learning (elective)</li><li>Cyber Physical Systems (elective)</li><li>Blockchain Systems (elective)</li><li>Thesis (core)</li></ul><p>Holistically, the programme covers fundamentals and domain specific areas such as Blockchain Security and Cyber Physical Systems.</p><p>Since I am doing this programme as a part-time student, I will be covering modules that I have completed in year 1.</p><h3>Foundations of CyberSecurity</h3><h4>Course Overview</h4><ul><li><strong>Introduction</strong>: CIA, System &amp; Attacker models, Security policy &amp; mechanism, Access control matrix &amp; delegation and etc.</li><li><strong>Security Policies</strong>: MAC, DAC, Bell-LaPadula model, Biba model, Lipner model and etc.</li><li><strong>Information Flow</strong>: Explicit &amp; implicit information flows, Entropy &amp; uncertainty, Compiler-based &amp; Execution-based mechanisms and etc.</li><li><strong>Distributed Systems</strong>: Availability, Concurrency, Deadlock &amp; semaphore, Fault tolerance &amp; recovery and etc.</li><li><strong>Symmetric Encryption</strong>: Attacks (COA, KPA, CPA, CCA), Block ciphers (AES), Block cipher modes (ECB, CBC, OFB, CTR) and etc.</li><li><strong>Hash &amp; MAC</strong>: Merkle-Damgard construction, MD-based hash functions, Hash-based MACs, Cipher-based MACs and etc.</li><li><strong>Secure Channel and Randomness</strong>: Design of PRNG, Authenticated encryption (CCM, GCM), Order of authentication &amp; encryption and etc.</li><li><strong>Public-Key Cryptography</strong>: (E)GCD algorithms, Cyclic groups &amp; CRT, Diffie-Hellman algorithm, RSA algorithm and etc.</li><li><strong>Cryptographic Protocols</strong>: Key negotiation (authenticated DH), Key distribution (Kerberos), Entity authentication, Non-repudiation and etc.</li><li><strong>Public Key Infrastructure</strong>: Trust models, Digital certificates &amp; revocation.</li></ul><h4>My Experience</h4><p>Even though this covered a broad overview of the fundamentals in cyber security, I barely passed. Most of the concepts were mathematical in nature and I had difficulty understanding the lectures. The module final grade consists of the assessment on 2 exam papers, 10 individual and 10 group assignments. The individual and group assignments are relatively easier to score, however, the exam papers are monsters (even though it is open book assessment).</p><h3>Computer Networks</h3><h4>Course Overview</h4><ul><li>Networking basics</li><li>Network performance</li><li>Client-server applications</li><li>Peer-to-peer networking</li><li>Transport layer (design principles)</li><li>Transport layer (TCP)</li><li>Network layer (design principles and IP)</li><li>Network layer (interdomain routing and BGP)</li></ul><h4>My Experience</h4><p>Even though this covered a broad overview of the fundamentals in computer networking, I barely passed. The module final grade consists of the assessment on 2 exam papers and an individual project. The exam papers have a much higher weightage and easily killed me (even though we are allowed to bring in a 2 sided handwritten cheat-sheet). The project is relatively easier as it was more practical in nature.</p><h3>Systems Security</h3><h4>Course Overview</h4><ul><li>Threat modelling, security principles, OS level access control</li><li>Memory safety and protection mechanisms</li><li>Network Security</li><li>Internet Security</li><li>Web Security</li><li>Anonymity and Privacy, Tor</li><li>User Authentication</li><li>Side Channel Attacks</li><li>Mobile Security</li><li>Paper Criticism</li></ul><h4>My Experience</h4><p>By far, one of the more interesting modules in MSSD. I did much better compared to foundational modules. The module final grade consists of the assessment on 2 exam papers, 8 group assignments and a group paper criticism. The group assignments and paper criticism helped a lot in calculating my final grade. The group assignments are more practical (coding involved) in nature. The exam papers are not that difficult but it is a closed book assessment.</p><h3>Cyber Crime</h3><h4>Course Overview</h4><ul><li>Research Study</li><li>Forensics Labs</li></ul><h4>My Experience</h4><p>There are just 2 components to this module. The research study has a 90% weightage towards the final grade. In this research study, the students work in groups and can expect to choose a topic. This topic defines what they are going to research on, how are they going to conduct the research and justification via statistics. In my opinion, this module could in some ways prepare for writing a thesis paper as part of the graduation requirements.</p><h3>Security Tools Lab 1</h3><h4>Course Overview</h4><ul><li>Passwords and Hashing</li><li>Breaking Simple Ciphers</li><li>BGP Attacks and Mininet</li><li>Network Exploitation</li><li>ARP Spoofing and TLS</li><li>Software Defined Networking (SDN)</li><li>Data Analytics</li><li>Web Attacks</li><li>Machine Learning</li><li>Project (Data Analytics, Network Anomaly Detection, SSL Grader, Passwords)</li></ul><h4>My Experience</h4><p>One of the most hands on practical modules in MSSD. In every week, the students have to submit a report of assignment. This is a individual assignment. At the last 4 weeks before the module ends, each student have to work on a project which they will submit. Overall, the pace of submitting a assignment every week could be overwhelming for some students as they could have work commitments. I particularly enjoy web attacks and network exploitation. By far, I scored well for this module.</p><h3>Security Tools Lab 2</h3><h4>Course Overview</h4><ul><li>Random Numbers and Cryptography</li><li>Breaking Synchronous Stream Ciphers</li><li>Hashing Collision Attacks</li><li>Buffer Overflow and Race Conditions</li><li>Email Security</li><li>Introduction to Cyber Physical Systems</li><li>Blockchain</li><li>Privilege Escalation Attacks</li><li>Ethereum and Smart Contracts</li><li>Project (Security Ops Centre, DAPP Distributed Storage, Dark Web Analysis, Email Spam Filtering Techniques)</li></ul><h4>My Experience</h4><p>One of the most hands on practical modules in MSSD. In every week, the students have to submit a report of assignment. This is a individual assignment. At the last 4 weeks before the module ends, each student have to work on a project which they will submit. Overall, the pace of submitting a assignment every week could be overwhelming for some students as they could have work commitments. I particularly enjoyed Buffer Overflow and Privilege Escalation Attacks. By far, I scored well for this module.</p><h3>Takeaways</h3><p>I can’t conclude my final verdict on the programme yet. I have to wait until I have submitted my thesis paper before making a final judgment. Stay tuned to <strong>Master of Science in Security by Design (MSSD) in SUTD After 2 Years (As a Part Time Student) in 2023</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97e0dae94f52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode 75 Level 1 — Is Subsequence]]></title>
            <link>https://levelup.gitconnected.com/leetcode-75-level-1-is-subsequence-fe5183c02ce9?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe5183c02ce9</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[two-pointers]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Sun, 03 Jul 2022 16:20:48 GMT</pubDate>
            <atom:updated>2022-07-03T16:20:48.581Z</atom:updated>
            <content:encoded><![CDATA[<h3>LeetCode 75 Level 1 — Is Subsequence</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uSbuH6drGy6WOc1-" /><figcaption>Photo by <a href="https://unsplash.com/es/@bradyn?utm_source=medium&amp;utm_medium=referral">Bradyn Trollip</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Problem</h3><p>Given two strings s and t, return true<em> if </em>s<em> is a </em><strong><em>subsequence</em></strong><em> of </em>t<em>, or </em>false<em> otherwise</em>.</p><p>A <strong>subsequence</strong> of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., &quot;ace&quot; is a subsequence of &quot;abcde&quot; while &quot;aec&quot; is not).</p><h4>Examples</h4><ul><li><strong>Example 1:</strong></li></ul><pre><strong>Input:</strong> s = &quot;abc&quot;, t = &quot;ahbgdc&quot;<br><strong>Output:</strong> true</pre><ul><li><strong>Example 2:</strong></li></ul><pre><strong>Input:</strong> s = &quot;axc&quot;, t = &quot;ahbgdc&quot;<br><strong>Output:</strong> false</pre><h4><strong>Constraints</strong></h4><ul><li>0 &lt;= s.length &lt;= 100</li><li>0 &lt;= t.length &lt;= 104</li><li>s and t consist only of lowercase English letters.</li></ul><h3>Solution</h3><pre>class Solution:<br>    def isSubsequence(self, s: str, t: str) -&gt; bool:<br>        if not s:<br>            return True<br>        if not t:<br>            return False<br>        <br>        sleft, sright = 0, len(s)<br>        tleft, tright = 0, len(t)<br>        <br>        while sleft &lt; sright and tleft &lt; tright:<br>            if s[sleft] == t[tleft]:<br>                sleft += 1<br>            tleft += 1<br>        <br>        return sleft == len(s)</pre><h4>Time and Space Complexity</h4><ul><li><strong>Time Complexity</strong>: O(t). Given t is the number of elements in string t .</li><li><strong>Space Complexity</strong>: O(1). No auxiliary memory space used.</li></ul><h3>Takeaways</h3><p>Thank you for reading this short problem solving question. If anyone knows a better or faster time complexity to solve this question, feel free to comment and feedback. Peace! ✌️</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! More content in the <a href="https://levelup.gitconnected.com/">Level Up Coding publication</a>.<br>Follow: <a href="https://twitter.com/gitconnected">Twitter</a>, <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a>, <a href="https://newsletter.levelup.dev/">Newsletter</a><br><strong>Level Up is transforming tech recruiting ➡️ </strong><a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join our talent collective</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe5183c02ce9" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/leetcode-75-level-1-is-subsequence-fe5183c02ce9">LeetCode 75 Level 1 — Is Subsequence</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode 75 Level 1— Running Sum of 1d Array]]></title>
            <link>https://levelup.gitconnected.com/leetcode-75-level-1-running-sum-of-1d-array-f983c068c36b?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/f983c068c36b</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[prefix-sum]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Sun, 03 Jul 2022 16:20:23 GMT</pubDate>
            <atom:updated>2022-07-03T16:20:23.420Z</atom:updated>
            <content:encoded><![CDATA[<h3>LeetCode 75 Level 1 — Running Sum of 1D Array</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RGk5DQ3gUYB5xdCt" /><figcaption>Photo by <a href="https://unsplash.com/@nadineshaabana?utm_source=medium&amp;utm_medium=referral">Nadine Shaabana</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Problem</h3><p>Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).</p><p>Return the running sum of nums.</p><h4>Examples</h4><ul><li>Example 1:</li></ul><pre><strong>Input:</strong> nums = [1,2,3,4]<br><strong>Output:</strong> [1,3,6,10]<br><strong>Explanation:</strong> Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].</pre><ul><li>Example 2:</li></ul><pre><strong>Input:</strong> nums = [1,1,1,1,1]<br><strong>Output:</strong> [1,2,3,4,5]<br><strong>Explanation:</strong> Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].</pre><ul><li>Example 3:</li></ul><pre><strong>Input:</strong> nums = [3,1,2,10,1]<br><strong>Output:</strong> [3,4,6,16,17]</pre><h3>Solution</h3><pre>class Solution:<br>    def runningSum(self, nums: List[int]) -&gt; List[int]:<br>        if len(nums) == 1:<br>            return nums<br>        <br>        result = []<br>        for i in range(len(nums)):<br>            result.append(sum(nums[:i+1]))<br>        <br>        return result</pre><h4>Time and Space Complexity</h4><ul><li><strong>Time Complexity</strong>: O(n). Given n is the number of elements in nums .</li><li><strong>Space Complexity</strong>: O(n) if we consider the output. O(1) if we do not consider the output.</li></ul><h3>Takeaways</h3><p>Thank you for reading this short problem solving question. If anyone knows a better or faster time complexity to solve this question, feel free to comment and feedback. Peace! ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f983c068c36b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/leetcode-75-level-1-running-sum-of-1d-array-f983c068c36b">LeetCode 75 Level 1— Running Sum of 1d Array</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Minimum Number of Coins that must be Reversed to Achieve Alternating Sequence of Heads and Tails]]></title>
            <link>https://levelup.gitconnected.com/minimum-number-of-coins-that-must-be-reversed-to-achieve-alternating-sequence-of-heads-and-tails-632b72794964?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/632b72794964</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Mon, 02 May 2022 00:07:46 GMT</pubDate>
            <atom:updated>2022-05-02T00:07:46.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bmiWio0Xpvq0Fjqm" /><figcaption>Photo by <a href="https://unsplash.com/@joshappel?utm_source=medium&amp;utm_medium=referral">Josh Appel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Problem</h3><p>There are N coins, each showing either heads or tails. We would like all the coins to form a sequence of alternating heads and tails. What is the minimum number of coins that must be reversed to achieve this?</p><p>Given an array A consisting of N integers representing the coins, returns the minimum number of coins that must be reversed. Consecutive elements of array A represent consecutive coins and contain either a 0 (heads) or a 1 (tails).</p><h4>Examples</h4><ul><li>Example 01</li></ul><pre><strong>Input</strong>: [1,0,1,0,1,1]<br><strong>Output</strong>: 1<br><strong>Explanation</strong>: After reversing the sixth coin, we achieve an alternating sequence of coins [1,0,1,0,1,0].</pre><ul><li>Example 02</li></ul><pre><strong>Input</strong>: [1,1,0,1,1]<br><strong>Output</strong>: 2<br><strong>Explanation</strong>: After reversing the first and fifth coins, we achieve an alternating sequence of coins [0,1,0,1,0].</pre><ul><li>Example 03</li></ul><pre><strong>Input</strong>: [0,1,0]<br><strong>Output</strong>: 0<br><strong>Explanation</strong>: The sequence of coins is already alternating.</pre><ul><li>Example 04</li></ul><pre><strong>Input</strong>: [0,1,1,0]<br><strong>Output</strong>: 2<br><strong>Explanation</strong>: After reversing the first and second coins, we achieve an alternating sequence of coins [1,0,1,0].</pre><h4>Constraints</h4><ul><li>N is an integer within the range [1..100];</li><li>each element of array A is an integer that can have one of the following values: 0, 1</li></ul><h3>Solution</h3><pre>def solution(A):<br>    if len(A) &gt; 0:<br>        count1 = 0<br>        count2 = 0<br>        for index in range(len(A)):<br>            if index % 2 == 0:<br>                if A[index] == 1:<br>                    count1 += 1<br>                if A[index] == 0:<br>                    count2 += 1<br>            else:<br>                if A[index] == 0:<br>                    count1 += 1<br>                if A[index] == 1:<br>                    count2 += 1<br><br>        return min(count1, count2)</pre><h4>Time and Space Complexity</h4><ul><li><strong>Time Complexity</strong>: O(n). Given n is the number of elements in the array.</li><li><strong>Space Complexity</strong>: O(1). No auxiliary memory used.</li></ul><h3>Explanation of Algorithm</h3><p>Here is an example to walk-through the algorithm. Given this input array, [1,0,1,0,1,1] .</p><ul><li><strong>Iteration 1</strong>: Is 0 modulo 2 equals 0? Yes. Is 1 equals 1? Yes. count1 increments by 1. Now count1 is 1.</li><li><strong>Iteration 2</strong>: Is 1 modulo 2 equals 0? No. Is 0 equals 0? Yes. count1 increments by 1. Now count1 is 2.</li><li><strong>Iteration 3</strong>: Is 2 modulo 2 equals 0? Yes. Is 1 equals 1? Yes. count1 increments by 1. Now count1 is 3.</li><li><strong>Iteration 4</strong>: Is 3 modulo 2 equals 0? No. Is 0 equals 0? Yes. count1 increments by 1. Now count1 is 4.</li><li><strong>Iteration 5</strong>: Is 4 modulo 2 equals 0? Yes. Is 1 equals 1? Yes. count1 increments by 1. Now count1 is 5.</li><li><strong>Iteration 6</strong>: Is 5 modulo 2 equals 0? No. Is 1 equals 1? Yes. count2 increments by 1. Now count2 is 1.</li><li>What is the minimum of count1 and count2 ? Answer is 1.</li></ul><p>Here’s another example to walk-through the algorithm. Given this input array, [0,1,1,0] .</p><ul><li><strong>Iteration 1</strong>: Is 0 modulo 2 equals 0? Yes. Is 0 equals 0? Yes. count2 increments by 1. Now count2 is 1.</li><li><strong>Iteration 2</strong>: Is 1 modulo 2 equals 0? No. Is 1 equals 1? Yes. count2 increments by 1. Now count2 is 2.</li><li><strong>Iteration 3</strong>: Is 2 modulo 2 equals 0? Yes. Is 1 equals 1? Yes. count1 increments by 1. Now count1 is 1.</li><li><strong>Iteration 4</strong>: Is 3 modulo 2 equals 0? No. Is 0 equals 0? Yes. count1 increments by 1. Now count1 is 2.</li><li>What is the minimum of count1 and count2 ? Answer is 2.</li></ul><h3>Takeaways</h3><p>Thank you for reading this short problem solving question. If anyone knows a better or faster time complexity to solve this question, feel free to comment and feedback. Peace! ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=632b72794964" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/minimum-number-of-coins-that-must-be-reversed-to-achieve-alternating-sequence-of-heads-and-tails-632b72794964">Minimum Number of Coins that must be Reversed to Achieve Alternating Sequence of Heads and Tails</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge Two Sorted Linked Lists — Leetcode]]></title>
            <link>https://levelup.gitconnected.com/merge-two-sorted-linked-lists-leetcode-7dd56db5c35a?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dd56db5c35a</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 01:18:27 GMT</pubDate>
            <atom:updated>2022-03-22T01:18:27.046Z</atom:updated>
            <content:encoded><![CDATA[<h3>Merge Two Sorted Linked Lists — Leetcode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*2tSha5ShTrJu2_0n0aMlwQ.jpeg" /></figure><h3>Problem</h3><h4>Examples</h4><ul><li><strong>Example 01</strong></li></ul><pre><strong>Input:</strong> list1 = [1,2,4], list2 = [1,3,4]<br><strong>Output:</strong> [1,1,2,3,4,4]</pre><ul><li><strong>Example 02</strong></li></ul><pre><strong>Input:</strong> list1 = [], list2 = []<br><strong>Output:</strong> []</pre><ul><li><strong>Example 03</strong></li></ul><pre><strong>Input:</strong> list1 = [], list2 = [0]<br><strong>Output:</strong> [0]</pre><h3>Algorithm Walk-through</h3><h4>Initial</h4><pre>current = dummy = Node()</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*0Q0yPJRopzpS7VMAy3omsQ.jpeg" /></figure><h4>Iteration 01</h4><pre>if ll1.val &gt;= ll2.val:<br>    current.next = ll2<br>    ll2 = ll2.next<br>current = current.next</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*Emr0jrBRmDpUq3vyJKE6wg.jpeg" /></figure><h4>Iteration 02</h4><pre>if ll1.val &lt; ll2.val:<br>    current.next = ll1<br>    ll1 = ll1.next<br>current = current.next</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*cgsbcf-sV3f1Xg_VIWW9GA.jpeg" /></figure><h4>Iteration 03</h4><pre>if ll1.val &gt;= ll2.val:<br>    current.next = ll2<br>    ll2 = ll2.next<br>current = current.next</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*gVesI2-3mysLYndFsfQ9Vw.jpeg" /></figure><h4>Iteration 04</h4><pre>if ll1.val &gt;= ll2.val:<br>    current.next = ll2<br>    ll2 = ll2.next<br>current = current.next</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*_WHE7py7Re4s8KAuJbYZXQ.jpeg" /></figure><h4>Iteration 05</h4><pre>if ll1.val &gt;= ll2.val:<br>    current.next = ll2<br>    ll2 = ll2.next<br>current = current.next</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*JJBpkCG3HtFyD-Nnquu8Hw.jpeg" /></figure><h4>Finished iterations, Finish off last part of linked list and Return</h4><pre>if ll1 or ll2:<br>    current.next = ll1 if ll1 else ll2<br>            <br>return dummy.next</pre><p>After executing the source code, the state of the linked lists shown in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*dL_I1v4oDIKGT71BFgpIMA.jpeg" /></figure><h3>Solution</h3><pre>class Node:<br>  def __init__(self, val = 0, next=None): <br>    self.val = val<br>    self.next = next<br>      <br>def MergeTwoLists(ll1, ll2):<br>    current = dummy = Node()<br>    while ll1 and ll2:<br>        if ll1.val &lt; ll2.val:<br>            current.next = ll1<br>            ll1 = ll1.next<br>        else:<br>            current.next = ll2<br>            ll2 = ll2.next<br>        current = current.next<br>    <br>    if ll1 or ll2:<br>        current.next = ll1 if ll1 else ll2<br>            <br>    return dummy.next</pre><pre>LL1 = Node(1, Node(2, Node(4)))<br>LL2 = Node(1, Node(3, Node(4)))<br>ll3 = MergeTwoLists(LL1, LL2)</pre><h4>Time and Space Complexity</h4><ul><li>Time Complexity: O(N)</li><li>Space Complexity: O(1)</li></ul><h3>Takeaways</h3><p>Thank you for reading this short problem solving question. If anyone knows a better or faster time complexity to solve this question, feel free to comment and feedback. Peace! ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dd56db5c35a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/merge-two-sorted-linked-lists-leetcode-7dd56db5c35a">Merge Two Sorted Linked Lists — Leetcode</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Queue using Stacks —Leetcode]]></title>
            <link>https://levelup.gitconnected.com/queue-using-stacks-leetcode-972bd1d53a9c?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/972bd1d53a9c</guid>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[stack-data-structure]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[queue-data-structure]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 01:18:17 GMT</pubDate>
            <atom:updated>2022-03-22T01:18:17.146Z</atom:updated>
            <content:encoded><![CDATA[<h3>Queue using Two Stacks —Hackerrank</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*U-hts_af2-XGTY4jh0wrYA.jpeg" /></figure><h3>Problem</h3><p>Implement a queue using two stacks. Then process q queries, where each query is one of the following 3 types:</p><ol><li>Enqueue element x into the end of the queue</li><li>Dequeue the element at the front of the queue</li><li>Print the element at the front of the queue</li></ol><h4>Example</h4><h4>Input</h4><p>The first line contains a single integer, q, denoting the number of queries.</p><p>Each line i of the q subsequent lines contains a single query in the form described in the problem statement above. All three queries start with an integer denoting the query type, but only query 1 is followed by an additional space-separated value, x, denoting the value to be enqueued.</p><ul><li>1 → enqueue</li><li>2 → dequeue</li><li>3 → print front of the queue</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*ditpe6Zf2zy3zQBbzPzjmw.png" /></figure><h4>Output</h4><p>For each query of type 3, print the value of the element at the front of the queue on a new line.</p><pre>14<br>14</pre><h4>Explanation</h4><p>Perform the following sequence of actions:</p><ol><li>Enqueue 42; queue = {42}</li><li>Dequeue the value at the head of the queue, 42; queue = {}</li><li>Enqueue 14; queue = {14}</li><li>Print the value at the head of queue, 14; queue = {14}</li><li>Enqueue 28; queue = {14,28}</li><li>Print the value at the head of queue, 14; queue = {14,28}</li><li>Enqueue 60; queue = {14,28,60}</li><li>Enqueue 78; queue = {14,28,60,78}</li><li>Dequeue the value at the head of the queue, 14; queue = {28,60,78}</li><li>Dequeue the value at the head of the queue, 28; queue = {60,78}</li></ol><h3>Algorithm Walk-through</h3><h4>Enqueue 42</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*HhaHV4Hsdgy4cGcqXheWww.jpeg" /></figure><h4>Dequeue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*WhophOGpjV0lrFINpTe1YQ.jpeg" /></figure><h4>Enqueue 14</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*CzQsK1AAlj5HfnDS99vQzw.jpeg" /></figure><h4>Check the top of Incoming Stack</h4><p>The answer is 14.</p><h4>Enqueue 28</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*-g_1XQ-5b1vi2invVwppAg.jpeg" /></figure><h4>Check the bottom of Incoming Stack</h4><p>The answer is 14.</p><h4>Enqueue 60</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*FdGeNsN0XhOP8q5RCCjv8Q.jpeg" /></figure><h4>Enqueue 78</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*sgAgCX9cxKcUEnu69ZQP2g.jpeg" /></figure><h4>Dequeue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*IhXcpPBqkq6mIPR-6i34yQ.jpeg" /></figure><h4>Dequeue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*u3NT2MVfnho7WqiV-CqZXg.jpeg" /></figure><h4>Check the top of Outgoing Stack</h4><p>The answer is 60.</p><h3>Solution</h3><pre>def Solution(input_arr):<br>    out_stack, in_stack = [], []<br>    <br>    for _input in input_arr:<br>        val = list(map(<br>            int, <br>            _input.split()<br>        ))<br>        <br>        if val[0] == 1:<br>            in_stack.append(val[1])<br>            <br>        elif val[0] == 2:<br>            if not out_stack :<br>                while in_stack:<br>                    out_stack.append(<br>                        in_stack.pop()<br>                    )<br>            out_stack.pop()<br>            <br>        else:<br>            print(out_stack[-1] if out_stack else in_stack[0])<br>            <br>Solution([<br>    &quot;1 42&quot;,<br>    &quot;2&quot;,<br>    &quot;1 14&quot;,<br>    &quot;3&quot;,<br>    &quot;1 28&quot;,<br>    &quot;3&quot;,<br>    &quot;1 60&quot;,<br>    &quot;1 78&quot;,<br>    &quot;2&quot;,<br>    &quot;2&quot;<br>])</pre><h4>Time and Space Complexity</h4><ul><li><strong>Time Complexity</strong>: O(N*N). Given N is the number of elements in the array. There could be a scenario where there are all enqueue commands, then when a dequeue command is invoked, it could take N times to POP from the Incoming Stack and PUSH to the Outgoing Stack.</li><li><strong>Space Complexity</strong>: if we were to consider the stacks, then it should be O(N+N).</li></ul><h3>Takeaways</h3><p>Thank you for reading this short problem solving question. If anyone knows a better or faster time complexity to solve this question, feel free to comment and feedback. Peace! ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=972bd1d53a9c" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/queue-using-stacks-leetcode-972bd1d53a9c">Queue using Stacks —Leetcode</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge Two Sorted Arrays in Python]]></title>
            <link>https://levelup.gitconnected.com/merge-two-sorted-arrays-in-python-a6851f8ff2e2?source=rss-42b5efdab50------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6851f8ff2e2</guid>
            <category><![CDATA[two-pointers]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[hackerrank]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Leonard Yeo]]></dc:creator>
            <pubDate>Fri, 18 Mar 2022 12:08:25 GMT</pubDate>
            <atom:updated>2022-03-18T12:08:25.233Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*eF1cWMZK6Zf9ppw7U1Tnrg.png" /></figure><h3>Problem</h3><p>Given two sorted arrays, merge them into a sorted manner.</p><h4>Examples</h4><ul><li>Example 01</li></ul><pre>Input: arr1 = [3, 5, 6, 10], arr2 = [1, 2, 7, 8, 11, 12]<br>Output: arr3 = [1, 2, 3, 5, 6, 7, 8, 10, 11, 12]</pre><ul><li>Example 02</li></ul><pre>Input: arr1 = [1, 3, 4, 5], arr2 = [2, 4, 6, 8]<br>Output: arr3 = [1, 2, 3, 4, 4, 5, 6, 8]</pre><ul><li>Example 03</li></ul><pre>Input: arr1 = [5, 8, 9], arr2 = [4, 7, 8]<br>Output: arr3 = [4, 5, 7, 8, 8, 9]</pre><h3>Solution 01</h3><h4>Pseudocode</h4><ol><li>Create an array arr3 by concatenatingarr1 and arr2.</li><li>Sort arr3 .</li></ol><h4>Source code</h4><pre>def merge(num1, num2):<br>    arr3 = num1+num2<br>    arr3.sort()<br>    return arr3<br>    <br>arr1 = [3, 5, 6, 10]<br>arr2 = [1, 2, 7, 8, 11, 12]<br>assert merge(arr1, arr2) == [1, 2, 3, 5, 6, 7, 8, 10, 11, 12]<br>arr1 = [1, 3, 4, 5]<br>arr2 = [2, 4, 6, 8]<br>assert merge(arr1, arr2) == [1, 2, 3, 4, 4, 5, 6, 8]<br>arr1 = [5, 8, 9]<br>arr2 = [4, 7, 8]<br>assert merge(arr1, arr2) == [4, 5, 7, 8, 8, 9]</pre><h4>Time and Space Complexity</h4><ul><li><strong>Time Complexity</strong>: O((N+M)log(N+M)). Given N is the number of elements in arr1 and M is the number of elements in arr2 .</li><li><strong>Space Complexity</strong>: O(N+M)</li></ul><h3>Solution 02</h3><h4>Pseudocode</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*LLryzAD6n_-icUgOT4_eSA.png" /><figcaption>Credits: GeeksForGeeks</figcaption></figure><ol><li>Create an array arr3 of length/size arr1 + arr2 .</li><li>Simultaneously traverse arr1 and arr2.</li></ol><ul><li>Pick smaller of current elements in arr1 and arr2 , copy this smaller element to the next position in arr3 and move ahead in arr3 and the array whose element is picked.</li></ul><p>3. If there are remaining elements in arr1 or arr2 , copy them in arr3 .</p><h4>Source code</h4><pre>def merge(num1, num2):<br>    arr3 = [None]*(len(num1)+len(num2))<br>    i, j, k = 0, 0, 0<br>    <br>    while i &lt; len(arr1) and j &lt; len(arr2):<br>        if arr1[i] &lt; arr2[j]:<br>            arr3[k] = arr1[i]<br>            k += 1<br>            i += 1<br>        else:<br>            arr3[k] = arr2[j]<br>            k += 1<br>            j += 1<br>            <br>    while i &lt; len(num1):<br>        arr3[k] = arr1[i];<br>        k += 1<br>        i += 1<br>        <br>    while j &lt; len(num2):<br>        arr3[k] = arr2[j];<br>        k += 1<br>        j += 1<br>    <br>    return arr3<br>                <br>arr1 = [3, 5, 6, 10]<br>arr2 = [1, 2, 7, 8, 11, 12]<br>assert merge(arr1, arr2) == [1, 2, 3, 5, 6, 7, 8, 10, 11, 12]<br>arr1 = [1, 3, 4, 5]<br>arr2 = [2, 4, 6, 8]<br>assert merge(arr1, arr2) == [1, 2, 3, 4, 4, 5, 6, 8]<br>arr1 = [5, 8, 9]<br>arr2 = [4, 7, 8]<br>assert merge(arr1, arr2) == [4, 5, 7, 8, 8, 9]</pre><h4>Time and Space Complexity</h4><ul><li><strong>Time Complexity</strong>: O(N+M). Given N is the number of elements in arr1 and M is the number of elements in arr2 .</li><li><strong>Space Complexity</strong>: O(N+M)</li></ul><h3>Takeaways</h3><p>Thank you for reading this short problem solving question. If anyone knows a better or faster time complexity to solve this question, feel free to comment and feedback. Peace! ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6851f8ff2e2" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/merge-two-sorted-arrays-in-python-a6851f8ff2e2">Merge Two Sorted Arrays in Python</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>