<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: luparinx</title>
    <description>The latest articles on DEV Community by luparinx (@luparinx).</description>
    <link>https://dev.to/luparinx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3080756%2F05eb86a4-72eb-4919-9194-9252e014de0f.jpg</url>
      <title>DEV Community: luparinx</title>
      <link>https://dev.to/luparinx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/luparinx"/>
    <language>en</language>
    <item>
      <title>Day 09/90: Mastering the Longest Palindromic Substring - Center Expansion Technique in TypeScript</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Thu, 01 May 2025 14:54:31 +0000</pubDate>
      <link>https://dev.to/luparinx/day-0990-mastering-the-longest-palindromic-substring-center-expansion-technique-in-typescript-3p1i</link>
      <guid>https://dev.to/luparinx/day-0990-mastering-the-longest-palindromic-substring-center-expansion-technique-in-typescript-3p1i</guid>
      <description>&lt;h1&gt;
  
  
  Longest Palindromic Substring
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Today we're solving one of LeetCode's classic string problems - finding the longest palindromic substring. This is problem #5, and it's an excellent way to understand dynamic programming and center expansion techniques in string algorithms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;br&gt;
Given a string &lt;code&gt;s&lt;/code&gt;, return the longest substring that reads the same forwards and backwards (a palindrome).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
'''&lt;br&gt;
Input: "babad"&lt;br&gt;
Output: "bab" or "aba"&lt;br&gt;
Explanation: Both "bab" and "aba" are valid palindromic substrings.&lt;br&gt;
'''&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Optimal Solution&lt;/strong&gt;&lt;br&gt;
'''typescript&lt;br&gt;
function longestPalindrome(s: string): string {&lt;br&gt;
    let start = 0;&lt;br&gt;
    let end = 0;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; s.length; i++) {
    const [left1, right1] = expandAroundCenter(s, i, i);
    const [left2, right2] = expandAroundCenter(s, i, i + 1);

    if (right1 - left1 &amp;gt; end - start) {
        start = left1;
        end = right1;
    }
    if (right2 - left2 &amp;gt; end - start) {
        start = left2;
        end = right2;
    }
}

return s.substring(start, end + 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;function expandAroundCenter(s: string, left: number, right: number): [number, number] {&lt;br&gt;
    while (left &amp;gt;= 0 &amp;amp;&amp;amp; right &amp;lt; s.length &amp;amp;&amp;amp; s[left] === s[right]) {&lt;br&gt;
        left--;&lt;br&gt;
        right++;&lt;br&gt;
    }&lt;br&gt;
    return [left + 1, right - 1];&lt;br&gt;
}&lt;br&gt;
'''&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This solution is:&lt;/strong&gt;&lt;br&gt;
✅ Efficient - O(n²) time complexity (optimal for this problem)&lt;br&gt;
✅ Space-optimized - O(1) additional space&lt;br&gt;
✅ Clean - Uses simple center expansion logic&lt;br&gt;
✅ Handles both odd and even length palindromes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Center Expansion Technique&lt;/strong&gt;: Checks each character (and between characters) as potential palindrome centers&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual Expansion&lt;/strong&gt;: Expands for both odd-length (single center) and even-length (dual center) palindromes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bounds Tracking&lt;/strong&gt;: Maintains the start/end indices of the longest palindrome found&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Length Comparison&lt;/strong&gt;: Continuously updates when longer palindromes are found&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alternative Approaches&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Dynamic Programming Approach&lt;/strong&gt;:&lt;br&gt;
'''typescript&lt;br&gt;
function longestPalindrome(s: string): string {&lt;br&gt;
    const n = s.length;&lt;br&gt;
    const dp: boolean[][] = Array(n).fill(false).map(() =&amp;gt; Array(n).fill(false));&lt;br&gt;
    let result = '';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = n - 1; i &amp;gt;= 0; i--) {
    for (let j = i; j &amp;lt; n; j++) {
        dp[i][j] = s[i] === s[j] &amp;amp;&amp;amp; (j - i &amp;lt; 3 || dp[i + 1][j - 1]);
        if (dp[i][j] &amp;amp;&amp;amp; j - i + 1 &amp;gt; result.length) {
            result = s.substring(i, j + 1);
        }
    }
}
return result;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
'''&lt;br&gt;
&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Systematic approach using DP table&lt;/li&gt;
&lt;li&gt;Easier to understand the recurrence relation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;O(n²) space complexity&lt;/li&gt;
&lt;li&gt;More complex implementation&lt;/li&gt;
&lt;li&gt;Slower due to table initialization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Brute Force Approach&lt;/strong&gt;:&lt;br&gt;
'''typescript&lt;br&gt;
function longestPalindrome(s: string): string {&lt;br&gt;
    let longest = '';&lt;br&gt;
    for (let i = 0; i &amp;lt; s.length; i++) {&lt;br&gt;
        for (let j = i; j &amp;lt; s.length; j++) {&lt;br&gt;
            const substr = s.substring(i, j + 1);&lt;br&gt;
            if (isPalindrome(substr) &amp;amp;&amp;amp; substr.length &amp;gt; longest.length) {&lt;br&gt;
                longest = substr;&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
    return longest;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function isPalindrome(s: string): boolean {&lt;br&gt;
    return s === s.split('').reverse().join('');&lt;br&gt;
}&lt;br&gt;
'''&lt;br&gt;
&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple to understand&lt;/li&gt;
&lt;li&gt;No advanced concepts needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;O(n³) time complexity&lt;/li&gt;
&lt;li&gt;Extremely inefficient for longer strings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Edge Cases to Consider&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Empty string&lt;/li&gt;
&lt;li&gt;Single character string ("a")&lt;/li&gt;
&lt;li&gt;All characters same ("aaaaa")&lt;/li&gt;
&lt;li&gt;No palindromes longer than 1 character ("abcde")&lt;/li&gt;
&lt;li&gt;Even-length palindromes ("abba")&lt;/li&gt;
&lt;li&gt;Mixed case with special characters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Performance Considerations&lt;/strong&gt;&lt;br&gt;
The optimal solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Processes each character as a potential center&lt;/li&gt;
&lt;li&gt;Expands outward in O(n) time per center&lt;/li&gt;
&lt;li&gt;Total O(n²) time complexity (optimal for this problem)&lt;/li&gt;
&lt;li&gt;Uses constant space (just stores indices)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common Mistakes to Avoid&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forgetting to check both odd and even length palindromes&lt;/li&gt;
&lt;li&gt;Incorrect bounds when expanding from center&lt;/li&gt;
&lt;li&gt;Not updating the longest palindrome properly&lt;/li&gt;
&lt;li&gt;Off-by-one errors in substring extraction&lt;/li&gt;
&lt;li&gt;Not handling edge cases like empty strings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-world Applications&lt;/strong&gt;&lt;br&gt;
This algorithm has practical uses in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DNA sequence analysis (palindromic sequences)&lt;/li&gt;
&lt;li&gt;Cryptography (pattern matching)&lt;/li&gt;
&lt;li&gt;Data compression (finding repeated patterns)&lt;/li&gt;
&lt;li&gt;Text processing (finding mirrored structures)&lt;/li&gt;
&lt;li&gt;Plagiarism detection (finding similar structures)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The center expansion approach provides the best combination of:&lt;br&gt;
🔥 Optimal O(n²) time complexity&lt;br&gt;
🔥 Minimal O(1) space usage&lt;br&gt;
🔥 Clean implementation&lt;br&gt;
🔥 Robust handling of all edge cases&lt;/p&gt;

