<?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>Forem: Jatin Jayadev</title>
    <description>The latest articles on Forem by Jatin Jayadev (@jayadev_jatin).</description>
    <link>https://forem.com/jayadev_jatin</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%2F2573304%2F37c71750-b959-4842-b807-f0ffe0e42344.png</url>
      <title>Forem: Jatin Jayadev</title>
      <link>https://forem.com/jayadev_jatin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jayadev_jatin"/>
    <language>en</language>
    <item>
      <title>Day 57: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:35:36 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-57-competitive-programming-journal-m16</link>
      <guid>https://forem.com/jayadev_jatin/day-57-competitive-programming-journal-m16</guid>
      <description>&lt;p&gt;Date: November 22, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks Day 57 of my competitive programming journey. Here’s what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I focused on solving two problems: Partition a set into k subsets with equal sums (Backtracking) and Determine if a string contains all permutations of another string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Partition a set into k subsets with equal sums (Backtracking):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a set of numbers, partition them into k subsets with equal sum.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use backtracking to explore all possible partitions and check if the sum of k subsets equals the target sum.&lt;/li&gt;
&lt;li&gt;If the subsets match the required sum, return true; otherwise, return false.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool canPartition(vector&amp;lt;int&amp;gt;&amp;amp; nums, int n, int k, int targetSum, vector&amp;lt;int&amp;gt;&amp;amp; subsets) {
    if (k == 0) return true;
    if (targetSum == 0) return canPartition(nums, n, k - 1, targetSum, subsets); 

    for (int i = 0; i &amp;lt; n; ++i) {
        if (subsets[i] + nums[n - 1] &amp;lt;= targetSum) {
            subsets[i] += nums[n - 1];
            if (canPartition(nums, n - 1, k, targetSum, subsets)) return true;
            subsets[i] -= nums[n - 1];
        }
    }

    return false;
}

