<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tanvir Ahmed Tuhin on Medium]]></title>
        <description><![CDATA[Stories by Tanvir Ahmed Tuhin on Medium]]></description>
        <link>https://medium.com/@tanvir011?source=rss-5279af0d80e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*joEELCF6E2JycIoV</url>
            <title>Stories by Tanvir Ahmed Tuhin on Medium</title>
            <link>https://medium.com/@tanvir011?source=rss-5279af0d80e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:12:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanvir011/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reverse Words in a String — LeetCode 151]]></title>
            <link>https://medium.com/@tanvir011/reverse-words-in-a-string-leetcode-151-691f0313c666?source=rss-5279af0d80e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/691f0313c666</guid>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[Tanvir Ahmed Tuhin]]></dc:creator>
            <pubDate>Fri, 04 Sep 2026 16:53:59 GMT</pubDate>
            <atom:updated>2026-09-04T16:53:59.479Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r-7Tssgm2bG1cBX5" /></figure><p>While practicing string problems, I came across a problem called <strong>“Reverse Words in a String.”</strong></p><p>At first, it looked pretty simple:</p><blockquote><em>Given a string, reverse the order of its words.</em></blockquote><p>For example:</p><pre>Input:  &quot;the sky is blue&quot;<br>Output: &quot;blue is sky the&quot;</pre><p>But there is a small twist. The input can contain <strong>extra spaces</strong>, including spaces at the beginning, at the end, or multiple spaces between words.</p><p>For example:</p><pre>Input:  &quot;  hello   world  &quot;<br>Output: &quot;world hello&quot;</pre><p>So, let’s solve it step by step.</p><h3>My Approach</h3><p>Instead of trying to reverse the entire string character by character, I thought:</p><p><strong>Why not first separate the words and store them in a vector?</strong></p><p>For example:</p><pre>&quot;the sky is blue&quot;</pre><p>can be converted into:</p><pre>[&quot;the&quot;, &quot;sky&quot;, &quot;is&quot;, &quot;blue&quot;]</pre><p>Then all I have to do is traverse the vector from the back.</p><h3>Step 1: Extract the Words</h3><p>I used a word string to build each word character by character.</p><pre>string word = &quot;&quot;;</pre><pre>for(char c : s) {<br>    if(c != &#39; &#39;) {<br>        word += c;<br>    }<br>    else {<br>        if(word != &quot;&quot;) {<br>            words.push_back(word);<br>            word = &quot;&quot;;<br>        }<br>    }<br>}</pre><p>Here:</p><pre>if(c != &#39; &#39;)</pre><p>means the current character is not a space, so I add it to word.</p><p>For example, while processing:</p><pre>&quot;the sky&quot;</pre><p>word becomes:</p><pre>t<br>th<br>the</pre><p>When a space is found, &quot;the&quot; is stored in the vector.</p><p>The condition:</p><pre>if(word != &quot;&quot;)</pre><p>is important because the input may contain multiple spaces.</p><p>For example:</p><pre>&quot;hello   world&quot;</pre><p>We don’t want to store empty strings in our vector.</p><p>After the loop, we also need to add the last word because there may not be a space after it:</p><pre>if(word != &quot;&quot;) {<br>    words.push_back(word);<br>}</pre><p>Now:</p><pre>&quot;the sky is blue&quot;</pre><p>becomes:</p><pre>[&quot;the&quot;, &quot;sky&quot;, &quot;is&quot;, &quot;blue&quot;]</pre><h3>Step 2: Traverse the Vector Backwards</h3><p>Now the difficult part is basically over.</p><p>We already have the words separated.</p><p>So we start from the last word:</p><pre>string ans = &quot;&quot;;</pre><pre>for(int i = words.size() - 1; i &gt;= 0; i--) {<br>    ans += words[i];</pre><pre>    if(i != 0) {<br>        ans += &quot; &quot;;<br>    }<br>}</pre><p>The vector:</p><pre>[&quot;the&quot;, &quot;sky&quot;, &quot;is&quot;, &quot;blue&quot;]</pre><p>is traversed like this:</p><pre>blue<br>is<br>sky<br>the</pre><p>So the final answer becomes:</p><pre>&quot;blue is sky the&quot;</pre><p>The condition:</p><pre>if(i != 0)</pre><p>is used so that we don’t add an extra space at the end.</p><h3>Final Code</h3><pre>class Solution {<br>public:<br>    string reverseWords(string s) {<br>        vector&lt;string&gt; words;<br>        string word = &quot;&quot;;</pre><pre>        for(char c : s) {<br>            if(c != &#39; &#39;) {<br>                word += c;<br>            }<br>            else {<br>                if(word != &quot;&quot;) {<br>                    words.push_back(word);<br>                    word = &quot;&quot;;<br>                }<br>            }<br>        }</pre><pre>        if(word != &quot;&quot;) {<br>            words.push_back(word);<br>        }</pre><pre>        string ans = &quot;&quot;;</pre><pre>        for(int i = words.size() - 1; i &gt;= 0; i--) {<br>            ans += words[i];</pre><pre>            if(i != 0) {<br>                ans += &quot; &quot;;<br>            }<br>        }</pre><pre>        return ans;<br>    }<br>};</pre><h3>Example</h3><p>Let’s take:</p><pre>&quot;a good   example&quot;</pre><p>After extracting the words:</p><pre>[&quot;a&quot;, &quot;good&quot;, &quot;example&quot;]</pre><p>Then traversing backwards:</p><pre>example<br>good<br>a</pre><p>Final result:</p><pre>&quot;example good a&quot;</pre><h3>Complexity</h3><p>Let n be the length of the string.</p><ul><li><strong>Time Complexity:</strong> O(n)</li><li><strong>Space Complexity:</strong> O(n)</li></ul><p>We use extra space for the vector and the resulting string.</p><h3>What I Learned</h3><p>The main thing I learned from this problem is that sometimes we don’t need to make the problem complicated.</p><p>Instead of trying to reverse everything at once, I broke the problem into two simple steps:</p><p><strong>String → Words → Reverse Words</strong></p><p>This made the problem much easier to understand and implement.</p><p>If you’re practicing DSA and still getting comfortable with strings and vectors, this is a good problem to practice because it combines both in a very straightforward way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=691f0313c666" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Valid Palindrome — Two Pointer Approach]]></title>
            <link>https://medium.com/@tanvir011/valid-palindrome-two-pointer-approach-a8aef8f3a68e?source=rss-5279af0d80e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8aef8f3a68e</guid>
            <category><![CDATA[blind75]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[validpalindrom]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Tanvir Ahmed Tuhin]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 17:58:10 GMT</pubDate>
            <atom:updated>2026-09-02T17:58:10.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*dM-oNRbx_K3AJ0HH.jpg" /></figure><h3>Problem</h3><p>We are given a string s. We need to check whether the string is a palindrome or not.</p><p>While checking the palindrome:</p><ul><li>We don’t consider spaces or special characters.</li><li>We don’t care about uppercase or lowercase letters.</li></ul><p>For example:</p><pre>&quot;A man, a plan, a canal: Panama&quot;</pre><p>This is a palindrome because after removing spaces and special characters and ignoring the case, it becomes:</p><pre>&quot;amanaplanacanalpanama&quot;</pre><h3>Approach</h3><p>First, I create a new string variable called s1.</p><pre>string s1 = &quot;&quot;;</pre><p>Then I loop through all the characters of the original string s.</p><pre>for (char c : s)</pre><p>For each character, I check whether it is a letter or a number using the isalnum() function.</p><pre>if (isalnum(c))</pre><p>isalnum() returns true if the character is an alphabet or a number. Otherwise, it returns false.</p><p>So, spaces and special characters will not be stored in s1.</p><p>I also convert every valid character to lowercase using tolower() and store it in s1.</p><pre>s1 += tolower(c);</pre><p>For example:</p><pre>Original:<br>&quot;A man, a plan!&quot;</pre><pre>After filtering and converting to lowercase:<br>&quot;amanaplan&quot;</pre><p>Now s1 contains only the characters that we actually need to compare.</p><h3>Two Pointer Approach</h3><p>After creating the new string, I use the <strong>Two Pointer</strong> approach.</p><p>I create two pointers:</p><pre>int st = 0, end = s1.size() - 1;</pre><p>Here:</p><ul><li>st points to the first character.</li><li>end points to the last character.</li></ul><p>Then I use a while loop:</p><pre>while (st &lt; end)</pre><p>The loop continues until the two pointers meet or cross each other.</p><p>Inside the loop, I compare the characters at both pointers.</p><pre>if (s1[st] != s1[end])</pre><p>If the first character and last character are different, then the string cannot be a palindrome.</p><p>So, I immediately return false.</p><pre>return false;</pre><p>On the other hand, if both characters are the same, I move both pointers toward the center.</p><pre>st++;<br>end--;</pre><p>For example:</p><pre>s1 = &quot;madam&quot;</pre><pre>m a d a m<br>↑       ↑<br>st     end</pre><p>First:</p><pre>m == m</pre><p>So we move the pointers:</p><pre>m a d a m<br>  ↑   ↑<br> st  end</pre><p>Again:</p><pre>a == a</pre><p>Then we move them again and reach the middle.</p><p>If the loop finishes without finding any different pair of characters, that means all corresponding characters are the same.</p><p>Therefore, the string is a palindrome, so we return:</p><pre>return true;</pre><h3>C++ Solution</h3><pre>class Solution {<br>public:<br>    bool isPalindrome(string s) {</pre><pre>        string s1 = &quot;&quot;;</pre><pre>        for (char c : s) {<br>            if (isalnum(c)) {<br>                s1 += tolower(c);<br>            }<br>        }</pre><pre>        int st = 0, end = s1.size() - 1;</pre><pre>        while (st &lt; end) {<br>            if (s1[st] != s1[end]) {<br>                return false;<br>            } else {<br>                st++;<br>                end--;<br>            }<br>        }</pre><pre>        return true;<br>    }<br>};</pre><h3>Complexity</h3><p>Let n be the length of the original string.</p><h3>Time Complexity: O(n)</h3><p>We traverse the string once to create s1, and then traverse the valid characters again using two pointers.</p><p>So the overall time complexity is:</p><pre>O(n)</pre><h3>Space Complexity: O(n)</h3><p>We create a new string s1 to store the valid characters.</p><p>Therefore, the space complexity is:</p><pre>O(n)</pre><h3>Conclusion</h3><p>The main idea is simple:</p><ol><li>Remove spaces and special characters using isalnum().</li><li>Convert characters to lowercase using tolower().</li><li>Use two pointers, one from the beginning and one from the end.</li><li>Compare both characters.</li><li>If any pair is different, return false.</li><li>If all pairs are the same, return true.</li></ol><p>This makes the palindrome check simple and easy to understand using the Two Pointer technique.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8aef8f3a68e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master Linked List from Scratch]]></title>
            <link>https://medium.com/@tanvir011/master-linked-list-from-scratch-a9fa2fee57fd?source=rss-5279af0d80e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9fa2fee57fd</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[dsa-problem]]></category>
            <category><![CDATA[singly-linked-list]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Tanvir Ahmed Tuhin]]></dc:creator>
            <pubDate>Sun, 02 Aug 2026 12:57:46 GMT</pubDate>
            <atom:updated>2026-08-02T12:57:46.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yz0wphz9LJX7rBfl0UdWDg.png" /><figcaption>pic collect from internet</figcaption></figure><pre>I&#39;m a 4th-year Computer Science student. I&#39;m just an average person <br>like everyone else.</pre><p><em>It is not </em><strong><em>language</em></strong><em> specific article .Trust me ,you will learn a lot .No matter what language you use .</em></p><p>So, with that let&#39;s start.<br>Hello, my fellow programmer’s today I’m going to teach you how you can become master’s in LinkedList.</p><h3><strong>What is LinkedList?</strong></h3><p>LinkedList is a linear data Structure in which data store in linear sequence.</p><p>But???</p><p><strong>Array is also linear data structure.It is stores data in linear form.Then whats the difference !</strong></p><p>In array we have to first declared the size in Array.</p><pre>int arr[5];<br>Array:-[10,20,30,40,50]</pre><blockquote><strong><em>Memory size : 1Bit size=4, therefore 8 bit=5*4=20 bit.</em></strong></blockquote><p>But linked list is dynamic ,because its size is not fixed, we don’t have to define it’s size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*iY30Ppo1G3Pwm8WQCv3KMQ.png" /></figure><p><em>In linked list we can add element as many as we want, on the other hand the array size is fixed if we want to add more element we need to create different array.</em></p><pre>Advantage:                           |  Disadvantage:<br><br>1.Dynamic Size                          1.Slow random acess.<br>2.Add &amp; remove element easily(just      2.slow traversal Compare to array<br>shift the pointer,)  <br>3.No memory Wastage.                    3.No random Access         </pre><h3><strong>There are 4 types of linked list ,but in general we use 3 types:</strong></h3><h3>1.Single LinkedList:</h3><p>In linked list in which each node points to the next node and the last node points to null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fMN39mXpVBY3zGVvAR0sw.png" /></figure><h3>Double Linked List:</h3><p>Linked list in which each node has two pointer , p and n, such that p points to the previous node and n points to the next node , last node n pointer points to null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aEKh8iJNgbFMiSfQP9YFCQ.png" /></figure><h3><strong>Circular -Linked list:</strong></h3><p>In a circular linked list, the last node points back to the head node, forming a closed loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfnVUyOkvkTTSQV217lsxg.png" /></figure><p><strong>Time Complexity:</strong></p><pre>Access: O(n)<br>Search: O(n)<br>Insert: O(1)<br>Remove: O(1)</pre><h3><strong>Creating a Linked List</strong></h3><p>There are two information sets to store at every node, thus there is a need to create a self-defined data type to handle them. Therefore, we will use the help of <strong>structs</strong> and <strong>classes</strong>.</p><pre>#include &lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>// Node class represents a node in the linked list<br>class Node {<br>public:<br>    int data;     // Data value<br>    Node* next;   // Pointer to next node<br><br>    // Constructor with data and next<br>    Node(int data1, Node* next1) {<br>        data = data1;<br>        next = next1;<br>    }<br><br>    // Constructor with only data<br>    Node(int data1) {<br>        data = data1;<br>        next = nullptr;<br>    }<br>};<br><br>int main() {<br>    // Create an array<br>    vector&lt;int&gt; arr = {2, 5, 8, 7};<br><br>    // Create first node<br>    Node* y = new Node(arr[0]);<br><br>    // Print memory location of node<br>    cout &lt;&lt; y &lt;&lt; &#39;\n&#39;;<br><br>    // Print data stored in node<br>    cout &lt;&lt; y-&gt;data &lt;&lt; &#39;\n&#39;;<br><br>    return 0;<br>}</pre><pre>                         Best Question&#39;s to practice</pre><p>Problem list is in order from <strong>EASY to HARD</strong> in a sequence. And all question&#39;s are available on LeetCode!</p><p>Remember : Practice makes a men perfect</p><ol><li>Reverse a Linked List</li><li>Middle of the Linked List</li><li>Delete Node in a Linked List</li><li>Merge Two Sorted Linked List</li><li>Remove duplicates from sorted list</li><li>Intersection of two linked list</li><li>Linked List Cycle</li><li>Palindrome Linked List</li><li>Swapping Nodes in a Linked List</li><li>Odd Even Linked List</li><li>Remove nth node from Linked List</li><li>Add Two Numbers</li><li>Swap Nodes in Pairs</li><li>Split Linked List in Parts</li><li>Insertion sort on Linked List</li><li>Merge sort on Linked List</li><li>Copy list with random pointers</li><li>Remove zero sum from consecutive nodes from linked list</li><li>Merge k sorted Linked List</li><li>Reverse nodes in k group</li><li>Doubly Linked List</li><li>Adding a node at the front, at the end, after a node or before a node</li><li>Deleting a node from the front, from the end, after a node or before a node</li><li>Circular Doubly Linked List</li><li>Adding a node at the front, at the end, after a node or before a node</li><li>Deleting a node from the front, from the end, after a node or before a node</li><li>LRU Cache.</li></ol><blockquote><strong><em>Thank you for reading! I hope this article helped you understand the topic better. Stay tuned for more programming tutorials and solutions.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9fa2fee57fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>