<?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[Webby Journal]]></title><description><![CDATA[A developer journal by Abhishek Vedant—documenting web development, NeetCode 250 DSA solutions in JS/TS, and software engineering notes.]]></description><link>https://webbyjournal.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/63aae712f42b1f067f8371ef/bc580560-7761-4624-bd97-c633b3c106db.jpg</url><title>Webby Journal</title><link>https://webbyjournal.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 16:17:09 GMT</lastBuildDate><atom:link href="https://webbyjournal.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Valid Anagram || Arrays & Hashing || Neetcode 250 || JS/TS]]></title><description><![CDATA[Valid Anagram coding problem, a quick sorting approach and an optimal O(n) frequency-counting solution using Maps.]]></description><link>https://webbyjournal.hashnode.dev/valid-anagram-arrays-hashing-neetcode-250-js-ts</link><guid isPermaLink="true">https://webbyjournal.hashnode.dev/valid-anagram-arrays-hashing-neetcode-250-js-ts</guid><category><![CDATA[leetcode]]></category><category><![CDATA[#Neetcode]]></category><category><![CDATA[DSA]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[Abhishek V]]></dc:creator><pubDate>Mon, 16 Nov 2026 10:48:55 GMT</pubDate><content:encoded><![CDATA[<p>Here is another classic problem, and just like the previous ones, it looks very approachable.</p>
<p>The question is phrased like this:</p>
<p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code> if <code>t</code> is an anagram of <code>s</code>, and <code>false</code> otherwise.</p>
<p>An <strong>Anagram</strong> is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.</p>
<p><strong>Example 1:</strong></p>
<pre><code class="language-typescript">Input: s = "racecar", t = "carrace"

Output: true
</code></pre>
<p><strong>Example 2:</strong></p>
<pre><code class="language-typescript">Input: s = "jar", t = "jam"

Output: false
</code></pre>
<p>Before we even touch any code,<br />We know that if we <strong>check their lengths</strong>. If <code>s</code> and <code>t</code> don't have the exact same number of characters, they can never be anagrams of each other. That immediately gives us an easy <code>false</code> right at the start.</p>
<p>Now, for the actual logic. The most intuitive way to think about anagrams is sorting. If two words are made of the exact same letters just shuffled around, sorting both of them alphabetically should produce the exact same string.</p>
<p>Let's start with that approach first:</p>
<pre><code class="language-typescript">function isAnagram(s: string, t: string): boolean {
    if (s.length !== t.length) return false;
    return s.split('').sort().join('') === t.split('').sort().join('');
}
</code></pre>
<p>It's clean, readable, and only takes two lines! We split each string into an array of characters, sort them alphabetically, and join them back together to compare.</p>
<p>However,<br />sorting comes with a trade-off. Sorting a string of length n takes O(nlogn) time.</p>
<p>Can we do better and bring the time complexity down to O(n)?</p>
<p>Of course we can!<br /><br />Instead of sorting, we can just count the frequency of every character in both strings using two hash maps. If every character appears the exact same number of times in both <code>s</code> and <code>t</code>, then we have a valid anagram.</p>
<p>Here is how that looks:</p>
<pre><code class="language-typescript">function    isAnagram(s: string, t: string): boolean {

        if (s.length !== t.length) return false;
        const s_map: Map&lt;string, number&gt; = new Map();
        const t_map: Map&lt;string, number&gt; = new Map();

        for (let i = 0; i &lt; s.length; i++) {
            if (s_map.has(s[i])) s_map.set(s[i], s_map.get(s[i]) + 1);
            else if (!s_map.has(s[i])) s_map.set(s[i], 1);
            if (t_map.has(t[i])) t_map.set(t[i], t_map.get(t[i]) + 1);
            else if (!t_map.has(t[i])) t_map.set(t[i], 1);
        }
        for (let i of s) {
            if (s_map.get(i) !== t_map.get(i)) return false;
        }
        return true;
    }
}
</code></pre>
<p>another example of short code is not always the better one.<br /><br />see you in the next read!</p>
]]></content:encoded></item><item><title><![CDATA[Contains Duplicate || Arrays & Hashing || Neetcode 250 || JS/TS]]></title><description><![CDATA[Learn three ways to solve the "Contains Duplicate" from simple brute force to fast, efficient solutions using Sets and early exit optimization.]]></description><link>https://webbyjournal.hashnode.dev/contains-duplicate-arrays-hashing-neetcode-250-js-ts</link><guid isPermaLink="true">https://webbyjournal.hashnode.dev/contains-duplicate-arrays-hashing-neetcode-250-js-ts</guid><category><![CDATA[#Neetcode]]></category><category><![CDATA[leetcode]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[DSA]]></category><dc:creator><![CDATA[Abhishek V]]></dc:creator><pubDate>Mon, 16 Nov 2026 05:33:27 GMT</pubDate><content:encoded><![CDATA[<p>Another simple question from this list. I'm sure we'll be seeing fewer of these easy ones as we go further down!</p>
<p>The question is phrased like this:</p>
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>more than once</strong> in the array; otherwise, return <code>false</code>.</p>
<p><strong>Example 1:</strong></p>
<pre><code class="language-typescript">Input: nums = [1, 2, 3, 3]