bool partitionKSubsets(vector&amp;lt;int&amp;gt;&amp;amp; nums, int k) {
    int totalSum = accumulate(nums.begin(), nums.end(), 0);
    if (totalSum % k != 0) return false;

    vector&amp;lt;int&amp;gt; subsets(k, 0);
    int targetSum = totalSum / k;

    return canPartition(nums, nums.size(), k, targetSum, subsets);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Determine if a string contains all permutations of another string:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given two strings str1 and str2, determine if str1 contains all permutations of str2.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use character frequency counting and sliding window approach to verify if str1 contains all permutations of str2.&lt;/li&gt;
&lt;li&gt;If the frequency count of characters matches between the window size of str2 and str1, then return true.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool containsPermutation(string str1, string str2) {
    if (str1.size() &amp;lt; str2.size()) return false;

    unordered_map&amp;lt;char, int&amp;gt; freqMap;
    for (char c : str2) freqMap[c]++;

    int left = 0, right = 0, count = str2.size();

    while (right &amp;lt; str1.size()) {
        if (freqMap.find(str1[right]) != freqMap.end()) {
            if (--freqMap[str1[right]] &amp;gt;= 0) count--;
        }

        if (count == 0) return true;

        if (right - left + 1 &amp;lt; str2.size()) right++;
        else {
            if (freqMap.find(str1[left]) != freqMap.end()) {
                if (++freqMap[str1[left]] &amp;gt; 0) count++;
            }
            left++;
            right++;
        }
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today's challenges required understanding backtracking and string manipulations. The partitioning problem was about ensuring equal partitioning into k subsets, which felt like a well-known subset sum variant. The permutation problem required character frequency checks, and the sliding window technique made it efficient. Both problems were insightful, giving more clarity on how backtracking and window-based approaches work for such problems.&lt;/p&gt;

&lt;p&gt;Looking forward to tomorrow’s problems!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 56: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:33:22 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-56-competitive-programming-journal-266m</link>
      <guid>https://forem.com/jayadev_jatin/day-56-competitive-programming-journal-266m</guid>
      <description>&lt;p&gt;Date: November 21, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks Day 56 of my competitive programming journey. Here’s what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I tackled two problems: Solve the Subset Sum problem (Backtracking) and Find the length of the shortest common supersequence of two strings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Solve the Subset Sum problem (Backtracking):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a set of integers, determine if there exists a subset whose sum is equal to a given sum S.&lt;/p&gt;

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

&lt;p&gt;Use backtracking to explore all possible subsets and check if their sum equals S.&lt;br&gt;
If a subset's sum matches S, return true.&lt;/p&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool subsetSum(vector&amp;lt;int&amp;gt;&amp;amp; nums, int n, int target) {
    if (target == 0) return true;
    if (n == 0) return false;
    if (nums[n - 1] &amp;gt; target) return subsetSum(nums, n - 1, target);
    return subsetSum(nums, n - 1, target) || subsetSum(nums, n - 1, target - nums[n - 1]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Find the length of the shortest common supersequence of two strings:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given two strings X and Y, find the length of their shortest common supersequence (SCS). A supersequence is a sequence that includes both strings as subsequences with the minimum possible length.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use dynamic programming to solve this by finding the longest common subsequence (LCS) and then adjusting the result based on the length of LCS.&lt;/li&gt;
&lt;li&gt;The formula is:
SCS_length = len(X) + len(Y) - LCS_length&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int shortestCommonSupersequence(string X, string Y) {
    int m = X.size(), n = Y.size();
    vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; dp(m + 1, vector&amp;lt;int&amp;gt;(n + 1, 0));

    // Fill dp table for LCS
    for (int i = 1; i &amp;lt;= m; ++i) {
        for (int j = 1; j &amp;lt;= n; ++j) {
            if (X[i - 1] == Y[j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    int lcs_length = dp[m][n];
    return m + n - lcs_length;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems were a nice blend of backtracking and dynamic programming. The subset sum problem was a good reminder of how powerful backtracking can be, especially when dealing with subsets and combinations. The shortest common supersequence problem was an insightful way to utilize LCS to simplify the overall solution.&lt;/p&gt;

&lt;p&gt;Looking forward to tomorrow's challenges!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 55: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:29:56 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-55-competitive-programming-journal-5238</link>
      <guid>https://forem.com/jayadev_jatin/day-55-competitive-programming-journal-5238</guid>
      <description>&lt;p&gt;Date: November 20, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks Day 55 of my competitive programming journey. Here’s what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I tackled two problems: Solve the Josephus problem (Recursion) and Count all possible palindromic substrings in a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Solve the Josephus problem (Recursion):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
In a circle of people, every k-th person is eliminated until only one person remains. Find the position of that last person.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;The Josephus problem can be solved using recursion.&lt;/li&gt;
&lt;li&gt;If there's only one person, the survivor is at position 0.&lt;/li&gt;
&lt;li&gt;Otherwise, the problem reduces to the Josephus problem for n-1 people with k as the step size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int josephus(int n, int k) {
    if (n == 1) {
        return 0;
    }
    return (josephus(n - 1, k) + k) % n;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Count all possible palindromic substrings in a string:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a string, count the number of palindromic substrings. A substring is considered palindromic if it reads the same forward and backward.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use dynamic programming to keep track of palindromic substrings.&lt;/li&gt;
&lt;li&gt;Expand around each center (both odd-length and even-length centers) to check for palindromic substrings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int countPalindromicSubstrings(string s) {
    int n = s.size();
    int count = 0;

    vector&amp;lt;vector&amp;lt;bool&amp;gt;&amp;gt; dp(n, vector&amp;lt;bool&amp;gt;(n, false));

    for (int i = 0; i &amp;lt; n; ++i) {
        dp[i][i] = true;
        count++;
    }

    for (int i = 0; i &amp;lt; n - 1; ++i) {
        if (s[i] == s[i + 1]) {
            dp[i][i + 1] = true;
            count++;
        }
    }

    for (int len = 3; len &amp;lt;= n; ++len) {
        for (int i = 0; i &amp;lt;= n - len; ++i) {
            int j = i + len - 1;
            if (s[i] == s[j] &amp;amp;&amp;amp; dp[i + 1][j - 1]) {
                dp[i][j] = true;
                count++;
            }
        }
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems were both interesting! The Josephus problem helped sharpen my recursion skills, while counting palindromic substrings reinforced dynamic programming and pattern matching. Both challenges are common in algorithmic contests, so solving them will be useful in future coding interviews.&lt;/p&gt;

&lt;p&gt;Looking forward to the next!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 54: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:26:16 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-54-competitive-programming-journal-5a13</link>
      <guid>https://forem.com/jayadev_jatin/day-54-competitive-programming-journal-5a13</guid>
      <description>&lt;p&gt;Date: November 19, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 54&lt;/strong&gt; of my competitive programming journey. Here’s what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I tackled two problems: Find the smallest range covering elements from k sorted lists (Sliding Window) and Find the length of the shortest unsorted subarray in an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Find the smallest range covering elements from k sorted lists (Sliding Window):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given k sorted lists, find the smallest range that includes at least one number from each of the k lists.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use a min-heap to maintain the current minimum of the current window and track which list each element belongs to.&lt;/li&gt;
&lt;li&gt;Iterate through each list, updating the range and ensuring no overlap.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vector&amp;lt;int&amp;gt; findSmallestRange(vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; nums) {
    int k = nums.size();
    priority_queue&amp;lt;pair&amp;lt;int, int&amp;gt;, vector&amp;lt;pair&amp;lt;int, int&amp;gt;&amp;gt;, greater&amp;lt;&amp;gt;&amp;gt; minHeap;
    int rangeStart = 0, rangeEnd = INT_MAX;
    int currentMax = INT_MIN;

    for (int i = 0; i &amp;lt; k; ++i) {
        minHeap.push({nums[i][0], i, 0});
        currentMax = max(currentMax, nums[i][0]);
    }

    while (true) {
        auto [minVal, listIndex, elementIndex] = minHeap.top(); minHeap.pop();
        if (currentMax - minVal &amp;lt; rangeEnd - rangeStart) {
            rangeStart = minVal;
            rangeEnd = currentMax;
        }

        if (elementIndex + 1 &amp;lt; nums[listIndex].size()) {
            int nextVal = nums[listIndex][elementIndex + 1];
            minHeap.push({nextVal, listIndex, elementIndex + 1});
            currentMax = max(currentMax, nextVal);
        } else {
            break;
        }
    }

    return {rangeStart, rangeEnd};
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Find the length of the shortest unsorted subarray in an array:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given an array, find the length of the shortest subarray that, if sorted, would sort the entire array.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Identify the leftmost and rightmost elements that are out of order.&lt;/li&gt;
&lt;li&gt;The length of the shortest subarray is the difference between these indices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int findUnsortedSubarray(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
    int n = nums.size();
    int left = 0, right = n - 1;

    while (left &amp;lt; n - 1 &amp;amp;&amp;amp; nums[left] &amp;lt;= nums[left + 1]) {
        ++left;
    }

    if (left == n - 1) {
        return 0;
    }

    while (right &amp;gt; 0 &amp;amp;&amp;amp; nums[right] &amp;gt;= nums[right - 1]) {
        --right;
    }

    int minVal = *min_element(nums.begin() + left, nums.begin() + right + 1);
    int maxVal = *max_element(nums.begin() + left, nums.begin() + right + 1);

    while (left &amp;gt; 0 &amp;amp;&amp;amp; nums[left - 1] &amp;gt; minVal) {
        --left;
    }
    while (right &amp;lt; n - 1 &amp;amp;&amp;amp; nums[right + 1] &amp;lt; maxVal) {
        ++right;
    }

    return right - left + 1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems provided great practice with sliding windows and identifying subarrays that need sorting. The first problem on finding the smallest range covering elements from k sorted lists sharpened my sliding window technique, while the second problem on finding the length of the shortest unsorted subarray gave me a deep understanding of range-based operations and sorting-related algorithms. Both challenges enhanced my problem-solving skills significantly.&lt;/p&gt;

&lt;p&gt;Looking forward to more!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 53: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:23:47 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-53-competitive-programming-journal-4f1n</link>
      <guid>https://forem.com/jayadev_jatin/day-53-competitive-programming-journal-4f1n</guid>
      <description>&lt;p&gt;Date: November 18, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 53&lt;/strong&gt; of my competitive programming journey. Here’s what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I tackled two problems: Find the row with the maximum number of 1s in a binary matrix and Rearrange a string such that no two adjacent characters are the same.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Find the row with the maximum number of 1s in a binary matrix:&lt;/strong&gt;&lt;br&gt;
Problem:&lt;br&gt;
Given a binary matrix, find the row that contains the maximum number of 1s.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use a two-pointer approach, where we start from the rightmost column and move leftwards.&lt;/li&gt;
&lt;li&gt;If we find a 1, we move left to narrow the possible rows.&lt;/li&gt;
&lt;li&gt;If we find a 0, we move downward, skipping those rows as they can’t contain 1s further to the left.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int findMaxOnesRow(vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; &amp;amp;matrix) {
    int rows = matrix.size();
    int cols = matrix[0].size();

    int maxRow = -1, maxCount = 0;
    int j = cols - 1;

    for (int i = 0; i &amp;lt; rows; ++i) {
        while (j &amp;gt;= 0 &amp;amp;&amp;amp; matrix[i][j] == 1) {
            --j; 
        }
        int countOnes = cols - j - 1;
        if (countOnes &amp;gt; maxCount) {
            maxCount = countOnes;
            maxRow = i;
        }
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Rearrange a string such that no two adjacent characters are the same:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a string, rearrange its characters such that no two adjacent characters are the same.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Count the frequency of each character.&lt;/li&gt;
&lt;li&gt;Use a max-heap to always place the most frequent character first, ensuring that no two adjacent characters are the same.&lt;/li&gt;
&lt;li&gt;If at any point, we can't place the most frequent character, it’s impossible to rearrange the string accordingly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string rearrangeString(string s) {
    unordered_map&amp;lt;char, int&amp;gt; freq;
    for (char c : s) {
        freq[c]++;
    }

    priority_queue&amp;lt;pair&amp;lt;int, char&amp;gt;&amp;gt; maxHeap;
    for (auto &amp;amp;entry : freq) {
        maxHeap.push({entry.second, entry.first});
    }

    string result;
    while (!maxHeap.empty()) {
        auto [count, ch] = maxHeap.top(); maxHeap.pop();
        if (result.empty() || result.back() != ch) {
            result += ch;
            if (--count &amp;gt; 0) {
                maxHeap.push({count, ch});
            }
        } else {
            if (maxHeap.empty()) {
                return "";
            }
            auto [nextCount, nextCh] = maxHeap.top(); maxHeap.pop();
            result += nextCh;
            if (--nextCount &amp;gt; 0) {
                maxHeap.push({nextCount, nextCh});
            }
            maxHeap.push({count, ch});
        }
    }

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

&lt;/div&gt;



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

&lt;p&gt;Today’s problems tested my understanding of binary search and greedy algorithms. The first problem, finding the row with the maximum number of 1s, was a good exercise in searching and condition checking, while the second problem on rearranging a string required understanding of frequency counts and using a max-heap to ensure no two adjacent characters are the same. Both problems were insightful and helped strengthen my problem-solving skills.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 52: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:19:27 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-52-competitive-programming-journal-19h2</link>
      <guid>https://forem.com/jayadev_jatin/day-52-competitive-programming-journal-19h2</guid>
      <description>&lt;p&gt;Date: November 15, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 52&lt;/strong&gt; of my competitive programming journey. Here’s what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I tackled two problems: Find the number of ways to climb n stairs with 1 or 2 steps at a time (Recursion) and Determine if two rectangles overlap on a 2D plane.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Find the number of ways to climb n stairs with 1 or 2 steps at a time (Recursion):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given n stairs, find the number of ways to reach the top if you can take 1 or 2 steps at a time.&lt;/p&gt;

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

&lt;p&gt;Use recursion, where the number of ways to reach the n-th step is the sum of the ways to reach the (n−1)-th and (n−2)-th steps.&lt;/p&gt;

&lt;p&gt;Base cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If n=0, there is 1 way to stay at the ground (do nothing).&lt;/li&gt;
&lt;li&gt;If n=1, there is only 1 way (1 step at a time).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int countWaysToClimbStairs(int n) {
    if (n == 0) return 1;
    if (n == 1) return 1;

    return countWaysToClimbStairs(n - 1) + countWaysToClimbStairs(n - 2);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Determine if two rectangles overlap on a 2D plane:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given two rectangles on a 2D plane, determine if they overlap.&lt;/p&gt;

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

&lt;p&gt;Two rectangles overlap if they have a common area.&lt;br&gt;
Conditions to check for overlap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One rectangle is to the left of the other (i.e., right edge of one is left of the other’s left edge).&lt;/li&gt;
&lt;li&gt;One rectangle is above the other (i.e., bottom edge of one is above the other’s top edge).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Rectangle {
    int x1, y1, x2, y2;
};

bool isOverlap(Rectangle r1, Rectangle r2) {
    if (r1.x2 &amp;lt;= r2.x1 || r2.x2 &amp;lt;= r1.x1) return false;
    if (r1.y2 &amp;lt;= r2.y1 || r2.y2 &amp;lt;= r1.y1) return false;
    return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems tested recursion and condition-checking. The climbing stairs problem with 1 or 2 steps was an insightful use of recursion, while the rectangle overlap problem required geometry-based checks and simple logical conditions. Both exercises improved my understanding of recursion and basic geometry.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 51: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:16:38 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-51-competitive-programming-journal-19k2</link>
      <guid>https://forem.com/jayadev_jatin/day-51-competitive-programming-journal-19k2</guid>
      <description>&lt;p&gt;Date: November 14, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks Day 51 of my competitive programming journey. Here's what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I solved two problems: Generate all balanced parentheses of length 2n and Find the longest common subsequence between two strings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Generate all balanced parentheses of length 2n (Backtracking):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a number n, generate all combinations of n pairs of balanced parentheses.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use recursion and backtracking to build the combinations.&lt;/li&gt;
&lt;li&gt;Track the number of open and close parentheses to ensure balance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void generateParentheses(int open, int close, string current, vector&amp;lt;string&amp;gt;&amp;amp; result) {
    if (open == 0 &amp;amp;&amp;amp; close == 0) {
        result.push_back(current);
        return;
    }

    if (open &amp;gt; 0) {
        generateParentheses(open - 1, close, current + "(", result);
    }

    if (close &amp;gt; open) {
        generateParentheses(open, close - 1, current + ")", result);
    }
}

vector&amp;lt;string&amp;gt; balancedParentheses(int n) {
    vector&amp;lt;string&amp;gt; result;
    generateParentheses(n, n, "", result);
    return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Find the longest common subsequence between two strings (Recursion):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given two strings, find the length of their longest common subsequence.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use recursion to compare characters from both strings.&lt;/li&gt;
&lt;li&gt;If characters match, add 1 and move to the next characters in both strings.&lt;/li&gt;
&lt;li&gt;Otherwise, explore both possibilities (skip one character in each string) and take the maximum length.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int longestCommonSubsequence(string s1, string s2, int i, int j) {
    if (i == s1.length() || j == s2.length()) {
        return 0;
    }

    if (s1[i] == s2[j]) {
        return 1 + longestCommonSubsequence(s1, s2, i + 1, j + 1);
    } else {
        return max(longestCommonSubsequence(s1, s2, i + 1, j),
                   longestCommonSubsequence(s1, s2, i, j + 1));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems were an excellent mix of recursion and backtracking. Generating balanced parentheses was particularly enjoyable as it required creative problem-solving. The longest common subsequence problem strengthened my understanding of recursion and string manipulations.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 50: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:13:37 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-50-competitive-programming-journal-2jdg</link>
      <guid>https://forem.com/jayadev_jatin/day-50-competitive-programming-journal-2jdg</guid>
      <description>&lt;p&gt;Date: November 13, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 50&lt;/strong&gt; of my competitive programming journey. Here's what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I tackled two challenging problems: Solve the Knight’s Tour problem and Find the maximum path sum in a binary matrix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Solve the Knight’s Tour problem (Backtracking):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given an N×N chessboard, the goal is to find a sequence of moves for a knight such that it visits every square exactly once.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use backtracking to try all possible knight moves.&lt;/li&gt;
&lt;li&gt;Use a 2D matrix to track the visited squares.&lt;/li&gt;
&lt;li&gt;If all squares are visited, print the path; otherwise, backtrack.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool isSafe(int x, int y, vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; board) {
    return (x &amp;gt;= 0 &amp;amp;&amp;amp; y &amp;gt;= 0 &amp;amp;&amp;amp; x &amp;lt; N &amp;amp;&amp;amp; y &amp;lt; N &amp;amp;&amp;amp; board[x][y] == -1);
}

bool solveKnightTour(int x, int y, int move, vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; board, vector&amp;lt;int&amp;gt;&amp;amp; dx, vector&amp;lt;int&amp;gt;&amp;amp; dy) {
    if (move == N * N) return true;

    for (int i = 0; i &amp;lt; 8; i++) {
        int nextX = x + dx[i];
        int nextY = y + dy[i];

        if (isSafe(nextX, nextY, board)) {
            board[nextX][nextY] = move;

            if (solveKnightTour(nextX, nextY, move + 1, board, dx, dy)) {
                return true;
            }

            board[nextX][nextY] = -1;
        }
    }
    return false;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Find the maximum path sum in a binary matrix:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given a binary matrix, find the maximum path sum from any cell in the first row to any cell in the last row, moving only to the cells below, diagonally left below, or diagonally right below.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use dynamic programming to calculate the maximum path sum for each cell, starting from the top row and propagating downwards.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int maxPathSum(vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; matrix) {
    int n = matrix.size();
    int m = matrix[0].size();

    for (int i = 1; i &amp;lt; n; i++) {
        for (int j = 0; j &amp;lt; m; j++) {
            int up = matrix[i - 1][j];
            int left = (j &amp;gt; 0) ? matrix[i - 1][j - 1] : 0;
            int right = (j &amp;lt; m - 1) ? matrix[i - 1][j + 1] : 0;

            matrix[i][j] += max({up, left, right});
        }
    }

    return *max_element(matrix[n - 1].begin(), matrix[n - 1].end());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Both problems tested my problem-solving and implementation skills. The Knight’s Tour problem emphasized the importance of backtracking, while the matrix problem reinforced dynamic programming concepts.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 49: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:10:50 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-49-competitive-programming-journal-mi7</link>
      <guid>https://forem.com/jayadev_jatin/day-49-competitive-programming-journal-mi7</guid>
      <description>&lt;p&gt;Date: November 12, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 49&lt;/strong&gt; of my competitive programming journey. Here's what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I solved two problems: Count the number of subarrays with a given sum and Find the maximum sum of a subarray using Kadane’s Algorithm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Count the number of subarrays with a given sum (Sliding Window):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
You are given an array and a target sum. Count the number of subarrays that add up to the target sum.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use a hashmap to store the cumulative sum at each point in the array.&lt;/li&gt;
&lt;li&gt;Check if the difference between the current cumulative sum and the target exists in the hashmap. If it does, that means a subarray with the target sum exists.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int countSubarraysWithSum(vector&amp;lt;int&amp;gt;&amp;amp; nums, int target) {
    unordered_map&amp;lt;int, int&amp;gt; prefixSum;
    int count = 0, currentSum = 0;

    prefixSum[0] = 1;

    for (int num : nums) {
        currentSum += num;

        if (prefixSum.find(currentSum - target) != prefixSum.end()) {
            count += prefixSum[currentSum - target];
        }

        prefixSum[currentSum]++;
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Find the maximum sum of a subarray (Kadane’s Algorithm):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given an array, find the maximum possible sum of a subarray.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use a variable to track the current sum (currentSum) and update the maximum sum (maxSum) whenever currentSum exceeds maxSum.&lt;/li&gt;
&lt;li&gt;If currentSum drops below 0, reset it to 0 since a negative sum cannot contribute to a maximum.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int maxSubarraySum(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
    int maxSum = nums[0], currentSum = 0;

    for (int num : nums) {
        currentSum += num;

        if (currentSum &amp;gt; maxSum) {
            maxSum = currentSum;
        }

        if (currentSum &amp;lt; 0) {
            currentSum = 0;
        }
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems highlighted the power of efficient algorithms like prefix sums and Kadane's algorithm. It was great to revisit these fundamental yet powerful techniques that are frequently used in competitive programming.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 48: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:06:16 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-48-competitive-programming-journal-3fbd</link>
      <guid>https://forem.com/jayadev_jatin/day-48-competitive-programming-journal-3fbd</guid>
      <description>&lt;p&gt;Date: November 11, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 48&lt;/strong&gt; of my competitive programming journey. Here's what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I solved two problems: Search an element in a matrix sorted row-wise and column-wise and Find the longest palindromic substring in a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Search an element in a matrix sorted row-wise and column-wise:&lt;br&gt;
Problem:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are given an n x m matrix where each row is sorted in ascending order, and each column is also sorted in ascending order. Find whether a given element exists in the matrix.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Start searching from the top-right corner of the matrix.&lt;/li&gt;
&lt;li&gt;If the current element is larger than the target, move left.&lt;/li&gt;
&lt;li&gt;If the current element is smaller than the target, move down.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool searchMatrix(vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; matrix, int target) {
    int rows = matrix.size();
    int cols = matrix[0].size();
    int i = 0, j = cols - 1; 

    while (i &amp;lt; rows &amp;amp;&amp;amp; j &amp;gt;= 0) {
        if (matrix[i][j] == target) {
            return true;
        } else if (matrix[i][j] &amp;gt; target) {
            j--;
        } else {
            i++; 
        }
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Find the longest palindromic substring in a string:&lt;br&gt;
Problem:&lt;/strong&gt;&lt;br&gt;
Given a string, find the longest substring that is a palindrome.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use the "expand around center" approach.&lt;/li&gt;
&lt;li&gt;Treat each character as a potential center of a palindrome.&lt;/li&gt;
&lt;li&gt;Check for odd- and even-length palindromes by expanding around the center.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string longestPalindrome(string s) {
    int n = s.length();
    int start = 0, maxLength = 1;

    for (int i = 0; i &amp;lt; n; i++) {
        int low = i, high = i;
        while (low &amp;gt;= 0 &amp;amp;&amp;amp; high &amp;lt; n &amp;amp;&amp;amp; s[low] == s[high]) {
            if (high - low + 1 &amp;gt; maxLength) {
                start = low;
                maxLength = high - low + 1;
            }
            low--;
            high++;
        }

        low = i, high = i + 1;
        while (low &amp;gt;= 0 &amp;amp;&amp;amp; high &amp;lt; n &amp;amp;&amp;amp; s[low] == s[high]) {
            if (high - low + 1 &amp;gt; maxLength) {
                start = low;
                maxLength = high - low + 1;
            }
            low--;
            high++;
        }
    }

    return s.substr(start, maxLength);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today’s problems challenged my logical thinking, especially in understanding how to navigate a sorted matrix efficiently. The palindrome problem, though classic, is always enjoyable as it combines multiple concepts like pointers and substring operations.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 47: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:01:57 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-47-competitive-programming-journal-4pfl</link>
      <guid>https://forem.com/jayadev_jatin/day-47-competitive-programming-journal-4pfl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Date:&lt;/strong&gt; November 8, 2024&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 47&lt;/strong&gt; of my competitive programming journey. Here's what I worked on today:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I solved two problems: Find the length of the longest palindrome that can be built using letters from a string and Reverse a string using recursion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Find the length of the longest palindrome that can be built using letters from a string:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a string, find the length of the longest palindrome that can be constructed using its letters. Characters can appear in any order, but at most one character can have an odd frequency.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use a frequency count of the characters.&lt;/li&gt;
&lt;li&gt;Add all pairs of characters to the palindrome's length.&lt;/li&gt;
&lt;li&gt;If any characters have an odd frequency, one of them can be placed in the center of the palindrome.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int longestPalindrome(string s) {
    unordered_map&amp;lt;char, int&amp;gt; freq;
    for (char c : s) {
        freq[c]++;
    }

    int length = 0;
    bool oddFound = false;

    for (auto&amp;amp; [key, value] : freq) {
        length += (value / 2) * 2;
        if (value % 2 == 1) {
            oddFound = true;
        }
    }

    if (oddFound) length += 1;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Reverse a string using recursion:&lt;/strong&gt;&lt;br&gt;
**Problem:&lt;br&gt;
**Reverse a string using recursion without using any additional data structures.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Swap the first and last characters of the string and recursively process the remaining substring.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void reverseString(string&amp;amp; s, int i, int j) {
    if (i &amp;gt;= j) return; 
    swap(s[i], s[j]);
    reverseString(s, i + 1, j - 1); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today's problems were straightforward but insightful. I enjoyed implementing the &lt;strong&gt;recursive reversal&lt;/strong&gt; and learning how character frequencies contribute to constructing &lt;strong&gt;palindromes&lt;/strong&gt;. Both were great exercises for logical thinking and recursion.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 46: Competitive Programming Journal</title>
      <dc:creator>Jatin Jayadev</dc:creator>
      <pubDate>Mon, 16 Dec 2024 09:57:14 +0000</pubDate>
      <link>https://forem.com/jayadev_jatin/day-46-competitive-programming-journal-3mol</link>
      <guid>https://forem.com/jayadev_jatin/day-46-competitive-programming-journal-3mol</guid>
      <description>&lt;p&gt;&lt;strong&gt;Date:&lt;/strong&gt; November 7, 2024.&lt;br&gt;
&lt;strong&gt;Hello Everyone,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today marks &lt;strong&gt;Day 46&lt;/strong&gt; of my competitive programming journey, and I’m here to share my progress.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Did Today:&lt;/strong&gt;&lt;br&gt;
I worked on two problems: Find all possible combinations of k numbers that add up to n (Backtracking) and Determine if a Sudoku board is valid (Matrix).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Find all possible combinations of k numbers that add up to n (Backtracking):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given two integers, k (number of elements) and n (target sum), find all unique combinations of k numbers between 1 and 9 that sum to n. Each number can be used only once.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Use backtracking to explore all possible combinations.&lt;/li&gt;
&lt;li&gt;Include a number, reduce the target sum, and decrease the count k for the next recursive call.&lt;/li&gt;
&lt;li&gt;Backtrack when the target becomes negative or when k reaches zero.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void findCombinations(int k, int n, int start, vector&amp;lt;int&amp;gt;&amp;amp; current, vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&amp;amp; result) {
    if (n == 0 &amp;amp;&amp;amp; k == 0) { 
        result.push_back(current);
        return;
    }

    if (n &amp;lt; 0 || k == 0) return;

    for (int i = start; i &amp;lt;= 9; i++) {
        current.push_back(i);
        findCombinations(k - 1, n - i, i + 1, current, result);
        current.pop_back(); 
    }
}

vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; combinationSum3(int k, int n) {
    vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; result;
    vector&amp;lt;int&amp;gt; current;
    findCombinations(k, n, 1, current, result);
    return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Determine if a Sudoku board is valid (Matrix):&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
Given a partially filled 9x9 Sudoku board, determine if it is valid.&lt;/p&gt;

&lt;p&gt;A valid board satisfies these rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each row contains unique digits from 1-9 or empty cells ('.').&lt;/li&gt;
&lt;li&gt;Each column contains unique digits from 1-9 or empty cells ('.').&lt;/li&gt;
&lt;li&gt;Each 3x3 sub-grid contains unique digits from 1-9 or empty cells ('.').&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Use hash sets to track the seen numbers in rows, columns, and sub-grids.&lt;/li&gt;
&lt;li&gt;Traverse the board and validate numbers accordingly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool isValidSudoku(vector&amp;lt;vector&amp;lt;char&amp;gt;&amp;gt;&amp;amp; board) {
    vector&amp;lt;unordered_set&amp;lt;char&amp;gt;&amp;gt; rows(9), cols(9), grids(9);

    for (int i = 0; i &amp;lt; 9; i++) {
        for (int j = 0; j &amp;lt; 9; j++) {
            char num = board[i][j];
            if (num == '.') continue;

            int gridIndex = (i / 3) * 3 + (j / 3);

            if (rows[i].count(num) || cols[j].count(num) || grids[gridIndex].count(num)) {
                return false;
            }

            rows[i].insert(num);
            cols[j].insert(num);
            grids[gridIndex].insert(num);
        }
    }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reflection:&lt;/strong&gt;&lt;br&gt;
Today's problems tested my ability to implement backtracking and matrix validation efficiently. I enjoyed the logical depth involved in generating combinations and ensuring Sudoku's rules are followed systematically.&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates, and as always, happy coding!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
