<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MyEngineeringJournal]]></title><description><![CDATA[MyEngineeringJournal]]></description><link>https://myengineeringjournal.in</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 08:01:37 GMT</lastBuildDate><atom:link href="https://myengineeringjournal.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Greatest Common Divisor of Strings]]></title><description><![CDATA[As part of my LeetCode 75 series, I’m diving into fundamental algorithmic problems that enhance problem-solving skills. Today, we explore the problem Greatest Common Divisor of Strings (LeetCode 1071) The problem is a great blend of string manipulati...]]></description><link>https://myengineeringjournal.in/greatest-common-divisor-of-strings</link><guid isPermaLink="true">https://myengineeringjournal.in/greatest-common-divisor-of-strings</guid><category><![CDATA[leetcode]]></category><category><![CDATA[DSA]]></category><category><![CDATA[greatest commomn divisor of strings]]></category><dc:creator><![CDATA[Salil Luley]]></dc:creator><pubDate>Wed, 31 Dec 2025 14:16:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767190538662/56e69156-2a8c-427c-a9d8-6c8f37cad3f1.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As part of my <strong>LeetCode 75</strong> series, I’m diving into fundamental algorithmic problems that enhance problem-solving skills. Today, we explore the problem <strong>Greatest Common Divisor of Strings</strong> (<a target="_blank" href="https://leetcode.com/problems/greatest-common-divisor-of-strings/">LeetCode 1071)</a> The problem is a great blend of string manipulation and mathematical concepts, particularly the Greatest Common Divisor (GCD).</p>
<h2 id="heading-problem-statement"><strong>Problem Statement</strong></h2>
<p>Given two strings <code>str1</code> and <code>str2</code>, the task is to determine the largest string <code>X</code> that divides both <code>str1</code> and <code>str2</code>. In other words, <code>X</code> should be the largest string that, when repeated, can form both <code>str1</code> and <code>str2</code>.</p>
<h2 id="heading-solution-approach"><strong>Solution Approach</strong></h2>
<p>To solve this problem, we leverage two key insights:</p>
<ol>
<li><p>If <code>str1 + str2</code> is not equal to <code>str2 + str1</code>, there is no common divisor string.</p>
</li>
<li><p>The length of the GCD string is determined by the <strong>Greatest Common Divisor</strong> (GCD) of the lengths of <code>str1</code> and <code>str2</code>.</p>
</li>
</ol>
<h2 id="heading-implementation-in-go"><strong>Implementation in Go</strong></h2>
<p>Below is the Go implementation for solving this problem efficiently:</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> leetcode_75
<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">GreatestCommonDivisorOfStrings</span><span class="hljs-params">()</span></span> {
    str1 := <span class="hljs-string">"ABAB"</span>
    str2 := <span class="hljs-string">"ABABAB"</span>
    fmt.Printf(<span class="hljs-string">"gcdOfStrings(): %v\n"</span>, gcdOfStrings(str1, str2))
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">gcdOfStrings</span><span class="hljs-params">(str1 <span class="hljs-keyword">string</span>, str2 <span class="hljs-keyword">string</span>)</span> <span class="hljs-title">string</span></span> {
    <span class="hljs-keyword">if</span> str1+str2 != str2+str1 {
        <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>
    }
    gcdLength := gcd(<span class="hljs-built_in">len</span>(str1), <span class="hljs-built_in">len</span>(str2))
    <span class="hljs-keyword">return</span> str1[:gcdLength]
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">gcd</span><span class="hljs-params">(a, b <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">for</span> b != <span class="hljs-number">0</span> {
        a, b = b, a%b
    }
    <span class="hljs-keyword">return</span> a
}
</code></pre>
<h2 id="heading-complexity-analysis"><strong>Complexity Analysis</strong></h2>
<ul>
<li><p><strong>Time Complexity:</strong> O(N + log(min(len(str1), len(str2))))</p>
</li>
<li><p><strong>Space Complexity:</strong> O(1), as we use only a few additional variables.</p>
</li>
</ul>
<h2 id="heading-explanation"><strong>Explanation</strong></h2>
<ol>
<li><p><strong>Concatenation Check:</strong> If <code>str1 + str2</code> is not equal to <code>str2 + str1</code>, it means the two strings do not share a common pattern, so we return an empty string.</p>
</li>
<li><p><strong>Finding the GCD Length:</strong> We compute the GCD of the lengths of <code>str1</code> and <code>str2</code>.</p>
</li>
<li><p><strong>Extracting the GCD String:</strong> The prefix of <code>str1</code> up to the GCD length is the desired result.</p>
</li>
</ol>
<h2 id="heading-example-walkthrough"><strong>Example Walkthrough</strong></h2>
<h3 id="heading-input"><strong>Input:</strong></h3>
<pre><code class="lang-go">str1 = <span class="hljs-string">"ABAB"</span>
str2 = <span class="hljs-string">"ABABAB"</span>
</code></pre>
<h3 id="heading-process"><strong>Process:</strong></h3>
<ul>
<li><p><code>str1 + str2 = "ABABABABABAB"</code></p>
</li>
<li><p><code>str2 + str1 = "ABABABABABAB"</code> (equal ✅)</p>
</li>
<li><p><code>GCD(len("ABAB"), len("ABABAB")) = 2</code></p>
</li>
<li><p>The first 2 characters of <code>str1</code> (<code>"AB"</code>) is the GCD string.</p>
</li>
</ul>
<h3 id="heading-output"><strong>Output:</strong></h3>
<pre><code class="lang-go"><span class="hljs-string">"AB"</span>
</code></pre>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>This problem demonstrates how mathematical concepts like GCD can be applied to string problems, making it a perfect blend of <strong>string manipulation and number theory</strong>. Stay tuned for more problems in the <strong>LeetCode 75 series</strong>!</p>
]]></content:encoded></item><item><title><![CDATA[The Two Sum Problem]]></title><description><![CDATA[Problem Statement: Two Sum
The Two Sum problem is a popular question in coding interviews and foundational in learning hash maps.
Problem
Given an array of integers, return indices of the two numbers that add up to a specific target.
Example
Input: a...]]></description><link>https://myengineeringjournal.in/leetcode-75-the-two-sum-problem</link><guid isPermaLink="true">https://myengineeringjournal.in/leetcode-75-the-two-sum-problem</guid><category><![CDATA[Go Language]]></category><category><![CDATA[leetcode]]></category><category><![CDATA[#Leetcode75]]></category><category><![CDATA[two-sum-problem]]></category><dc:creator><![CDATA[Salil Luley]]></dc:creator><pubDate>Tue, 30 Dec 2025 11:23:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767093852104/92459164-aa40-4576-ae53-2c3859283997.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-problem-statement-two-sum"><strong>Problem Statement: Two Sum</strong></h2>
<p>The <strong>Two Sum</strong> problem is a popular question in coding interviews and foundational in learning hash maps.</p>
<h2 id="heading-problem"><strong>Problem</strong></h2>
<p>Given an array of integers, return indices of the two numbers that add up to a specific target.</p>
<h2 id="heading-example"><strong>Example</strong></h2>
<p><strong>Input</strong>: <code>arr = [2, 7, 11, 15]</code>, <code>target = 9</code><br /><strong>Output</strong>: <code>[0, 1]</code><br />Explanation: <code>arr[0] + arr[1] = 2 + 7 = 9</code></p>
<p>You can find the detailed question description here:<br /><a target="_blank" href="https://leetcode.com/problems/two-sum/description/">LeetCode — Two Sum</a></p>
<h2 id="heading-brute-force-approach"><strong>Brute Force Approach</strong></h2>
<p>The simplest way to solve this problem is to check every pair of numbers in the array.</p>
<h2 id="heading-implementation"><strong>Implementation</strong></h2>
<pre><code class="lang-go"><span class="hljs-comment">// Brute force - Time Complexity: O(n^2), Space Complexity: O(1)</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">twoSum</span><span class="hljs-params">()</span> []<span class="hljs-title">int</span></span> {
    arr := []<span class="hljs-keyword">int</span>{<span class="hljs-number">2</span>, <span class="hljs-number">7</span>, <span class="hljs-number">11</span>, <span class="hljs-number">15</span>}
    target := <span class="hljs-number">9</span>
    <span class="hljs-keyword">for</span> index1, i := <span class="hljs-keyword">range</span> arr {
        <span class="hljs-keyword">for</span> index2, j := <span class="hljs-keyword">range</span> arr {
            <span class="hljs-keyword">if</span> i+j == target {
                <span class="hljs-keyword">return</span> []<span class="hljs-keyword">int</span>{index1, index2}
            }
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span>
}
</code></pre>
<h2 id="heading-explanation"><strong>Explanation</strong></h2>
<ol>
<li><p>Use nested loops to iterate through all pairs of numbers.</p>
</li>
<li><p>Check if the sum of two numbers equals the target.</p>
</li>
<li><p>If it does, return their indices.</p>
</li>
</ol>
<h2 id="heading-complexity-analysis"><strong>Complexity Analysis</strong></h2>
<ul>
<li><p><strong>Time Complexity</strong>: O(n²), as we are iterating through pairs of elements.</p>
</li>
<li><p><strong>Space Complexity</strong>: O(1), as no additional data structures are used.</p>
</li>
</ul>
<h2 id="heading-optimised-approach"><strong>Optimised Approach</strong></h2>
<p>We can improve the solution using a <strong>hash map</strong> to store the numbers and their indices.</p>
<h2 id="heading-implementation-1"><strong>Implementation</strong></h2>
<pre><code class="lang-go"><span class="hljs-comment">// Optimized approach - Time Complexity: O(n), Space Complexity: O(n)</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">twoSum</span><span class="hljs-params">()</span> []<span class="hljs-title">int</span></span> {
    arr := []<span class="hljs-keyword">int</span>{<span class="hljs-number">2</span>, <span class="hljs-number">7</span>, <span class="hljs-number">11</span>, <span class="hljs-number">15</span>}
    target := <span class="hljs-number">9</span>
    hm := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">map</span>[<span class="hljs-keyword">int</span>]<span class="hljs-keyword">int</span>) 
    <span class="hljs-keyword">for</span> index, value := <span class="hljs-keyword">range</span> arr {
        numberToFind := target - value
        <span class="hljs-keyword">if</span> indexFound, ok := hm[numberToFind]; ok {
            <span class="hljs-keyword">return</span> []<span class="hljs-keyword">int</span>{indexFound, index}
        }
        hm[value] = index
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span>
}
</code></pre>
<h2 id="heading-explanation-1"><strong>Explanation</strong></h2>
<ol>
<li><p>Use a hash map to store each number and its index.</p>
</li>
<li><p>For each number, calculate the complement (<code>target - current number</code>) (i.e value in above solution).</p>
</li>
<li><p>Check if the complement exists in the hash map.</p>
</li>
<li><p>If it does, return the indices.</p>
</li>
</ol>
<h2 id="heading-complexity-analysis-1"><strong>Complexity Analysis</strong></h2>
<ul>
<li><p><strong>Time Complexity</strong>: O(n), as we iterate through the array once.</p>
</li>
<li><p><strong>Space Complexity</strong>: O(n), as we store elements in a hash map.</p>
</li>
</ul>
<h2 id="heading-code-and-repository"><strong>Code and Repository</strong></h2>
<p>You can find the complete code for this solution and follow my progress solving LeetCode 75 questions in Golang on GitHub:</p>
<ul>
<li><p><strong>GitHub Repository</strong>: <a target="_blank" href="https://github.com/SalilLuley/DSA-Golang?tab=readme-ov-file">DSA-Golang</a></p>
</li>
<li><p><strong>Solution Code</strong>: <a target="_blank" href="https://github.com/SalilLuley/DSA-Golang/blob/develop/leetcode_75/two_sum.go">Two Sum Solution</a></p>
</li>
</ul>
<h2 id="heading-lets-connect"><strong>Let’s Connect!</strong></h2>
<p>I’m documenting my journey to master DSA with Golang. If you’re on a similar path or just want to connect, feel free to reach out:</p>
<ul>
<li><p><strong>LinkedIn</strong>: <a target="_blank" href="https://www.linkedin.com/in/salil-luley/">Salil Luley</a></p>
</li>
<li><p><strong>My Website</strong>: <a target="_blank" href="https://salilluley.vercel.app/">salilluley.vercel.app</a></p>
</li>
</ul>
<p>Stay tuned for more solutions and insights as we tackle LeetCode 75 together. Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[🚧 Coming Soon]]></title><description><![CDATA[👋 Hi there I am Salil,
MyEngineeringJournal is currently under construction.
I’ll be sharing:• AWS & DevOps learnings• Engineering notes• Real-world system design• Career lessons
Stay tuned 🚀]]></description><link>https://myengineeringjournal.in/my-blog</link><guid isPermaLink="true">https://myengineeringjournal.in/my-blog</guid><dc:creator><![CDATA[Salil Luley]]></dc:creator><pubDate>Tue, 30 Dec 2025 09:58:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767089083193/67a4f69a-11b8-4385-b503-b7a65f4845e6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>👋 Hi there I am Salil,</p>
<p>MyEngineeringJournal is currently under construction.</p>
<p>I’ll be sharing:<br />• AWS &amp; DevOps learnings<br />• Engineering notes<br />• Real-world system design<br />• Career lessons</p>
<p>Stay tuned 🚀</p>
]]></content:encoded></item></channel></rss>