&lt;p&gt;Understanding this center expansion technique will help with many other string manipulation problems. It's a fundamental pattern that demonstrates how we can often find efficient solutions by looking for natural symmetries in problems!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 08/90: Solving the Longest Substring Without Repeating Characters Problem in TypeScript/JavaScript</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Wed, 30 Apr 2025 15:27:33 +0000</pubDate>
      <link>https://dev.to/luparinx/day-0890-solving-the-longest-substring-without-repeating-characters-problem-in-29e0</link>
      <guid>https://dev.to/luparinx/day-0890-solving-the-longest-substring-without-repeating-characters-problem-in-29e0</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Today, we're tackling a classic string manipulation problem - finding the length of the longest substring without repeating characters. This is LeetCode Problem 3, and it's a great way to understand sliding window techniques and hash map usage in algorithms.&lt;/p&gt;

&lt;p&gt;**The Problem&lt;br&gt;
**Given a string s, find the length of the longest substring without repeating characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Optimal Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function lengthOfLongestSubstring(s: string): number {
    let start = 0;
    let maxLength = 0;
    const charMap = new Map&amp;lt;string, number&amp;gt;();

    for (let end = 0; end &amp;lt; s.length; end++) {
        const currentChar = s[end];
        if (charMap.has(currentChar)) {
            const prevIndex = charMap.get(currentChar)!;
            if (prevIndex &amp;gt;= start) {
                start = prevIndex + 1;
            }
        }
        charMap.set(currentChar, end);
        maxLength = Math.max(maxLength, end - start + 1);
    }

    return maxLength;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;This solution is:&lt;br&gt;
*&lt;/em&gt;✅ Efficient - O(n) time complexity&lt;br&gt;
✅ Space-optimized - O(min(m, n)) space (m = character set size)&lt;br&gt;
✅ Clean - Uses a single pass with smart window adjustment&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
Sliding Window Technique: Maintains a window of characters that haven't repeated&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hash Map Tracking&lt;/strong&gt;: Stores the most recent index of each character&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Window Adjustment&lt;/strong&gt;: When a duplicate is found, moves the start of the window&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Length Calculation&lt;/strong&gt;: Continuously updates the maximum length found&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alternative Approaches&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Brute Force Approach&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function lengthOfLongestSubstring(s: string): number {
    let max = 0;
    for (let i = 0; i &amp;lt; s.length; i++) {
        const seen = new Set();
        let j = i;
        while (j &amp;lt; s.length &amp;amp;&amp;amp; !seen.has(s[j])) {
            seen.add(s[j]);
            j++;
        }
        max = Math.max(max, j - i);
    }
    return max;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Simple to understand&lt;/p&gt;

&lt;p&gt;No advanced concepts needed&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;O(n²) time complexity&lt;/p&gt;

&lt;p&gt;Inefficient for long strings&lt;/p&gt;

&lt;p&gt;** Optimized Sliding Window with Set**&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function lengthOfLongestSubstring(s: string): number {
    let start = 0;
    let end = 0;
    let maxLength = 0;
    const charSet = new Set&amp;lt;string&amp;gt;();

    while (end &amp;lt; s.length) {
        if (!charSet.has(s[end])) {
            charSet.add(s[end]);
            maxLength = Math.max(maxLength, end - start + 1);
            end++;
        } else {
            charSet.delete(s[start]);
            start++;
        }
    }

    return maxLength;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;O(n) time complexity&lt;/p&gt;

&lt;p&gt;Easier to visualize than the map approach&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Potentially more operations than the optimal solution&lt;/p&gt;

&lt;p&gt;Worst case O(2n) time when many duplicates exist&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edge Cases to Consider&lt;/strong&gt;&lt;br&gt;
Empty string&lt;/p&gt;

&lt;p&gt;All characters the same ("aaaaa")&lt;/p&gt;

&lt;p&gt;No repeating characters ("abcdef")&lt;/p&gt;

&lt;p&gt;Mixed case with special characters&lt;/p&gt;

&lt;p&gt;Very long strings (performance testing)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Considerations&lt;/strong&gt;&lt;br&gt;
The optimal solution:&lt;/p&gt;

&lt;p&gt;Processes each character exactly once&lt;/p&gt;

&lt;p&gt;Uses efficient hash map operations (O(1) average case)&lt;/p&gt;

&lt;p&gt;Minimizes unnecessary computations&lt;/p&gt;

&lt;p&gt;Works well with Unicode characters&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Mistakes to Avoid&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Not properly handling window adjustment&lt;/strong&gt;: Moving start to just prevIndex instead of prevIndex + 1&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgetting&lt;/strong&gt; to update the character's latest position in the map&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Incorrect length calculation&lt;/strong&gt;: Using end - start instead of end - start + 1&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not considering all test cases&lt;/strong&gt;: Especially edge cases with 0 or 1 length strings&lt;/p&gt;

&lt;p&gt;**Real-world Applications&lt;br&gt;
**This algorithm has practical uses in:&lt;/p&gt;

&lt;p&gt;Text editors (finding unique sequences)&lt;/p&gt;

&lt;p&gt;Data analysis (pattern detection)&lt;/p&gt;

&lt;p&gt;Bioinformatics (DNA sequence analysis)&lt;/p&gt;

&lt;p&gt;Cryptography (finding unique character patterns)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The sliding window with hash map tracking provides the best combination of:&lt;br&gt;
🔥 Optimal O(n) time complexity&lt;br&gt;
🔥 Efficient space usage&lt;br&gt;
🔥 Clean implementation&lt;br&gt;
🔥 Robust handling of all edge cases&lt;/p&gt;

&lt;p&gt;Understanding this pattern will help with many other string manipulation and subarray problems. The sliding window technique is a powerful tool to have in your algorithm toolbox!&lt;/p&gt;

</description>
      <category>shadowcoderinx</category>
      <category>luparinxgrind</category>
      <category>codemonarchx</category>
      <category>rinxlevelup</category>
    </item>
    <item>
      <title>Day 07/90: Adding Two Numbers Represented by Linked Lists in TypeScript/JavaScript</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Tue, 29 Apr 2025 14:24:01 +0000</pubDate>
      <link>https://dev.to/luparinx/day-0790-adding-two-numbers-represented-by-linked-lists-in-typescriptjavascript-44nj</link>
      <guid>https://dev.to/luparinx/day-0790-adding-two-numbers-represented-by-linked-lists-in-typescriptjavascript-44nj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When numbers are represented as linked lists where each digit is stored in reverse order, adding them requires careful traversal and carry management. Today, we'll solve LeetCode Problem 2 ("Add Two Numbers") efficiently in TypeScript/JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;br&gt;
Given two non-empty linked lists representing two non-negative integers (with digits stored in reverse order), add the two numbers and return the sum as a linked list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
Input: (2 -&amp;gt; 4 -&amp;gt; 3) + (5 -&amp;gt; 6 -&amp;gt; 4)&lt;br&gt;
Output: 7 -&amp;gt; 0 -&amp;gt; 8&lt;br&gt;
Explanation: 342 + 465 = 807&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Optimal Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {
    let dummy = new ListNode(0);
    let current = dummy;
    let carry = 0;

    while (l1 || l2 || carry) {
        const x = l1 ? l1.val : 0;
        const y = l2 ? l2.val : 0;
        const sum = x + y + carry;

        carry = Math.floor(sum / 10);
        current.next = new ListNode(sum % 10);
        current = current.next;

        if (l1) l1 = l1.next;
        if (l2) l2 = l2.next;
    }

    return dummy.next;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This solution is:&lt;br&gt;
✅ Efficient - O(max(n,m)) time complexity&lt;br&gt;
✅ Clean - Handles all cases uniformly&lt;br&gt;
✅ Memory-friendly - O(max(n,m)) space complexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Dummy Node&lt;/strong&gt;: Simplifies edge cases by providing an initial node&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Carry Propagation&lt;/strong&gt;: Tracks overflow between digit places&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexible While Condition&lt;/strong&gt;: Continues until both lists and carry are exhausted&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Null Handling&lt;/strong&gt;: Safely accesses values using ternary operators&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alternative Approaches&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Recursive Solution&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addTwoNumbers(l1: ListNode | null, l2: ListNode | null, carry = 0): ListNode | null {
    if (!l1 &amp;amp;&amp;amp; !l2 &amp;amp;&amp;amp; !carry) return null;

    const sum = (l1?.val || 0) + (l2?.val || 0) + carry;
    return new ListNode(
        sum % 10,
        addTwoNumbers(l1?.next || null, l2?.next || null, Math.floor(sum / 10))
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;More declarative style&lt;/p&gt;

&lt;p&gt;No dummy node needed&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Potential stack overflow for very long lists&lt;/p&gt;

&lt;p&gt;Slightly less efficient&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Convert-and-Add Approach&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {
    const num1 = listToNum(l1);
    const num2 = listToNum(l2);
    return numToList(num1 + num2);
}

function listToNum(node: ListNode | null): number {
    let num = 0;
    let place = 1;
    while (node) {
        num += node.val * place;
        place *= 10;
        node = node.next;
    }
    return num;
}

function numToList(num: number): ListNode | null {
    if (num === 0) return new ListNode(0);

    let dummy = new ListNode(0);
    let current = dummy;

    while (num &amp;gt; 0) {
        current.next = new ListNode(num % 10);
        current = current.next;
        num = Math.floor(num / 10);
    }

    return dummy.next;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Conceptually simple&lt;/p&gt;

&lt;p&gt;Easy to understand&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Fails with very large numbers (JavaScript number precision limits)&lt;/p&gt;

&lt;p&gt;Inefficient for long lists&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edge Cases to Consider&lt;/strong&gt;&lt;br&gt;
Lists of different lengths&lt;/p&gt;

&lt;p&gt;Final carry (e.g., 5 + 5 = 10)&lt;/p&gt;

&lt;p&gt;Zero values&lt;/p&gt;

&lt;p&gt;Single-digit lists&lt;/p&gt;

&lt;p&gt;Large numbers (but within JavaScript safe integer range)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Considerations&lt;/strong&gt;&lt;br&gt;
The optimal solution:&lt;/p&gt;

&lt;p&gt;Processes each node exactly once&lt;/p&gt;

&lt;p&gt;Uses constant extra space (just the carry)&lt;/p&gt;

&lt;p&gt;Minimizes memory allocations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The dummy node approach provides the best combination of:&lt;br&gt;
🔥 Clean implementation&lt;br&gt;
🔥 Optimal performance&lt;br&gt;
🔥 Robust edge case handling&lt;/p&gt;

</description>
      <category>codemonarchx</category>
      <category>shadowcoderinx</category>
      <category>luparinxgrind</category>
      <category>rinxlevelup</category>
    </item>
    <item>
      <title>Day 06/90: Find the First Occurrence of a Substring in TypeScript/JavaScript</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Sun, 27 Apr 2025 18:14:32 +0000</pubDate>
      <link>https://dev.to/luparinx/day-0690-find-the-first-occurrence-of-a-substring-in-typescriptjavascript-247m</link>
      <guid>https://dev.to/luparinx/day-0690-find-the-first-occurrence-of-a-substring-in-typescriptjavascript-247m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When working with strings in programming, a common task is finding whether one string exists within another and locating its position. In this post, we'll explore how to solve the classic "strStr" problem (LeetCode Problem 28) in TypeScript/JavaScript, achieving optimal performance with just one line of code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given two strings haystack and needle, we need to return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;strStr("sadbutsad", "sad") returns 0&lt;/p&gt;

&lt;p&gt;strStr("leetcode", "leeto") returns -1&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Simple Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most straightforward solution in JavaScript/TypeScript is to use the built-in indexOf method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function strStr(haystack: string, needle: string): number {
    return haystack.indexOf(needle);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;This solution is:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concise&lt;/strong&gt;: Just one line of code&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Efficient&lt;/strong&gt;: Leverages JavaScript's highly optimized string search&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Readable&lt;/strong&gt;: Clearly expresses the intent&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why This Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript's indexOf method is implemented natively in the engine using efficient string search algorithms (likely a variation of the Boyer-Moore or Knuth-Morris-Pratt algorithms). These algorithms provide:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O(n + m)&lt;/strong&gt; average time complexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O(1)&lt;/strong&gt; space complexity&lt;/p&gt;

&lt;p&gt;Optimized performance for real-world use cases&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alternative Approaches&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While the one-liner is ideal for most cases, it's worth understanding alternative implementations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Brute Force Approach&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function strStr(haystack: string, needle: string): number {
    if (needle.length === 0) return 0;
    for (let i = 0; i &amp;lt;= haystack.length - needle.length; i++) {
        let j = 0;
        while (j &amp;lt; needle.length &amp;amp;&amp;amp; haystack[i + j] === needle[j]) {
            j++;
        }
        if (j === needle.length) return i;
    }
    return -1;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Doesn't rely on built-in methods&lt;/p&gt;

&lt;p&gt;Good for learning purposes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;O(n*m) time complexity in worst case&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More verbose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Using substring comparison&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function strStr(haystack: string, needle: string): number {
    if (needle.length === 0) return 0;
    for (let i = 0; i &amp;lt;= haystack.length - needle.length; i++) {
        if (haystack.substring(i, i + needle.length) === needle) {
            return i;
        }
    }
    return -1;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;More readable than brute force&lt;/p&gt;

&lt;p&gt;Still simple to understand&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Creates temporary strings&lt;/p&gt;

&lt;p&gt;Slightly less efficient than indexOf&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Considerations&lt;/strong&gt;&lt;br&gt;
When benchmarking these approaches:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Built-in indexOf&lt;/strong&gt; is consistently the fastest&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Substring comparison&lt;/strong&gt; is about 2-3x slower&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Brute force&lt;/strong&gt; varies widely based on input&lt;/p&gt;

&lt;p&gt;The V8 engine's optimizations make indexOf hard to beat for most real-world scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edge Cases to Consider&lt;/strong&gt;&lt;br&gt;
Always test your solution with:&lt;/p&gt;

&lt;p&gt;Empty needle string ("")&lt;/p&gt;

&lt;p&gt;Needle longer than haystack&lt;/p&gt;

&lt;p&gt;Multiple occurrences&lt;/p&gt;

&lt;p&gt;No occurrences&lt;/p&gt;

&lt;p&gt;Needle at the very start or end&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
For production code, the built-in indexOf method is:&lt;br&gt;
✅ Most performant&lt;br&gt;
✅ Most concise&lt;br&gt;
✅ Most readable&lt;/p&gt;

&lt;p&gt;While implementing your own version can be educational, in practice you should prefer the native implementation unless you have very specific requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Answer&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function strStr(haystack: string, needle: string): number {
    return haystack.indexOf(needle);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>codemonarchx</category>
      <category>luparinxgrind</category>
      <category>shadowcoderinx</category>
      <category>rinxlevelup</category>
    </item>
    <item>
      <title>Day 5/90: Purge Elements Like the Shadow Monarch — Conquering LeetCode’s Remove Element Problem</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Sun, 27 Apr 2025 18:08:27 +0000</pubDate>
      <link>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-i64</link>
      <guid>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-i64</guid>
      <description>&lt;p&gt;“The difference between the hunter and the prey is persistence.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sung Jin-Woo, moments before annihilating a dungeon boss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Daily Quest: System Notification&lt;br&gt;
Objective: Remove all occurrences of val from an array nums in-place.&lt;br&gt;
Difficulty: 🟢 Level 2 (Beginner-Friendly But Tactical)&lt;br&gt;
Reward: +15 DSA XP, +7 In-Place Operation Mastery&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
The Problem: A Dungeon Infested with "Val" Monsters&lt;br&gt;
Imagine your array is a dungeon corridor filled with monsters (elements equal to val). Your mission: eliminate them all without using extra space (no portals or shadow summons allowed).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Input: nums = [3, 2, 2, 3], val = 3 → Output: 2 (nums becomes [2, 2, _, _])&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;Do it in O(n) time.&lt;/p&gt;

&lt;p&gt;Use O(1) memory (no creating new arrays).&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
The Shadow Monarch’s Strategy: Two-Pointer Technique&lt;br&gt;
Sung Jin-Woo doesn’t waste energy fighting every monster head-on. He strategically deploys his forces. Here’s how we mimicked his tactics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Shadow Squad:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scout (i): Traverses the dungeon (array) to identify threats.&lt;/p&gt;

&lt;p&gt;Gatekeeper (k): Secures the safe zone by marking positions for non-monster elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Battle Plan:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Initialize &lt;em&gt;k = 0&lt;/em&gt; (Gatekeeper starts at the dungeon entrance).&lt;/p&gt;

&lt;p&gt;Send the Scout (&lt;em&gt;i&lt;/em&gt;) to inspect every element:&lt;/p&gt;

&lt;p&gt;If nums[i] != val (not a monster), order the Gatekeeper to secure it at nums[k].&lt;/p&gt;

&lt;p&gt;Advance the Gatekeeper (&lt;em&gt;k++&lt;/em&gt;) to fortify the next position.&lt;/p&gt;

&lt;p&gt;Return &lt;em&gt;k&lt;/em&gt; (number of survivors).&lt;/p&gt;




&lt;p&gt;Code Crafting: Commanding the Shadows&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
function removeElement(nums: number[], val: number): number {&lt;br&gt;&lt;br&gt;
    let k = 0; // Gatekeeper starts at the gates&lt;br&gt;&lt;br&gt;
    for (let i = 0; i &amp;lt; nums.length; i++) { // Scout explores the dungeon&lt;br&gt;&lt;br&gt;
        if (nums[i] !== val) { // Found a human survivor!&lt;br&gt;&lt;br&gt;
            nums[k] = nums[i]; // Gatekeeper secures them&lt;br&gt;&lt;br&gt;
            k++; // Advance the safe zone&lt;br&gt;&lt;br&gt;
        }&lt;br&gt;&lt;br&gt;
    }&lt;br&gt;&lt;br&gt;
    return k; // Total survivors&lt;br&gt;&lt;br&gt;
}&lt;br&gt;&lt;br&gt;
Live Battle Simulation:&lt;br&gt;
Input: nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2&lt;/p&gt;

&lt;p&gt;Scout (i=0): 0 is safe → Gatekeeper (k=0) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=1): 1 is safe → Gatekeeper (k=1) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=2): 2 is a monster → skipped.&lt;/p&gt;

&lt;p&gt;Scout (i=6): 4 is safe → Gatekeeper (k=4) secures it.&lt;/p&gt;

&lt;p&gt;Final Array: [0, 1, 3, 0, 4, _, _, _] → &lt;em&gt;k = 5&lt;/em&gt; survivors.&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
Why This Strategy Dominates&lt;/p&gt;

&lt;p&gt;Time Complexity: O(n) — Scout clears the dungeon in one sweep.&lt;/p&gt;

&lt;p&gt;Space Complexity: O(1) — No mana (memory) wasted.&lt;/p&gt;

&lt;p&gt;This is the coding equivalent of Sung Jin-Woo’s Shadow Extraction skill — efficient, ruthless, and resourceful.&lt;/p&gt;




&lt;p&gt;Level-Up Loot (Key Takeaways)&lt;/p&gt;

&lt;p&gt;In-Place Operations Are King: Like Jin-Woo repurposing defeated shadows, we repurposed the array itself.&lt;/p&gt;

&lt;p&gt;Order Doesn’t Matter: Focus on securing survivors, not their sequence (chaos is acceptable in battle).&lt;/p&gt;

&lt;p&gt;Edge Cases:&lt;/p&gt;

&lt;p&gt;Empty dungeon (array)? Return 0.&lt;/p&gt;

&lt;p&gt;All monsters (elements = val)? Return 0.&lt;/p&gt;




&lt;p&gt;Join the Shadow Army (Community Callout)&lt;/p&gt;

&lt;p&gt;Upvote if you’d partner with Sung Jin-Woo in this coding dungeon!&lt;/p&gt;

&lt;p&gt;Comment Below:&lt;/p&gt;

&lt;p&gt;Your favorite in-place algorithm tactic.&lt;/p&gt;

&lt;p&gt;Which Solo Leveling character best represents recursion? (Beru? Igris?)&lt;/p&gt;

&lt;p&gt;Post your solution — let’s see who writes the cleanest code!&lt;/p&gt;

&lt;p&gt;“Those who hesitate are disqualified.” Keep grinding, hunters! 🔥&lt;/p&gt;




&lt;p&gt;Follow My Journey:&lt;/p&gt;

&lt;p&gt;Reddit: Join r/CodeMonarch for daily updates.&lt;/p&gt;

&lt;p&gt;Series Tag: #SoloCodingJourney&lt;/p&gt;

&lt;p&gt;“The System is watching. Are you strong enough to answer?” 🕶️&lt;/p&gt;

</description>
      <category>codemonarchx</category>
    </item>
    <item>
      <title>Day 5/90: Purge Elements Like the Shadow Monarch — Conquering LeetCode’s Remove Element Problem 🗡️</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Sun, 27 Apr 2025 18:06:54 +0000</pubDate>
      <link>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-5ckk</link>
      <guid>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-5ckk</guid>
      <description>&lt;p&gt;“The difference between the hunter and the prey is persistence.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sung Jin-Woo, moments before annihilating a dungeon boss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Daily Quest: System Notification&lt;br&gt;
Objective: Remove all occurrences of val from an array nums in-place.&lt;br&gt;
Difficulty: 🟢 Level 2 (Beginner-Friendly But Tactical)&lt;br&gt;
Reward: +15 DSA XP, +7 In-Place Operation Mastery&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
The Problem: A Dungeon Infested with "Val" Monsters&lt;br&gt;
Imagine your array is a dungeon corridor filled with monsters (elements equal to val). Your mission: eliminate them all without using extra space (no portals or shadow summons allowed).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Input: nums = [3, 2, 2, 3], val = 3 → Output: 2 (nums becomes [2, 2, _, _])&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;Do it in O(n) time.&lt;/p&gt;

&lt;p&gt;Use O(1) memory (no creating new arrays).&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
The Shadow Monarch’s Strategy: Two-Pointer Technique&lt;br&gt;
Sung Jin-Woo doesn’t waste energy fighting every monster head-on. He strategically deploys his forces. Here’s how we mimicked his tactics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Shadow Squad:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scout (i): Traverses the dungeon (array) to identify threats.&lt;/p&gt;

&lt;p&gt;Gatekeeper (k): Secures the safe zone by marking positions for non-monster elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Battle Plan:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Initialize &lt;em&gt;k = 0&lt;/em&gt; (Gatekeeper starts at the dungeon entrance).&lt;/p&gt;

&lt;p&gt;Send the Scout (&lt;em&gt;i&lt;/em&gt;) to inspect every element:&lt;/p&gt;

&lt;p&gt;If nums[i] != val (not a monster), order the Gatekeeper to secure it at nums[k].&lt;/p&gt;

&lt;p&gt;Advance the Gatekeeper (&lt;em&gt;k++&lt;/em&gt;) to fortify the next position.&lt;/p&gt;

&lt;p&gt;Return &lt;em&gt;k&lt;/em&gt; (number of survivors).&lt;/p&gt;




&lt;p&gt;Code Crafting: Commanding the Shadows&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
function removeElement(nums: number[], val: number): number {&lt;br&gt;&lt;br&gt;
    let k = 0; // Gatekeeper starts at the gates&lt;br&gt;&lt;br&gt;
    for (let i = 0; i &amp;lt; nums.length; i++) { // Scout explores the dungeon&lt;br&gt;&lt;br&gt;
        if (nums[i] !== val) { // Found a human survivor!&lt;br&gt;&lt;br&gt;
            nums[k] = nums[i]; // Gatekeeper secures them&lt;br&gt;&lt;br&gt;
            k++; // Advance the safe zone&lt;br&gt;&lt;br&gt;
        }&lt;br&gt;&lt;br&gt;
    }&lt;br&gt;&lt;br&gt;
    return k; // Total survivors&lt;br&gt;&lt;br&gt;
}&lt;br&gt;&lt;br&gt;
Live Battle Simulation:&lt;br&gt;
Input: nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2&lt;/p&gt;

&lt;p&gt;Scout (i=0): 0 is safe → Gatekeeper (k=0) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=1): 1 is safe → Gatekeeper (k=1) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=2): 2 is a monster → skipped.&lt;/p&gt;

&lt;p&gt;Scout (i=6): 4 is safe → Gatekeeper (k=4) secures it.&lt;/p&gt;

&lt;p&gt;Final Array: [0, 1, 3, 0, 4, _, _, _] → &lt;em&gt;k = 5&lt;/em&gt; survivors.&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
Why This Strategy Dominates&lt;/p&gt;

&lt;p&gt;Time Complexity: O(n) — Scout clears the dungeon in one sweep.&lt;/p&gt;

&lt;p&gt;Space Complexity: O(1) — No mana (memory) wasted.&lt;/p&gt;

&lt;p&gt;This is the coding equivalent of Sung Jin-Woo’s Shadow Extraction skill — efficient, ruthless, and resourceful.&lt;/p&gt;




&lt;p&gt;Level-Up Loot (Key Takeaways)&lt;/p&gt;

&lt;p&gt;In-Place Operations Are King: Like Jin-Woo repurposing defeated shadows, we repurposed the array itself.&lt;/p&gt;

&lt;p&gt;Order Doesn’t Matter: Focus on securing survivors, not their sequence (chaos is acceptable in battle).&lt;/p&gt;

&lt;p&gt;Edge Cases:&lt;/p&gt;

&lt;p&gt;Empty dungeon (array)? Return 0.&lt;/p&gt;

&lt;p&gt;All monsters (elements = val)? Return 0.&lt;/p&gt;




&lt;p&gt;Join the Shadow Army (Community Callout)&lt;/p&gt;

&lt;p&gt;Upvote if you’d partner with Sung Jin-Woo in this coding dungeon!&lt;/p&gt;

&lt;p&gt;Comment Below:&lt;/p&gt;

&lt;p&gt;Your favorite in-place algorithm tactic.&lt;/p&gt;

&lt;p&gt;Which Solo Leveling character best represents recursion? (Beru? Igris?)&lt;/p&gt;

&lt;p&gt;Post your solution — let’s see who writes the cleanest code!&lt;/p&gt;

&lt;p&gt;“Those who hesitate are disqualified.” Keep grinding, hunters! 🔥&lt;/p&gt;




&lt;p&gt;Follow My Journey:&lt;/p&gt;

&lt;p&gt;Reddit: Join r/CodeMonarch for daily updates.&lt;/p&gt;

&lt;p&gt;Series Tag: #SoloCodingJourney&lt;/p&gt;

&lt;p&gt;“The System is watching. Are you strong enough to answer?” 🕶️&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 5/90: Purge Elements Like the Shadow Monarch — Conquering LeetCode’s Remove Element Problem 🗡️</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Sat, 26 Apr 2025 17:39:36 +0000</pubDate>
      <link>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-43gm</link>
      <guid>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-43gm</guid>
      <description>&lt;p&gt;“The difference between the hunter and the prey is persistence.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sung Jin-Woo, moments before annihilating a dungeon boss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Daily Quest: System Notification&lt;br&gt;
Objective: Remove all occurrences of val from an array nums in-place.&lt;br&gt;
Difficulty: 🟢 Level 2 (Beginner-Friendly But Tactical)&lt;br&gt;
Reward: +15 DSA XP, +7 In-Place Operation Mastery&lt;/p&gt;

&lt;p&gt;The Problem: A Dungeon Infested with "Val" Monsters&lt;br&gt;
Imagine your array is a dungeon corridor filled with monsters (elements equal to val). Your mission: eliminate them all without using extra space (no portals or shadow summons allowed).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Input: nums = [3, 2, 2, 3], val = 3 → Output: 2 (nums becomes [2, 2, _, _])&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;Do it in O(n) time.&lt;/p&gt;

&lt;p&gt;Use O(1) memory (no creating new arrays).&lt;/p&gt;

&lt;p&gt;The Shadow Monarch’s Strategy: Two-Pointer Technique&lt;br&gt;
Sung Jin-Woo doesn’t waste energy fighting every monster head-on. He strategically deploys his forces. Here’s how we mimicked his tactics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Shadow Squad:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scout (i): Traverses the dungeon (array) to identify threats.&lt;/p&gt;

&lt;p&gt;Gatekeeper (k): Secures the safe zone by marking positions for non-monster elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Battle Plan:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Initialize &lt;em&gt;k = 0&lt;/em&gt; (Gatekeeper starts at the dungeon entrance).&lt;/p&gt;

&lt;p&gt;Send the Scout (&lt;em&gt;i&lt;/em&gt;) to inspect every element:&lt;/p&gt;

&lt;p&gt;If nums[i] != val (not a monster), order the Gatekeeper to secure it at nums[k].&lt;/p&gt;

&lt;p&gt;Advance the Gatekeeper (&lt;em&gt;k++&lt;/em&gt;) to fortify the next position.&lt;/p&gt;

&lt;p&gt;Return &lt;em&gt;k&lt;/em&gt; (number of survivors).&lt;/p&gt;

&lt;p&gt;Code Crafting: Commanding the Shadows&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
function removeElement(nums: number[], val: number): number {&lt;br&gt;&lt;br&gt;
    let k = 0; // Gatekeeper starts at the gates&lt;br&gt;&lt;br&gt;
    for (let i = 0; i &amp;lt; nums.length; i++) { // Scout explores the dungeon&lt;br&gt;&lt;br&gt;
        if (nums[i] !== val) { // Found a human survivor!&lt;br&gt;&lt;br&gt;
            nums[k] = nums[i]; // Gatekeeper secures them&lt;br&gt;&lt;br&gt;
            k++; // Advance the safe zone&lt;br&gt;&lt;br&gt;
        }&lt;br&gt;&lt;br&gt;
    }&lt;br&gt;&lt;br&gt;
    return k; // Total survivors&lt;br&gt;&lt;br&gt;
}&lt;br&gt;&lt;br&gt;
Live Battle Simulation:&lt;br&gt;
Input: nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2&lt;/p&gt;

&lt;p&gt;Scout (i=0): 0 is safe → Gatekeeper (k=0) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=1): 1 is safe → Gatekeeper (k=1) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=2): 2 is a monster → skipped.&lt;/p&gt;

&lt;p&gt;Scout (i=6): 4 is safe → Gatekeeper (k=4) secures it.&lt;/p&gt;

&lt;p&gt;Final Array: [0, 1, 3, 0, 4, _, _, _] → &lt;em&gt;k = 5&lt;/em&gt; survivors.&lt;/p&gt;

&lt;p&gt;Why This Strategy Dominates&lt;/p&gt;

&lt;p&gt;Time Complexity: O(n) — Scout clears the dungeon in one sweep.&lt;/p&gt;

&lt;p&gt;Space Complexity: O(1) — No mana (memory) wasted.&lt;/p&gt;

&lt;p&gt;This is the coding equivalent of Sung Jin-Woo’s Shadow Extraction skill — efficient, ruthless, and resourceful.&lt;/p&gt;

&lt;p&gt;Level-Up Loot (Key Takeaways)&lt;/p&gt;

&lt;p&gt;In-Place Operations Are King: Like Jin-Woo repurposing defeated shadows, we repurposed the array itself.&lt;/p&gt;

&lt;p&gt;Order Doesn’t Matter: Focus on securing survivors, not their sequence (chaos is acceptable in battle).&lt;/p&gt;

&lt;p&gt;Edge Cases:&lt;/p&gt;

&lt;p&gt;Empty dungeon (array)? Return 0.&lt;/p&gt;

&lt;p&gt;All monsters (elements = val)? Return 0.&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
Join the Shadow Army (Community Callout)&lt;/p&gt;

&lt;p&gt;Upvote if you’d partner with Sung Jin-Woo in this coding dungeon!&lt;/p&gt;

&lt;p&gt;Comment Below:&lt;/p&gt;

&lt;p&gt;Your favorite in-place algorithm tactic.&lt;/p&gt;

&lt;p&gt;Which Solo Leveling character best represents recursion? (Beru? Igris?)&lt;/p&gt;

&lt;p&gt;Post your solution — let’s see who writes the cleanest code!&lt;/p&gt;

&lt;p&gt;“Those who hesitate are disqualified.” Keep grinding, hunters! 🔥&lt;/p&gt;

&lt;p&gt;Follow My Journey:&lt;/p&gt;

&lt;p&gt;Reddit: Join r/CodeMonarch for daily updates.&lt;/p&gt;

&lt;p&gt;Series Tag: #SoloCodingJourney&lt;/p&gt;

&lt;p&gt;“The System is watching. Are you strong enough to answer?” 🕶️&lt;/p&gt;

</description>
      <category>shadowcoderinx</category>
      <category>rinxlevelup</category>
      <category>luparinxgrind</category>
      <category>codemonarchx</category>
    </item>
    <item>
      <title>Day 5/90: Purge Elements Like the Shadow Monarch — Conquering LeetCode’s Remove Element Problem 🗡️</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Sat, 26 Apr 2025 17:39:36 +0000</pubDate>
      <link>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-21ll</link>
      <guid>https://dev.to/luparinx/day-590-purge-elements-like-the-shadow-monarch-conquering-leetcodes-remove-element-problem-21ll</guid>
      <description>&lt;p&gt;“The difference between the hunter and the prey is persistence.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sung Jin-Woo, moments before annihilating a dungeon boss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Daily Quest: System Notification&lt;br&gt;
Objective: Remove all occurrences of val from an array nums in-place.&lt;br&gt;
Difficulty: 🟢 Level 2 (Beginner-Friendly But Tactical)&lt;br&gt;
Reward: +15 DSA XP, +7 In-Place Operation Mastery&lt;/p&gt;

&lt;p&gt;The Problem: A Dungeon Infested with "Val" Monsters&lt;br&gt;
Imagine your array is a dungeon corridor filled with monsters (elements equal to val). Your mission: eliminate them all without using extra space (no portals or shadow summons allowed).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Input: nums = [3, 2, 2, 3], val = 3 → Output: 2 (nums becomes [2, 2, _, _])&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;Do it in O(n) time.&lt;/p&gt;

&lt;p&gt;Use O(1) memory (no creating new arrays).&lt;/p&gt;

&lt;p&gt;The Shadow Monarch’s Strategy: Two-Pointer Technique&lt;br&gt;
Sung Jin-Woo doesn’t waste energy fighting every monster head-on. He strategically deploys his forces. Here’s how we mimicked his tactics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Shadow Squad:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scout (i): Traverses the dungeon (array) to identify threats.&lt;/p&gt;

&lt;p&gt;Gatekeeper (k): Secures the safe zone by marking positions for non-monster elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Battle Plan:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Initialize &lt;em&gt;k = 0&lt;/em&gt; (Gatekeeper starts at the dungeon entrance).&lt;/p&gt;

&lt;p&gt;Send the Scout (&lt;em&gt;i&lt;/em&gt;) to inspect every element:&lt;/p&gt;

&lt;p&gt;If nums[i] != val (not a monster), order the Gatekeeper to secure it at nums[k].&lt;/p&gt;

&lt;p&gt;Advance the Gatekeeper (&lt;em&gt;k++&lt;/em&gt;) to fortify the next position.&lt;/p&gt;

&lt;p&gt;Return &lt;em&gt;k&lt;/em&gt; (number of survivors).&lt;/p&gt;

&lt;p&gt;Code Crafting: Commanding the Shadows&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
function removeElement(nums: number[], val: number): number {&lt;br&gt;&lt;br&gt;
    let k = 0; // Gatekeeper starts at the gates&lt;br&gt;&lt;br&gt;
    for (let i = 0; i &amp;lt; nums.length; i++) { // Scout explores the dungeon&lt;br&gt;&lt;br&gt;
        if (nums[i] !== val) { // Found a human survivor!&lt;br&gt;&lt;br&gt;
            nums[k] = nums[i]; // Gatekeeper secures them&lt;br&gt;&lt;br&gt;
            k++; // Advance the safe zone&lt;br&gt;&lt;br&gt;
        }&lt;br&gt;&lt;br&gt;
    }&lt;br&gt;&lt;br&gt;
    return k; // Total survivors&lt;br&gt;&lt;br&gt;
}&lt;br&gt;&lt;br&gt;
Live Battle Simulation:&lt;br&gt;
Input: nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2&lt;/p&gt;

&lt;p&gt;Scout (i=0): 0 is safe → Gatekeeper (k=0) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=1): 1 is safe → Gatekeeper (k=1) secures it.&lt;/p&gt;

&lt;p&gt;Scout (i=2): 2 is a monster → skipped.&lt;/p&gt;

&lt;p&gt;Scout (i=6): 4 is safe → Gatekeeper (k=4) secures it.&lt;/p&gt;

&lt;p&gt;Final Array: [0, 1, 3, 0, 4, _, _, _] → &lt;em&gt;k = 5&lt;/em&gt; survivors.&lt;/p&gt;

&lt;p&gt;Why This Strategy Dominates&lt;/p&gt;

&lt;p&gt;Time Complexity: O(n) — Scout clears the dungeon in one sweep.&lt;/p&gt;

&lt;p&gt;Space Complexity: O(1) — No mana (memory) wasted.&lt;/p&gt;

&lt;p&gt;This is the coding equivalent of Sung Jin-Woo’s Shadow Extraction skill — efficient, ruthless, and resourceful.&lt;/p&gt;

&lt;p&gt;Level-Up Loot (Key Takeaways)&lt;/p&gt;

&lt;p&gt;In-Place Operations Are King: Like Jin-Woo repurposing defeated shadows, we repurposed the array itself.&lt;/p&gt;

&lt;p&gt;Order Doesn’t Matter: Focus on securing survivors, not their sequence (chaos is acceptable in battle).&lt;/p&gt;

&lt;p&gt;Edge Cases:&lt;/p&gt;

&lt;p&gt;Empty dungeon (array)? Return 0.&lt;/p&gt;

&lt;p&gt;All monsters (elements = val)? Return 0.&lt;/p&gt;

&lt;p&gt;--&lt;br&gt;
Join the Shadow Army (Community Callout)&lt;/p&gt;

&lt;p&gt;Upvote if you’d partner with Sung Jin-Woo in this coding dungeon!&lt;/p&gt;

&lt;p&gt;Comment Below:&lt;/p&gt;

&lt;p&gt;Your favorite in-place algorithm tactic.&lt;/p&gt;

&lt;p&gt;Which Solo Leveling character best represents recursion? (Beru? Igris?)&lt;/p&gt;

&lt;p&gt;Post your solution — let’s see who writes the cleanest code!&lt;/p&gt;

&lt;p&gt;“Those who hesitate are disqualified.” Keep grinding, hunters! 🔥&lt;/p&gt;

&lt;p&gt;Follow My Journey:&lt;/p&gt;

&lt;p&gt;Reddit: Join r/CodeMonarch for daily updates.&lt;/p&gt;

&lt;p&gt;Series Tag: #SoloCodingJourney&lt;/p&gt;

&lt;p&gt;“The System is watching. Are you strong enough to answer?” 🕶️&lt;/p&gt;

</description>
      <category>shadowcoderinx</category>
      <category>rinxlevelup</category>
      <category>luparinxgrind</category>
      <category>codemonarchx</category>
    </item>
    <item>
      <title>🏋️ Day 4/100: Crushing LeetCode - Remove Duplicates from Sorted Array</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Sat, 26 Apr 2025 17:35:51 +0000</pubDate>
      <link>https://dev.to/luparinx/day-4100-crushing-leetcode-remove-duplicates-from-sorted-array-4bm3</link>
      <guid>https://dev.to/luparinx/day-4100-crushing-leetcode-remove-duplicates-from-sorted-array-4bm3</guid>
      <description>&lt;h1&gt;
  
  
  Day 4/90: Conquering Duplicates in Sorted Arrays
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;The Challenge:&lt;/strong&gt;&lt;br&gt;
As I continue my 90-day DSA journey, today's battlefield was removing duplicates from a sorted array. The mission seemed simple at first glance, but required careful strategy to execute efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why This Matters:&lt;/strong&gt;&lt;br&gt;
Duplicate removal is fundamental for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data cleaning and preprocessing&lt;/li&gt;
&lt;li&gt;Optimizing storage space&lt;/li&gt;
&lt;li&gt;Preparing data for other algorithms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;My Battle Plan:&lt;/strong&gt;&lt;br&gt;
After analyzing the problem, I chose the two-pointer technique because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The array is already sorted (duplicates are adjacent)&lt;/li&gt;
&lt;li&gt;We need O(1) space complexity&lt;/li&gt;
&lt;li&gt;It allows single-pass operation (O(n) time)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Solution:&lt;/strong&gt;&lt;br&gt;
Here's how I implemented the two-pointer approach:&lt;/p&gt;

&lt;p&gt;'''typescript&lt;br&gt;
function removeDuplicates(nums: number[]): number {&lt;br&gt;
    if (nums.length === 0) return 0;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let uniquePointer = 0;

for (let scout = 1; scout &amp;lt; nums.length; scout++) {
    if (nums[scout] !== nums[uniquePointer]) {
        uniquePointer++;
        nums[uniquePointer] = nums[scout];
    }
}

return uniquePointer + 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
'''&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;uniquePointer&lt;/strong&gt; marks the end of our unique elements section&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;scout&lt;/strong&gt; looks ahead for the next unique element&lt;/li&gt;
&lt;li&gt;When we find a new unique element, we:

&lt;ul&gt;
&lt;li&gt;Move uniquePointer forward&lt;/li&gt;
&lt;li&gt;Place the new element in its position&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Visual Walkthrough:&lt;/strong&gt;&lt;br&gt;
For input [1,1,2,3,3]:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initial: [1,1,2,3,3], uniquePointer=0, scout=1&lt;/li&gt;
&lt;li&gt;First unique found: [1,2,2,3,3], uniquePointer=1&lt;/li&gt;
&lt;li&gt;Second unique found: [1,2,3,3,3], uniquePointer=2&lt;/li&gt;
&lt;li&gt;Final result: 3 unique elements [1,2,3,...]&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Performance Analysis:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; O(n) - Single pass through array&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Space Complexity:&lt;/strong&gt; O(1) - No additional storage needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Insights:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The sorted property is crucial - random order would require different approach&lt;/li&gt;
&lt;li&gt;We're effectively compressing the unique elements to the front&lt;/li&gt;
&lt;li&gt;The remaining elements after our uniquePointer don't need to be cleared&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Common Pitfalls:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Forgetting to handle empty array case&lt;/li&gt;
&lt;li&gt;Off-by-one errors in the return value&lt;/li&gt;
&lt;li&gt;Unnecessary swaps when elements are equal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Testing Your Solution:&lt;/strong&gt;&lt;br&gt;
Always test these edge cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Empty array&lt;/li&gt;
&lt;li&gt;All duplicates&lt;/li&gt;
&lt;li&gt;No duplicates&lt;/li&gt;
&lt;li&gt;Single element array&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Going Further:&lt;/strong&gt;&lt;br&gt;
Try modifying this to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allow at most 2 duplicates&lt;/li&gt;
&lt;li&gt;Work with unsorted arrays&lt;/li&gt;
&lt;li&gt;Return the modified array instead of just count&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts:&lt;/strong&gt;&lt;br&gt;
This problem was an excellent exercise in efficient array manipulation. The two-pointer technique is powerful and appears in many other problems - well worth mastering!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Challenge:&lt;/strong&gt;&lt;br&gt;
Day 5 will tackle merging two sorted arrays - another practical application of similar techniques.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion Question:&lt;/strong&gt;&lt;br&gt;
What other problems can benefit from this two-pointer approach? Share your thoughts below!&lt;/p&gt;

</description>
      <category>codemonarchx</category>
      <category>luparinxgrind</category>
      <category>shadowcoderinx</category>
      <category>rinxlevelup</category>
    </item>
    <item>
      <title>How I Mastered Merging Sorted Lists with Pointer Tactics</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Thu, 24 Apr 2025 19:06:52 +0000</pubDate>
      <link>https://dev.to/luparinx/how-i-mastered-merging-sorted-lists-with-pointer-tactics-4j00</link>
      <guid>https://dev.to/luparinx/how-i-mastered-merging-sorted-lists-with-pointer-tactics-4j00</guid>
      <description>&lt;p&gt;🔥 The Challenge&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Merge two sorted linked lists into one sorted list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: list1 = [1-&amp;gt;2-&amp;gt;4], list2 = [1-&amp;gt;3-&amp;gt;4]  
Output: [1-&amp;gt;1-&amp;gt;2-&amp;gt;3-&amp;gt;4-&amp;gt;4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧠 My Battle Strategy&lt;/p&gt;

&lt;p&gt;I deployed the Two-Pointer Technique with a Dummy Node vanguard:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sentinel Node&lt;/strong&gt;: Created a dummy head to eliminate edge cases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pointer March&lt;/strong&gt;: Advanced through both lists like shadow soldiers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimal Selection&lt;/strong&gt;: Always chose the smaller value to maintain order
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode | null {
  const dummy = new ListNode(0); // 🛡️ My shield against null cases
  let current = dummy;

  while (list1 &amp;amp;&amp;amp; list2) {
    if (list1.val &amp;lt;= list2.val) {
      current.next = list1;
      list1 = list1.next!;
    } else {
      current.next = list2;
      list2 = list2.next!;
    }
    current = current.next;
  }

  current.next = list1 || list2; // ⚡ Finishing move
  return dummy.next;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 Key Insights&lt;br&gt;
&lt;strong&gt;Space Efficiency&lt;/strong&gt;: O(1) space complexity by reusing existing nodes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time Optimization&lt;/strong&gt;: O(n+m) time by single-pass merging&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elegant Edge Handling&lt;/strong&gt;: Dummy node prevents null reference headaches&lt;/p&gt;

&lt;p&gt;🚀 Level Up Challenge&lt;/p&gt;

&lt;p&gt;Can you solve this recursively? Here's a sneak peek:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function mergeRecursive(l1: ListNode | null, l2: ListNode | null): ListNode | null {
  if (!l1) return l2;
  if (!l2) return l1;

  if (l1.val &amp;lt; l2.val) {
    l1.next = mergeRecursive(l1.next, l2);
    return l1;
  } else {
    l2.next = mergeRecursive(l1, l2.next);
    return l2;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Daily Progress: ▰▰▰▰▰ 4.44% (4/90)&lt;br&gt;
Tags: algorithms, linkedlists, typescript, dsa, programming&lt;/p&gt;

</description>
      <category>codemonarchx</category>
      <category>luparinxgrind</category>
      <category>rinxlevelup</category>
      <category>shadowcoderinx</category>
    </item>
    <item>
      <title>Conquering Valid Parentheses with Stack Magic</title>
      <dc:creator>luparinx</dc:creator>
      <pubDate>Wed, 23 Apr 2025 19:08:09 +0000</pubDate>
      <link>https://dev.to/luparinx/conquering-valid-parentheses-with-stack-magic-4ak6</link>
      <guid>https://dev.to/luparinx/conquering-valid-parentheses-with-stack-magic-4ak6</guid>
      <description>&lt;p&gt;🔥 Today's Challenge Problem: Given a string containing just (, ), {, }, [ and ], determine if the input string is valid.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Input: "()[]{}"&lt;br&gt;
Output: true&lt;br&gt;
🧠 The Hunter's Strategy Weapon of Choice: Stack Data Structure When dealing with nested structures, stacks are your best friend. Here's why:&lt;/p&gt;

&lt;p&gt;Last-In-First-Out (LIFO) principle perfectly matches bracket validation&lt;/p&gt;

&lt;p&gt;O(n) time complexity - we process each character exactly once&lt;/p&gt;

&lt;p&gt;Early termination possible when mismatches occur&lt;/p&gt;

&lt;p&gt;Approach Breakdown: Initialize an empty stack&lt;/p&gt;

&lt;p&gt;Create a bracket pairing map (] → [, etc.)&lt;/p&gt;

&lt;p&gt;Iterate through the string:&lt;/p&gt;

&lt;p&gt;Push opening brackets onto stack&lt;/p&gt;

&lt;p&gt;For closing brackets: check if top of stack matches&lt;/p&gt;

&lt;p&gt;Final stack check ensures all brackets were closed&lt;/p&gt;

&lt;p&gt;💻 TypeScript Implementation&lt;/p&gt;

&lt;p&gt;function isValid(s: string): boolean {&lt;br&gt;
    const stack: string[] = [];&lt;br&gt;
    const bracketPairs: Record = { &lt;br&gt;
        ')': '(', &lt;br&gt;
        '}': '{', &lt;br&gt;
        ']': '[' &lt;br&gt;
    };&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (const char of s) {
    if (!bracketPairs[char]) {
        stack.push(char);
    } else if (stack.pop() !== bracketPairs[char]) {
        return false;
    }
}

return stack.length === 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Key Optimizations:&lt;/p&gt;

&lt;p&gt;Used a hashmap for O(1) bracket lookups&lt;/p&gt;

&lt;p&gt;Early return on mismatch&lt;/p&gt;

&lt;p&gt;Single pass through the string&lt;/p&gt;

&lt;p&gt;🎯 Edge Cases That Made Me Wiser Empty string: Technically valid (handled by final stack check)&lt;/p&gt;

&lt;p&gt;Nested valid brackets: ({[]}) → true&lt;/p&gt;

&lt;p&gt;Mismatched brackets: ([)] → false&lt;/p&gt;

&lt;p&gt;Single bracket: [ → false&lt;/p&gt;

&lt;p&gt;🚀 Performance Analysis Metric Value Time Complexity O(n) Space Complexity O(n) LeetCode Runtime 72ms (faster than 92.5%) 💡 Pro Tips Visualize the stack like a tower - you can only remove the top block!&lt;/p&gt;

&lt;p&gt;Test these cases:&lt;/p&gt;

&lt;p&gt;"(([]){})" (complex but valid)&lt;/p&gt;

&lt;p&gt;"]" (immediate fail)&lt;/p&gt;

&lt;p&gt;Try solving it without stack (hint: recursive approach exists)&lt;/p&gt;

&lt;p&gt;What's your favorite stack-based algorithm? Let's discuss in the comments! 👇&lt;/p&gt;

&lt;p&gt;Tomorrow's Preview: We'll tackle "Merge Two Sorted Lists" using pointer manipulation!&lt;/p&gt;

</description>
      <category>codemonarchx</category>
      <category>luparinxgrind</category>
      <category>rinxlevelup</category>
      <category>shadowcoderinx</category>
    </item>
  </channel>
</rss>