Output: true
</code></pre>
<p><strong>Example 2:</strong></p>
<pre><code class="language-typescript">Input: nums = [1, 2, 3, 4]

Output: false
</code></pre>
<p>Seems simple enough. I am sure you already have a few solutions in mind, and one of them is bound to involve a nested loop comparing every element against the others. So, let's start with that one first.</p>
<pre><code class="language-typescript">function hasDuplicate(nums: number[]): boolean {
    for (let i = 0; i &lt; nums.length; i++) {
        for (let j = i + 1; j &lt; nums.length; j++) {
            if (nums[i] === nums[j]) return true;
        }
    }
    return false;
}
</code></pre>
<p>This solution is the textbook definition of brute force. Let's break down what we are doing here:</p>
<p>We are iterating through the elements of <code>nums</code> in the first loop, and guess what? We are doing the exact same thing in the second loop. The only difference is that the second loop iterates over a shrinking subarray always n-1 elements if the outer loop runs for n elements. We do this so we don't accidentally compare an element with itself. If that happened, we'd trigger a false positive for a duplicate every single time!</p>
<p>The code is straightforward, but it comes with a time complexity of O(n^2). That's quite slow for large arrays, and while it passes for this specific problem, it won't cut it for harder challenges.</p>
<p>So, can we make the solution shorter, simpler, and faster?</p>
<p>Of course we can. Here is a very short approach:</p>
<pre><code class="language-typescript">function hasDuplicate(nums: number[]): boolean {
    return new Set(nums).size !== nums.length;
}
</code></pre>
<p>By passing the array straight into a <code>Set</code>, we automatically strip out all duplicate values because sets only store unique items. If the original array contained a duplicate, its length won't match the size of our new set. All we have to do is compare their lengths: if they are the same, there were no duplicates; if they differ, we had at least one!</p>
<p>It's simple, it's short, and it brings our time complexity down to O(n). But does shorter always mean better in practice? Not necessarily.</p>
<p>That brings us to our third and final solution:</p>
<pre><code class="language-typescript">function hasDuplicate(nums: number[]): boolean {
    const numCount: Set&lt;number&gt; = new Set();
    for (let i of nums) {
        if (numCount.has(i)) return true;
        numCount.add(i);
    }
    return false;
}
</code></pre>
<p>It might not be a one-liner, but this approach introduces a powerful optimization: <strong>early exit (or short-circuiting)</strong>.</p>
<p>While the previous one-liner creates the entire set for the whole array upfront, this iterative approach checks each element against our tracking set one by one. The moment it finds a duplicate, it immediately returns <code>true</code> and stops running. If the duplicate happens to show up early in a massive array, this saves a tremendous amount of processing time compared to processing every single element blindly.<br /><br />and I'll see you in the next read.</p>
]]></content:encoded></item><item><title><![CDATA[Concatenation of Array || Arrays & Hashing || Neetcode 250 || JS/TS]]></title><description><![CDATA[Part 1 of my NeetCode 250 JS/TS series: a beginner-friendly breakdown of Concatenation of Array, from loops to a one-liner.]]></description><link>https://webbyjournal.hashnode.dev/concatenation-of-array-arrays-hashing-neetcode-250-js-ts</link><guid isPermaLink="true">https://webbyjournal.hashnode.dev/concatenation-of-array-arrays-hashing-neetcode-250-js-ts</guid><category><![CDATA[leetcode]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[DSA]]></category><category><![CDATA[#Neetcode]]></category><dc:creator><![CDATA[Abhishek V]]></dc:creator><pubDate>Sat, 14 Nov 2026 11:07:09 GMT</pubDate><content:encoded><![CDATA[<p>The question is a simple one. It is phrased like this:</p>
<p>You are given an integer array <code>nums</code> of length <code>n</code>. Create an array <code>ans</code> of length <code>2n</code> where <code>ans[i] == nums[i]</code> and <code>ans[i + n] == nums[i]</code> for <code>0 &lt;= i &lt; n</code> <strong>(0-indexed)</strong>.</p>
<p>Specifically, <code>ans</code> is the concatenation of two <code>nums</code> arrays.</p>
<p>Return the array <code>ans</code>.</p>
<p>Don't get intimidated by the wording; let's break down what it actually means.</p>
<p>They want you to create an array named <code>ans</code> whose length should be twice that of the provided <code>nums</code> array. What will this new array be filled with?</p>
<p>The condition <code>ans[i] == nums[i]</code> means that the first <code>n</code> elements of <code>ans</code> will have all the same elements as <code>nums</code>. As for the last <code>n</code> elements, the second-to-last line states that <code>ans[i + n] == nums[i]</code>, which means the elements from <code>nums</code> repeat after the <code>n</code>th index.</p>
<p>Let's do exactly that.</p>
<pre><code class="language-typescript">function getConcatenation(nums: number[]): number[] {
    let ans = [];
    for(let i = 0; i &lt; nums.length; i++) {
        ans.push(nums[i]);
    }
    for(let i = 0; i &lt; nums.length; i++) {
        ans.push(nums[i]);
    }
    return ans;
}
</code></pre>
<p>Looking at the function above: We initialized <code>ans</code> as an empty array, then pushed all the elements of <code>nums</code> into it once (satisfying <code>ans[i] == nums[i]</code>). Then, we pushed all the elements of <code>nums</code> into <code>ans</code> one more time to satisfy <code>ans[i + n] == nums[i]</code>, and finally returned <code>ans</code>.</p>
<p>It's a straightforward solution with just two loops. But can it be simpler?</p>
<p>Yes, indeed it can.</p>
<p>Since the test cases only check whatever we return rather than verifying a specific memory reference for <code>ans</code>, we don't necessarily need a brand-new array. Instead of pushing the values of <code>nums</code> into a separate <code>ans</code> array twice, we can just push the values of <code>nums</code> back into <code>nums</code> once and return that.</p>
<pre><code class="language-typescript">function getConcatenation(nums: number[]): number[] {
    let size = nums.length;
    for(let i = 0; i &lt; size; i++) {
         nums.push(nums[i]);
    }
    return nums;
}
</code></pre>
<p>The only trade-off here is that we need to store the initial length of <code>nums</code> beforehand. If we used <code>nums.length</code> dynamically inside the loop condition, pushing new elements would increase the array's length continuously, causing an infinite loop.</p>
<p>Now, this solution is smaller and simpler. But can we make it even more concise?</p>
<p>Of course we can!</p>
<p>Right now, we still need to run a loop, save a variable, and return a value, three different things. Can't we do it all in one step? After all, it's an extremely easy problem.</p>
<p>Yes, we can.</p>
<p>In JavaScript, we can use the spread operator to unpack the elements of an array by placing three dots in front of the array name, like this: <code>...nums</code>. We can simply return <code>nums</code> destructured inside a new array twice:</p>
<pre><code class="language-typescript">function getConcatenation(nums: number[]): number[] {
    return [...nums, ...nums];
}
</code></pre>
<p>And here is my final submission to this extremely simple question. Unfortunately, I couldn't make it any smaller or simpler, but for now, I am quite content with it!</p>
]]></content:encoded></item></channel></rss>