<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tochi</title>
    <description>The latest articles on DEV Community by Tochi (@tochi_).</description>
    <link>https://dev.to/tochi_</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%2F1070815%2F767e146a-eea7-4e6d-8da9-7eef0c6c6fed.png</url>
      <title>DEV Community: Tochi</title>
      <link>https://dev.to/tochi_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tochi_"/>
    <language>en</language>
    <item>
      <title>Leetcode 13: Roman to Integer</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Wed, 10 Dec 2025 08:57:06 +0000</pubDate>
      <link>https://dev.to/tochi_/leetcode-13-roman-to-integer-43pf</link>
      <guid>https://dev.to/tochi_/leetcode-13-roman-to-integer-43pf</guid>
      <description>&lt;h3&gt;
  
  
  Question
&lt;/h3&gt;

&lt;p&gt;Roman numerals are represented by seven different symbols: &lt;code&gt;I&lt;/code&gt;, &lt;code&gt;V&lt;/code&gt;, &lt;code&gt;X&lt;/code&gt;, &lt;code&gt;L&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt;, &lt;code&gt;D&lt;/code&gt; and &lt;code&gt;M&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I        =    1&lt;br&gt;
V        =     5&lt;br&gt;
X         =    10&lt;br&gt;
L         =    50&lt;br&gt;
C         =    100&lt;br&gt;
D         =    500&lt;br&gt;
M          =   1000&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;2&lt;/code&gt; is written as &lt;code&gt;II&lt;/code&gt; in Roman numeral, just two ones added together. &lt;code&gt;12&lt;/code&gt; is written as &lt;code&gt;XII&lt;/code&gt;, which is simply &lt;code&gt;X + II&lt;/code&gt;. The number &lt;code&gt;27&lt;/code&gt; is written as &lt;code&gt;XXVII&lt;/code&gt;, which is &lt;code&gt;XX + V + II&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Roman numerals are usually written &lt;strong&gt;largest to smallest from left to right&lt;/strong&gt;. However, the numeral for four is not &lt;code&gt;IIII&lt;/code&gt;. Instead, the number &lt;code&gt;four&lt;/code&gt; is written as &lt;code&gt;IV&lt;/code&gt;. Because the &lt;strong&gt;one is before the five we subtract&lt;/strong&gt; it making four. The same principle applies to the number &lt;code&gt;nine&lt;/code&gt;, which is written as &lt;code&gt;IX&lt;/code&gt;. There are six instances where subtraction is used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;I&lt;/code&gt; can be placed before &lt;code&gt;V&lt;/code&gt; (5) and &lt;code&gt;X&lt;/code&gt; (10) to make &lt;code&gt;4&lt;/code&gt; and &lt;code&gt;9&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;X&lt;/code&gt; can be placed before &lt;code&gt;L&lt;/code&gt; (50) and &lt;code&gt;C&lt;/code&gt; (100) to make &lt;code&gt;40&lt;/code&gt; and &lt;code&gt;90&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;C&lt;/code&gt; can be placed before &lt;code&gt;D&lt;/code&gt; (500) and &lt;code&gt;M&lt;/code&gt; (1000) to make &lt;code&gt;400&lt;/code&gt; and &lt;code&gt;900&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Given a roman numeral, convert it to an integer.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 1:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: s = "III"
Output: 3
Explanation: III = 3.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example 2:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example 3:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Approach
&lt;/h3&gt;

&lt;p&gt;Initially, I could not figure out where to start or how to go about this task. So I went through the question again and noticed that the solution was already inside the question. It explained that with Roman numerals, you usually add two or more constant numerals to get some values or subtract two or more numerals to get others. When I say constant numerals, I mean the symbols like &lt;code&gt;I&lt;/code&gt;, &lt;code&gt;V&lt;/code&gt;, &lt;code&gt;X&lt;/code&gt;, &lt;code&gt;L&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt;, &lt;code&gt;D&lt;/code&gt;, &lt;code&gt;M&lt;/code&gt; and so on.&lt;/p&gt;

&lt;p&gt;With this, the approach becomes clearer. Given a string, the first thing to note is that we have to loop through each character in the string. We then compare each character to the Roman numeral symbols above to get the number value that matches that character.&lt;/p&gt;

&lt;p&gt;We also create a variable named &lt;code&gt;total&lt;/code&gt; outside the loop with a default value of &lt;code&gt;0&lt;/code&gt;. This variable will be updated every time the loop runs. It stores our running sum.&lt;/p&gt;

&lt;p&gt;Inside the loop, compare the current item with the next item.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the current item is &lt;strong&gt;greater than&lt;/strong&gt; the next item, add it to &lt;code&gt;total&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the current item is &lt;strong&gt;less than&lt;/strong&gt; the next item, subtract it from &lt;code&gt;total&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever result you get becomes the new value of &lt;code&gt;total&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Given a string &lt;code&gt;s = "MCMXCIV"&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with &lt;code&gt;total = 0&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Current item &lt;code&gt;M = 1000&lt;/code&gt;, next item &lt;code&gt;C = 100&lt;/code&gt;. 1000 &amp;gt; 100 → add 1000. &lt;code&gt;total = 1000&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Current item &lt;code&gt;C = 100&lt;/code&gt;, next item &lt;code&gt;M = 1000&lt;/code&gt;. 100 &amp;lt; 1000 → subtract 100. &lt;code&gt;total = 900&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Current item &lt;code&gt;M = 1000&lt;/code&gt;, next item &lt;code&gt;X = 10&lt;/code&gt;. 1000 &amp;gt; 10 → add 1000. &lt;code&gt;total = 1900&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Current item &lt;code&gt;X = 10&lt;/code&gt;, next item &lt;code&gt;C = 100&lt;/code&gt;. 10 &amp;lt; 100 → subtract 10. &lt;code&gt;total = 1890&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Current item &lt;code&gt;C = 100&lt;/code&gt;, next item &lt;code&gt;I = 1&lt;/code&gt;. 100 &amp;gt; 1 → add 100. &lt;code&gt;total = 1990&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Current item &lt;code&gt;I = 1&lt;/code&gt;, next item &lt;code&gt;V = 5&lt;/code&gt;. 1 &amp;lt; 5 → subtract 1. &lt;code&gt;total = 1989&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Last item &lt;code&gt;V = 5&lt;/code&gt; (no next item). Just add 5. &lt;code&gt;total = 1994&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the value of &lt;code&gt;"MCMXCIV"&lt;/code&gt; is &lt;code&gt;1994&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const romanToInt = (s) =&amp;gt; {
  const romanNumerals = {
    I: 1,
    V: 5,
    X: 10,
    L: 50,
    C: 100,
    D: 500,
    M: 1000,
  };

  let total = 0;
  for (let i = 0; i &amp;lt; s.length; i++) {
    let curr = s[i];
    let next = s[i + 1];

    if (romanNumerals[curr] &amp;lt; romanNumerals[next]) {


      total-= romanNumerals[curr];
    } else {
      total+= romanNumerals[curr];
    }
  }

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

&lt;/div&gt;



&lt;p&gt;This solution has a time complexity of O(n) linear time. Feel free to drop links to more solutions in the comment below. Let me know what you think.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>hashtables</category>
      <category>leetcode</category>
      <category>dsa</category>
    </item>
    <item>
      <title>Hash Tables</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Mon, 08 Dec 2025 16:33:44 +0000</pubDate>
      <link>https://dev.to/tochi_/hash-tables-1o03</link>
      <guid>https://dev.to/tochi_/hash-tables-1o03</guid>
      <description>&lt;p&gt;A hash table is a data structure that stores data in key-value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[key, value]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works by passing a key (usually a string) through a hash function.&lt;br&gt;
The hash function generates a number, called the hash index, which tells the table where to store that key–value pair. &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key = "bar" 
hash("bar") =&amp;gt; 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The hash index is &lt;strong&gt;4&lt;/strong&gt;. This index points to a bucket, which is like a storage box where the value is placed.&lt;/p&gt;

&lt;p&gt;Hash tables have O(1) time for inserting, deleting, and retrieving with a worst case scenario of O(n) time if many keys collide. In JavaScript, hash tables appear as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Objects {}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Maps (new Map())&lt;/code&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwlwn5m1h939wipy5tumw.png" alt="Image showing hash tables" width="800" height="557"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Hash Collisions
&lt;/h3&gt;

&lt;p&gt;A collision happens when two different keys hash to the same index.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hash("cat") → 2
hash("tap") → 2

Both keys go into bucket 2 → collision!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5o1mxrazpz1ihwcoz56t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5o1mxrazpz1ihwcoz56t.png" alt="Image showing hash collision" width="300" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Chaining
&lt;/h3&gt;

&lt;p&gt;A common fix for collision is &lt;a href="https://www.educative.io/answers/what-is-chaining-in-hash-tables" rel="noopener noreferrer"&gt;the chaining method.&lt;/a&gt; This is where multiple key–value pairs are stored in the same bucket using a list/array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bucket 2:
[
  ["cat", 5],
  ["tap", 9]
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both live in the same index, no overwriting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hash Table Implementation (Explained Step-by-Step)
&lt;/h3&gt;

&lt;p&gt;Below is a simplified JavaScript implementation showing how hash tables work under the hood.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const hash = (key, bucketSize) =&amp;gt; {
  let hash = 0;

  for (let i = 0; i &amp;lt; key.length; i++) {
    hash += key.charCodeAt(i);
  }

  return hash % bucketSize;
};

function HashTable() {
  let table = [];
  let tableLimit = 10;

  // print
  this.printTable = function () {
    console.log(table);
  };
  // add
  this.set = function (key, value) {
    // get the index of the key
    const index = hash(key, tableLimit);
    // check if the item exists at the index
    if (!table[index]) {
      table[index] = [[key, value]];
    } else {
      // if it does, update the value
      let inserted = false;
      for (let i = 0; i &amp;lt; table[index].length; i++) {
        if (table[index][i][0] === key) {
          table[index][i][1] = value;
          inserted = true;
        }
      }

      if (!inserted) {
        table[index].push([key, value]);
      }
    }
  };

  // delete
  this.remove = function (key) {
    const index = hash(key, tableLimit);

    if (table[index].length === 1 &amp;amp;&amp;amp; table[index][0][0] === key) {
      delete table[index];
    } else {
      for (let i = 0; i &amp;lt; table[index].length; i++) {
        if (table[index][i][0] === key) {
          delete table[index][i];
        }
      }
    }
  };

  // lookup
  this.get = function (key) {
    const index = hash(key, tableLimit);
    if (!table[index]) return undefined;

    for (let i = 0; i &amp;lt; table[index].length; i++) {
      if (table[index][i][0] === key) {
        return table[index][i][1];
      }
    }
  };
}

const myTable = new HashTable();
myTable.set("name", "Alice");
myTable.set("age", 30);
myTable.printTable();
myTable.set("name", "Jane");
myTable.printTable();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The Hash Function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const hash = (key, bucketSize) =&amp;gt; {
  let hash = 0;
  for (let i = 0; i &amp;lt; key.length; i++) {
    hash += key.charCodeAt(i);
  }
  return hash % bucketSize;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start with &lt;code&gt;hash = 0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Loop through each character of the key.&lt;/li&gt;
&lt;li&gt;Convert each character → number (&lt;code&gt;charCodeAt&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Add all the numbers together.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;% bucketSize&lt;/code&gt; makes sure the number fits inside the table size.&lt;/li&gt;
&lt;li&gt;The result tells you which bucket to store the key-value pair in.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The Hash Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function HashTable() {
  let table = [];
  let tableLimit = 10;
/*...some code here..*/
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;table&lt;/code&gt; is the actual array holding buckets.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tableLimit&lt;/code&gt; is how many buckets exist (size of the table).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The Print Function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this.printTable = function () {
  console.log(table);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This just shows the table in the console.&lt;/p&gt;

&lt;h4&gt;
  
  
  SET (insert or update)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this.set = function (key, value) {
  /*some code here*/
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;const index = hash(key, tableLimit);&lt;/code&gt; converts the key to a bucket index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!table[index]) {
  table[index] = [[key, value]];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This checks if the bucket is empty. If it is, it creates the bucket and stores the key/value in a mini array, e.g. &lt;code&gt;[ [key, value] ]&lt;/code&gt;. This is chaining. Each bucket stores a list of items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;else {
  let inserted = false;

  for (let i = 0; i &amp;lt; table[index].length; i++) {
    if (table[index][i][0] === key) {
      table[index][i][1] = value;
      inserted = true;
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The bucket already has items (collision happened). So;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loop through every item in the bucket.&lt;/li&gt;
&lt;li&gt;If the key already exists, update the value.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;inserted = true&lt;/code&gt; so you know the key was found.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If key was not found, then add it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!inserted) {
  table[index].push([key, value]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Remove
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this.remove = function (key) {
  const index = hash(key, tableLimit);

/*more code here*/
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the bucket has only one item, remove the whole bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (table[index].length === 1 &amp;amp;&amp;amp; table[index][0][0] === key) {
  delete table[index];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the bucket has only multiple items, loop through the items and delete only the matched one.&lt;/p&gt;

&lt;h4&gt;
  
  
  Get (lookup)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this.get = function (key) {
  const index = hash(key, tableLimit);
/*...more code here...*/
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the bucket doesn’t exist, the item is not in the table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!table[index]) return undefined;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Search the bucket and check each item in the chain. If a match is found, return the match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; table[index].length; i++) {
  if (table[index][i][0] === key) {
    return table[index][i][1];
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hash tables are used in many places,like storing user information, counting things, checking if something already exists, or quickly finding data by a key. They help programs run faster because they make lookups very quick. It may look complex at first, but once you understand the idea of hashing and buckets, everything becomes surprisingly simple.&lt;/p&gt;

&lt;p&gt;Check out this easy mode hash table question on leetcode: &lt;a href="https://leetcode.com/problems/roman-to-integer/description/?envType=problem-list-v2&amp;amp;envId=hash-table" rel="noopener noreferrer"&gt;Roman to Integer&lt;/a&gt;. Here is an article to &lt;a href="https://dev.to/tochi_/leetcode-13-roman-to-integer-43pf"&gt;my solution&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Hey folks! October is Cybersecurity Awareness Month, and I just published my first ever paper. It’s titled “Common Security Threats in Client–Server Communication”. Please, give it a read here: https://tinyurl.com/sec-threatsts . THANKS A LOT!</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Wed, 15 Oct 2025 21:55:11 +0000</pubDate>
      <link>https://dev.to/tochi_/hey-folks-october-is-cybersecurity-awareness-month-and-i-just-published-my-first-ever-paper-its-3fea</link>
      <guid>https://dev.to/tochi_/hey-folks-october-is-cybersecurity-awareness-month-and-i-just-published-my-first-ever-paper-its-3fea</guid>
      <description>&lt;p&gt;

&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://zenodo.org/records/17360964?token=eyJhbGciOiJIUzUxMiJ9.eyJpZCI6IjdmZDMxYmQ0LTljZDktNDg4Ni04MGFlLWI1YzE4YmFmMTZhMyIsImRhdGEiOnt9LCJyYW5kb20iOiJmOGY2NDIwYTc0YjM2ZjFmYTExZjJmYzZjODg0YjYyNSJ9.4uIXZ7jahckd6arZpO8iusbkMoyef_Ld8bnSTYTqZ8vK1LpgK_abMaMHEg6knOuRF5oDevokihBkH-63pi9Q5g" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fzenodo.org%2Fstatic%2Fimages%2Forcid.svg" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://zenodo.org/records/17360964?token=eyJhbGciOiJIUzUxMiJ9.eyJpZCI6IjdmZDMxYmQ0LTljZDktNDg4Ni04MGFlLWI1YzE4YmFmMTZhMyIsImRhdGEiOnt9LCJyYW5kb20iOiJmOGY2NDIwYTc0YjM2ZjFmYTExZjJmYzZjODg0YjYyNSJ9.4uIXZ7jahckd6arZpO8iusbkMoyef_Ld8bnSTYTqZ8vK1LpgK_abMaMHEg6knOuRF5oDevokihBkH-63pi9Q5g" rel="noopener noreferrer" class="c-link"&gt;
            Common Security Threats In Client-Server Architecture
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            This research paper explores common security threats in client-server communication, which is the foundation of most modern digital systems. It begins by explaining the structure and types of client-server architecture, including two-tier and three-tier systems, before examining key cybersecurity threats such as Man-in-the-Middle (MitM) attacks, Session Hijacking, Cross-Site Scripting (XSS), Cross-Site Request Forgery (CSRF), and SQL Injection. Each attack is explained in simple and clear language, including how it occurs and its impact on client-server communication. The paper also provides detailed preventive measures and best practices, emphasizing encryption, input validation, authentication, and user awareness. The goal of this study is to help readers, especially students and beginners in cybersecurity, understand how these threats work and how to protect client-server systems from them.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fzenodo.org%2Fstatic%2Ffavicon.ico"&gt;
          zenodo.org
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;




</description>
    </item>
    <item>
      <title>First Publication!</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Wed, 15 Oct 2025 21:51:28 +0000</pubDate>
      <link>https://dev.to/tochi_/first-publication-5b38</link>
      <guid>https://dev.to/tochi_/first-publication-5b38</guid>
      <description>&lt;p&gt;Hey folks!&lt;/p&gt;

&lt;p&gt;October is Cybersecurity Awareness Month, and I just published my first ever research paper. I promise I am not crying. Lol.&lt;/p&gt;

&lt;p&gt;It’s titled “&lt;strong&gt;Common Security Threats in Client–Server Communication&lt;/strong&gt;”, a simple breakdown of attacks like MitM, XSS, SQL injection, and how developers can protect their apps.&lt;/p&gt;

&lt;p&gt;If you’re into web development or just curious about cybersecurity, give it a read &lt;a href="https://tinyurl.com/sec-threatsts" rel="noopener noreferrer"&gt;here!&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Would love your thoughts or feedback!&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>systemdesign</category>
      <category>software</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Find The Longest Word In A Sentence: A JavaScript Solution</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Mon, 15 Sep 2025 09:06:15 +0000</pubDate>
      <link>https://dev.to/tochi_/find-the-longest-word-in-a-sentence-a-javascript-solution-1a7n</link>
      <guid>https://dev.to/tochi_/find-the-longest-word-in-a-sentence-a-javascript-solution-1a7n</guid>
      <description>&lt;h3&gt;
  
  
  Question
&lt;/h3&gt;

&lt;p&gt;Have the function &lt;code&gt;LongestWord(sen)&lt;/code&gt; take the &lt;code&gt;sen&lt;/code&gt; parameter being passed and return the longest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume &lt;code&gt;sen&lt;/code&gt; will not be empty. Words may also contain numbers, for example "Hello world123 567".&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const longestWordInArray = (sen) =&amp;gt; {
  if (sen.length === 0) {
    return sen;
  }
  let idx = 0;
  let len = 0;
  const wordsArray = sen.replace(/[^\w ]/g, "").split(" ");
  for (let i = 0; i &amp;lt; wordsArray.length; i++) {
    if (wordsArray[i].length &amp;gt; len) {
      len = wordsArray[i].length;
      idx = i;
    }
  }

  return wordsArray[idx];
};

console.log(longestWordInArray("fun&amp;amp;!! time chimpanze"));

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Solution Breakdown
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The first step is to create the function called &lt;code&gt;longestWordInArray&lt;/code&gt;. It takes one input called sen (which is just a string).&lt;/li&gt;
&lt;li&gt;Next, we check if &lt;code&gt;sen&lt;/code&gt; is empty (""). If it is we just return it. This prevents errors.&lt;/li&gt;
&lt;li&gt;We set up two variables: &lt;code&gt;idx&lt;/code&gt;, the position (index) of the longest word we find. At first, it’s 0. &lt;code&gt;len&lt;/code&gt;, the length of the longest word so far. At first, it’s 0.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const wordsArray = sen.replace(/[^\w ]/g, "").split(" ");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line does two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sen.replace(/[^\w ]/g, "")&lt;/code&gt;: removes punctuation and special characters, so we only keep letters, numbers, and spaces.
Example: "fun&amp;amp;!! time" becomes "fun time".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.split(" ")&lt;/code&gt;: splits the sentence into an array of words (breaking at spaces).
Example: "fun time chimpanze" becomes ["fun", "time", "chimpanze"].&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So now we have an array of words.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  for (let i = 0; i &amp;lt; wordsArray.length; i++) {
    if (wordsArray[i].length &amp;gt; len) {
      len = wordsArray[i].length;
      idx = i;
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop goes through each word in the array:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;wordsArray[i]&lt;/code&gt;: the current word.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wordsArray[i].length&lt;/code&gt;: the number of characters in that word.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the length of the current word is greater than the current value of &lt;code&gt;len&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update &lt;code&gt;len&lt;/code&gt; with the new length.&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;idx&lt;/code&gt; with the position of that word.
This way, after the loop ends, &lt;code&gt;idx&lt;/code&gt; will point to the longest word.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, we return the word at position &lt;code&gt;idx&lt;/code&gt; which is the longest word we found.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion.
&lt;/h3&gt;

&lt;p&gt;In short, the function above removes punctuation, splits the sentence into words, checks which word is the longest, and returns it. The time and space complexity of the solution above is O(n). &lt;/p&gt;

&lt;p&gt;Share your solutions in the comment below. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>dsa</category>
    </item>
    <item>
      <title>Leetcode 189: Rotate Array JavaScript Solution.</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Wed, 03 Sep 2025 12:03:17 +0000</pubDate>
      <link>https://dev.to/tochi_/leetcode-189-rotate-array-javascript-solution-2fb6</link>
      <guid>https://dev.to/tochi_/leetcode-189-rotate-array-javascript-solution-2fb6</guid>
      <description>&lt;h2&gt;
  
  
  Intuition
&lt;/h2&gt;

&lt;p&gt;My first idea was to split the array into two parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The last &lt;code&gt;k&lt;/code&gt; items in the array.&lt;/li&gt;
&lt;li&gt;All the items that come before those last &lt;code&gt;k&lt;/code&gt; items.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But before doing that, I make sure to update k like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;k = k % nums.length;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step is important because sometimes &lt;code&gt;k&lt;/code&gt; can be larger than the length of the array. If &lt;code&gt;k&lt;/code&gt; is larger, rotating the array by k times is the same as rotating it by the remainder after dividing k by the array’s length.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;

&lt;p&gt;Suppose &lt;code&gt;nums.length = 7&lt;/code&gt; and &lt;code&gt;k = 10&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 % 7 = 3.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means rotating the array 10 times is really the same as rotating it 3 times, because after 7 full rotations, the array looks the same again. So you can think of it as: rotate 7 times (which resets the array), then rotate 3 more times.&lt;/p&gt;

&lt;p&gt;After that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create two smaller arrays (one for the last k items, one for the rest).&lt;/li&gt;
&lt;li&gt;Merge those two arrays together.&lt;/li&gt;
&lt;li&gt;Copy the merged result back into the original nums array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;First I set &lt;code&gt;k&lt;/code&gt; to &lt;code&gt;k % nums.length&lt;/code&gt; (I explained why above). Then I created a copy of the nums array and call it &lt;code&gt;numsCopy&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;After that, I looped through the nums array and for each index I added &lt;code&gt;k&lt;/code&gt; to it. This is done to determine the new position of each item when &lt;code&gt;nums&lt;/code&gt; is rotated &lt;code&gt;k&lt;/code&gt; times. &lt;/p&gt;

&lt;p&gt;Now there are two ways to go about the next step. Either we use modulus and say old index plus k (&lt;code&gt;i + k&lt;/code&gt;) and then check if the sum is greater that nums.length-1. If it is we'll subtract nums.length from the sum. &lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;

&lt;p&gt;Suppose &lt;code&gt;i = 4&lt;/code&gt;, &lt;code&gt;k = 3&lt;/code&gt; and &lt;code&gt;nums.length = 7&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let idx = i + k;

if(idx &amp;lt; nums.length - 1){
   idx = idx - nums.length;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or we can use modulus and do old index plus k modulus nums.length (&lt;code&gt;(i + k) % nums.length&lt;/code&gt;). That way we get the new index from the remainder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let idx = (i + k) % nums.length;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both solutions give the new index or position of each item in nums.&lt;/p&gt;

&lt;p&gt;After the new index is gotten, we modify the nums array with the duplicate array by doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nums[idx] = numsCopy[i]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Initial Solution:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const rotate = (nums, k)=&amp;gt; {

  k %= nums.length;

  const kArray = [];

   for (let i = nums.length - k; i &amp;lt; nums.length; i++) {
     kArray.push(nums[i]);
   }

   const firstPartArray = [];

   for (let i = 0; i &amp;lt; nums.length - k; i++) {
     firstPartArray.push(nums[i]);
   }

  const rotatedArr =[...kArray, ...firstPartArray];

  for(let i = 0; i &amp;lt; rotatedArr.length; i++){
   nums[i] = rotatedArr[i]
  }

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Improved Solution:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const rotate = (nums, k)=&amp;gt; {

k %= nums.length;

const numsCopy = [...nums];

for(let i = 0; i &amp;lt; nums.length; i++){
  let rotateIdx = (i + k) % nums.length;

  nums[rotateIdx] = numsCopy[i]
}  
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Complexity
&lt;/h2&gt;

&lt;p&gt;Both solutions have a time and space complexity of O(n) linear time.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>datastructures</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Leetcode 283: Move Zeroes JavaScript Solution</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Mon, 18 Aug 2025 11:46:00 +0000</pubDate>
      <link>https://dev.to/tochi_/leetcode-283-move-zeroes-3g9d</link>
      <guid>https://dev.to/tochi_/leetcode-283-move-zeroes-3g9d</guid>
      <description>&lt;p&gt;Given an integer array &lt;code&gt;nums&lt;/code&gt;, move all 0's to the end of it while maintaining the relative order of the non-zero elements.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note that you must do this in-place without making a copy of the array.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;An in-place algorithm modifies the original array directly instead of creating a separate one. You only use a few extra variables (constant space). This is important in Data Structures and Algorithms (DSA) because it saves memory.&lt;/p&gt;

&lt;p&gt;What this challenge means is, send all the zeros to the right and all the non-zero items in the array without changing the order of the non-zero items. So, if you have &lt;code&gt;[5,0,1,9,0,6]&lt;/code&gt; the output will be &lt;code&gt;[5,1,9,6,0,0]&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Approach
&lt;/h3&gt;

&lt;p&gt;Initially, I solved this using a nested for loop. I compared each item in the array with the next one, and whenever I found a &lt;code&gt;0&lt;/code&gt;, I swapped it forward until it reached the end of the array. While this worked, it was inefficient because the nested loop made the solution run in &lt;code&gt;O(n²)&lt;/code&gt; time. For larger arrays, this approach quickly becomes slow.&lt;/p&gt;

&lt;p&gt;After tons of research, I was able to optimize my solution using the two pointer method. To do that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Pointer 1 (&lt;code&gt;pointer1&lt;/code&gt;) → keeps track of the position where the next non-zero element should go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pointer 2 (&lt;code&gt;i&lt;/code&gt;) → scans through every element of the array.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When we see a non-zero element, we swap it with the element at pointer1. After swapping, we move pointer1 forward by one. If the element is 0, we simply skip it. By the end of the loop, all non-zero numbers are shifted to the left in their original order, and all zeroes are pushed to the right. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Solution
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Solution 1
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const moveZeroes = (nums) =&amp;gt; {
 if(nums.length === 1){
    return nums;
  }

  for (let j = 0; j &amp;lt; nums.length; j++) {
    for (let i = 0; i &amp;lt; nums.length - 1; i++) {
      if (nums[i] === 0) {
        [nums[i], nums[i + 1]] = [nums[i + 1], nums[i]];
      }
    }
  }

  return nums;
};

console.log(moveZeroes([4, 1, 0, 3, 12])); =&amp;gt; [4,1,3,12,0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The solution above uses nested loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution 2
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const moveZeroes = (nums) =&amp;gt; {
  let pointer1= 0;
  for (let i = 0; i &amp;lt; nums.length; i++) {
    if (nums[i] !== 0) {
      [nums[pointer1], nums[i]] = [nums[i], nums[pointer1]];
      pointer1++;
    }
  }
  return nums;
};
console.log(moveZeroes([4, 1, 0, 3, 12]));=&amp;gt;[4,1,3,12,0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Solution 2 Explanation
&lt;/h4&gt;

&lt;p&gt;First remember that &lt;code&gt;pointer1 = 0&lt;/code&gt;, is where the next non-zero should go.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Look at first number(4). 

&lt;ul&gt;
&lt;li&gt;Not zero → put it at index 0.&lt;/li&gt;
&lt;li&gt;Swap index 0 with index 0 → no change.&lt;/li&gt;
&lt;li&gt;Array: &lt;code&gt;[4, 1, 0, 3, 12]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pointer1 = 1&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Look at second number(1)

&lt;ul&gt;
&lt;li&gt;Not zero → put it at index 1.&lt;/li&gt;
&lt;li&gt;Swap index 1 with index 1 → no change.&lt;/li&gt;
&lt;li&gt;Array: &lt;code&gt;[4, 1, 0, 3, 12]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pointer1 = 2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Look at third number(0)

&lt;ul&gt;
&lt;li&gt;It’s zero → do nothing.&lt;/li&gt;
&lt;li&gt;Array stays: &lt;code&gt;[4, 1, 0, 3, 12]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pointer1 = 2&lt;/code&gt; (stays 2 because the if block did not run).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Look at fourth number(3)

&lt;ul&gt;
&lt;li&gt;Not zero → put it at index 2.&lt;/li&gt;
&lt;li&gt;Swap index 2 with index 3 → &lt;code&gt;[4, 1, 3, 0, 12]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pointer1 = 3&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Look at fifth number(12)

&lt;ul&gt;
&lt;li&gt;Not zero → put it at index 3.&lt;/li&gt;
&lt;li&gt;Swap index 3 with index 4 → &lt;code&gt;[4, 1, 3, 12, 0]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pointer1 = 4&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The final result: &lt;code&gt;[4, 1, 3, 12, 0]&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Conclusion
&lt;/h3&gt;

&lt;p&gt;The time complexity for the initial solution (using the nested loops) is O(n²) because for every element in the array, we scan through the entire array again. The optimized solution runs in O(n) time since we only pass through the array once. &lt;/p&gt;

&lt;p&gt;Both solutions are in-place and use O(1) extra space, but the optimized version is much faster and more practical for larger arrays.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>Leetcode 53: Maximum Subarray in JavaScript</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Thu, 14 Aug 2025 13:41:50 +0000</pubDate>
      <link>https://dev.to/tochi_/leetcode-53-maximum-subarray-in-javascript-2ln6</link>
      <guid>https://dev.to/tochi_/leetcode-53-maximum-subarray-in-javascript-2ln6</guid>
      <description>&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;Given an integer array &lt;code&gt;nums&lt;/code&gt;, find the subarray with the largest sum, and return its sum.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A subarray is a contiguous(side-by-side) non-empty sequence of elements within an array. It is a part of the array where the numbers are next to each other. You cannot skip elements in between.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example 1:&lt;br&gt;
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]&lt;br&gt;
Output: 6&lt;br&gt;
Explanation: The subarray [4,-1,2,1] has the largest sum 6.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The Thought Process
&lt;/h3&gt;

&lt;p&gt;We can use Dynamic Programming to solve this problem. Dynamic Programming (DP) is just a way of solving a big problem by breaking it into smaller steps, remembering the answers, and reusing them so we don’t repeat work. &lt;/p&gt;

&lt;p&gt;In this problem, we ask ourselves for every index in the array:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What is the largest sum of a subarray that ends exactly at this index?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we know the largest sum ending at the previous index, we can decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start fresh at the current number (nums[i]) if the previous sum was negative&lt;/li&gt;
&lt;li&gt;Or continue the subarray from before by adding the current number&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gives our DP rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;currentMax = max(nums[i], nums[i] + currentMax(previous))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also keep track of the biggest currentMax we’ve seen so far — that’s our answer.&lt;/p&gt;

&lt;h3&gt;
  
  
  The solution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const maxSubArray = (nums)=&amp;gt; {
  let maxSum = nums[0];
  let currentMax = 0;

  for (let i = 0; i &amp;lt; nums.length; i++) {
    currentMax = Math.max(nums[i], currentMax + nums[i]);
    let currentMaxSum = maxSum;

    if (currentMax &amp;gt; maxSum) {
      maxSum = currentMax;
    } else {
      maxSum = currentMaxSum;
    }
  }

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Time Complexity: O(n). You loop through the array once &lt;code&gt;(for (let i = 0; i &amp;lt; nums.length; i++))&lt;/code&gt;, so the work grows linearly with n.&lt;/li&gt;
&lt;li&gt;Space Complexity: O(1). You only use a fixed number of variables (&lt;code&gt;maxSum, currentMax, currentMaxSum&lt;/code&gt;) regardless of the size of the input array. No extra arrays or data structures are created.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>datastructures</category>
      <category>beginners</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>JavaScript Array Methods Under the Hood: Unshift and Shift Explained</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Thu, 31 Jul 2025 17:57:39 +0000</pubDate>
      <link>https://dev.to/tochi_/javascript-array-methods-under-the-hood-unshift-and-shift-explained-3gd</link>
      <guid>https://dev.to/tochi_/javascript-array-methods-under-the-hood-unshift-and-shift-explained-3gd</guid>
      <description>&lt;p&gt;In a previous article, we broke down how &lt;code&gt;pop()&lt;/code&gt; and &lt;code&gt;push()&lt;/code&gt; work under the hood in JavaScript. If you haven’t read that yet, I recommend checking it out first so this one makes even more sense. You can read it &lt;a href="https://dev.to/tochi_/javascript-array-methods-under-the-hood-push-and-pop-explained-1e59"&gt;here&lt;/a&gt; if you're curious about how arrays handle adding and removing items from the end.&lt;/p&gt;

&lt;p&gt;In this article, we’re looking at the other side: &lt;code&gt;shift()&lt;/code&gt; and &lt;code&gt;unshift()&lt;/code&gt;. Let’s break them down together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Array.unshift(new_item)
&lt;/h3&gt;

&lt;p&gt;This array method is used when you want to add an item to the beginning of an array. Unlike push(), it's not as cheap. It has a time complexity of O(n), linear time.&lt;/p&gt;

&lt;p&gt;If you have an array and you want to add something to the front, i.e index 0, JavaScript has to move every other item one step forward to make space. Imagine shifting people in a line forward to make room for one more at the start. That takes time. Let’s look at what unshift() does under the hood.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const jsUnshift = (arr, newItem) =&amp;gt; {
  let newArr = [newItem];
  for (let i = 0; i &amp;lt; arr.length; i++) {
    newArr[i + 1] = arr[i];
  }

  return newArr;
};

console.log(jsUnshift([1, 2, 3, 4], 0)); 
//result: [0,1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript must make space at index 0. So, it shifts every existing element one position to the right. Another way to do this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numArray = [2, 3, 4];

const jsUnshift = (arr, newItem) =&amp;gt; {
  for (let i = arr.length; i &amp;gt; 0; i--) {
    arr[i] = arr[i - 1]; 
  }
  arr[0] = newItem;
  return arr;
};

console.log(jsUnshift(numArray, 1));
//result ==&amp;gt; [1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time it takes to perform this operation grows with the size of the array. Hence, the time complexity is O(n). &lt;/p&gt;

&lt;h3&gt;
  
  
  Array.shift()
&lt;/h3&gt;

&lt;p&gt;Now for the opposite. shift() removes the first item in the array. It sounds simple, but like unshift(), its time complexity is O(n), linear time.&lt;/p&gt;

&lt;p&gt;Why? Because when the first item is removed, all the other items need to shift one place to the left so the array stays in order. Again, we’re moving stuff.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const jsShift = (arr) =&amp;gt; {
  if (arr.length === 0) return undefined;
  for (let i = 0; i &amp;lt; arr.length; i++) {
    arr[i] = arr[i + 1];
  }
  arr.length = arr.length - 1;
  return arr;
};

console.log(jsShift([1, 3, 4]));
//result ==&amp;gt; [3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;While &lt;code&gt;shift()&lt;/code&gt; and &lt;code&gt;unshift()&lt;/code&gt; may seem straightforward, they’re doing more work behind the scenes than methods like &lt;code&gt;push()&lt;/code&gt; and &lt;code&gt;pop()&lt;/code&gt;. Because arrays are zero-indexed, inserting or removing items from the beginning means all other elements must be re-indexed, making these operations O(n) in time complexity.&lt;/p&gt;

&lt;p&gt;So, the next time you use &lt;code&gt;shift()&lt;/code&gt; or &lt;code&gt;unshift()&lt;/code&gt;, remember: JavaScript is quietly doing a lot of heavy lifting to maintain the order of your array.&lt;/p&gt;

&lt;p&gt;Understanding this can help you make better performance decisions, especially when working with large arrays or performance-critical code.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>JavaScript Array Methods Under the Hood: Push and Pop Explained</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Thu, 31 Jul 2025 15:44:25 +0000</pubDate>
      <link>https://dev.to/tochi_/javascript-array-methods-under-the-hood-push-and-pop-explained-1e59</link>
      <guid>https://dev.to/tochi_/javascript-array-methods-under-the-hood-push-and-pop-explained-1e59</guid>
      <description>&lt;p&gt;JavaScript array methods &lt;em&gt;push(), pop(), shift(), unshift(), and splice()&lt;/em&gt; are used every day by developers, but do you know how they work under the hood?&lt;/p&gt;

&lt;p&gt;In this article, we’ll break down the internal mechanics of these methods, explore their time and space complexities, and explain why some are faster than others. Whether you’re preparing for technical interviews or simply want to write more efficient code, understanding these fundamentals is a must.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Are Arrays?
&lt;/h3&gt;

&lt;p&gt;Let's start by defining arrays. Arrays are data structures used to store a collection of items in a single variable. These items can be of any data type, such as numbers, strings, objects, or even other arrays.&lt;/p&gt;

&lt;p&gt;In JavaScript, arrays are index-based. This means that each item is assigned a position (starting from index 0), making it easy to access or manipulate data based on its position. To learn more about arrays and array methods, check out &lt;a href="https://www.w3schools.com/js/js_arrays.asp" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const animes = ["castlevania", "devil may cry", "rick and morty"]

console.log(animes[0]) ==&amp;gt; castlevania
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Array.push(new_item)
&lt;/h3&gt;

&lt;p&gt;This array method is used when you want to add an item to an array. It has a time complexity of O(1). Let me explain why.&lt;/p&gt;

&lt;p&gt;The first thing to note is that with &lt;em&gt;push()&lt;/em&gt;, you're adding the new item after the last item in the array. So, if you have an array of length &lt;em&gt;n&lt;/em&gt; and you want to add the digit &lt;em&gt;3&lt;/em&gt;, here's what happens: Since arrays start counting from index &lt;em&gt;0&lt;/em&gt;, the last item is at index &lt;em&gt;n - 1&lt;/em&gt;. To add a new item, you simply assign it to index &lt;em&gt;n&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numArray = [1, 2, 5];

const jsPush = (arr, newItem) =&amp;gt; {
  arr[arr.length] = newItem;
  return arr;
};

console.log(jsPush(numArray, 4)) ==&amp;gt; [1,2,5,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what &lt;em&gt;push()&lt;/em&gt; does under the hood. It simply places the new item at the next available index without moving items around. That's why it is O(1) (constant time). Note that native push() returns the new length (arr.length), not the array itself. &lt;/p&gt;

&lt;h4&gt;
  
  
  Array.pop()
&lt;/h4&gt;

&lt;p&gt;This array method is used when you want to remove the last item from an array. It also has a time complexity of O(1). &lt;/p&gt;

&lt;p&gt;If you have an array of length &lt;em&gt;n&lt;/em&gt;, the last item is at index &lt;em&gt;n - 1&lt;/em&gt;. To remove it, you just ignore that index and reduce the array's length by &lt;em&gt;1&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numArray = [1, 2, 5, 4];

const jsPop = (arr) =&amp;gt; {
  arr.length = arr.length - 1;
  return arr;
};

console.log(jsPop(numArray))==&amp;gt; [1,2,5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With a time complexity of O(1), constant time, this is how pop() works under the hood.&lt;/p&gt;

&lt;p&gt;Note that the length property is mutable (can be changed). So, when you set &lt;code&gt;arr.length = arr.length - 1&lt;/code&gt;, JavaScript removes any item beyond the new length. It makes the array shorter, and it drops whatever doesn’t fit. If you do the opposite and set the length to &lt;code&gt;arr.length + 1&lt;/code&gt;, JavaScript won’t complain. It just adds a space at the end of the array. To learn more about the length property, visit &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Understanding how JavaScript array methods like &lt;em&gt;push()&lt;/em&gt; and &lt;em&gt;pop()&lt;/em&gt; work under the hood helps you write better and faster code. These methods may seem simple, but knowing what’s going on behind the scenes and why some are slower than others can make a big difference, especially when working with large amounts of data.&lt;/p&gt;

&lt;p&gt;If you found this helpful, stay tuned for the next part, where we’ll break down how &lt;em&gt;shift()&lt;/em&gt;, &lt;em&gt;unshift()&lt;/em&gt;, and &lt;em&gt;splice()&lt;/em&gt; work.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>datastructures</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Bubble Sort: A JavaScript Implementation Guide</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Sun, 27 Jul 2025 11:17:44 +0000</pubDate>
      <link>https://dev.to/tochi_/bubble-sort-a-javascript-implementation-guide-1bgj</link>
      <guid>https://dev.to/tochi_/bubble-sort-a-javascript-implementation-guide-1bgj</guid>
      <description>&lt;p&gt;Imagine a puzzle game where you have six holes. Each hole holds a colored ball (red, blue or green). To win that round in the game, you have to sort the balls so that all the red ones come first, then the green ones, and finally the blue ones. But you can only compare two balls that are side by side, and if they’re not in the right order, you swap them.&lt;/p&gt;

&lt;p&gt;You go through the row of balls, checking two at a time. If they’re in the wrong order, you swap them. As you repeat this process, the balls slowly move into the right positions (red moves forward, blue shifts to the back). You continue until no more swaps are needed. That is how the bubble sort algorithm works. So, what is bubble sort?&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Bubble Sort?
&lt;/h3&gt;

&lt;p&gt;Bubble sort is a type of sorting algorithm that goes through a list of items and arranges the items on the list in the right order. It does this by comparing two items that are side by side and swapping them if they are in the wrong order.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does it work?
&lt;/h3&gt;

&lt;p&gt;Let’s say you have an unsorted array of numbers: &lt;code&gt;const array = [10, 7, 6, 1]&lt;/code&gt;. Your task is to sort this array in ascending order. Naturally, your first thought might be, "Oh, that's easy. Just use the JavaScript built-in sort method." And you'll be correct to think that. But what if, like me, you were in an interview and your interviewer asked you to sort the array without any built-in method? How would you go about it?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start at the beginning of the array and move through it one item at a time.&lt;/li&gt;
&lt;li&gt;Compare each item with the one next to it.&lt;/li&gt;
&lt;li&gt;Swap the items if the current item is greater than the next one.&lt;/li&gt;
&lt;li&gt;Repeat this process for the entire array.&lt;/li&gt;
&lt;li&gt;Continue looping through the array until no more swaps are needed and your array is fully sorted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sortArray = (numList) =&amp;gt; {
  for (let j = 0; j &amp;lt; numList.length; j++) {    
    for (let i = 0; i &amp;lt; numList.length; i++) {
      if (numList[i] &amp;gt; numList[i + 1]) {
        let temp = numList[i];
        numList[i] = numList[i + 1];
        numList[i + 1] = temp;
      }
    }
  }

  return numList;
};
//
console.log("sorted===&amp;gt;", sortArray(arr));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;const sortArray = (numList) =&amp;gt; { ... }&lt;/code&gt; defines a function called &lt;code&gt;sortArray&lt;/code&gt; that takes an array of numbers &lt;code&gt;(numList)&lt;/code&gt; and returns a sorted version of it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for (let j = 0; j &amp;lt; numList.length; j++)&lt;/code&gt; is the outer loop. It runs the same number of times as the length of the list. It loops through the entire list from start to finish. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for (let i = 0; i &amp;lt; numList.length; i++)&lt;/code&gt; is the inner loop. This is the loop that does the actual comparison. It compares the current item with the item next to it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;if (numList[i] &amp;gt; numList[i + 1])&lt;/code&gt; is a conditional statement that checks if the current number is bigger than the one next to it. If the condition is true, then we need to swap them so the bigger number moves to the right.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let temp = numList[i];&lt;/code&gt; If the conditional statement is true, then this runs. This temporarily stores the current number in a variable called &lt;code&gt;temp&lt;/code&gt;. We are storing in a variable because we're about to change &lt;code&gt;numList[i]&lt;/code&gt;, and we still need its value to complete the swap.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;numList[i] = numList[i + 1];&lt;/code&gt; moves the next number to the current spot, and this, &lt;code&gt;numList[i + 1] = temp;&lt;/code&gt; puts the original number (from temp) into the next spot.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return numList;&lt;/code&gt; returns the sorted array once all the sorting is done.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;console.log("sorted===&amp;gt;", sortArray(arr));&lt;/code&gt; prints out the sorted array in the console so we can see the result.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why Do We Use Two Loops in Bubble Sort?
&lt;/h3&gt;

&lt;p&gt;The inner loop goes through the list once and compares each number with the next one. If the number is bigger than the one next to it, it swaps them. So if it loops just once, we'll get: &lt;code&gt;[7,10,6,1] → [7,6,10,1] → [7,6,1,10] → [7,6,1,10]&lt;/code&gt;. This is why the outer loop is needed. The outer loop tells your code: “Go through the list again... and again...” until everything is sorted. It does this &lt;em&gt;n-1&lt;/em&gt; times, where &lt;em&gt;n&lt;/em&gt; is the length of the array.&lt;/p&gt;

&lt;p&gt;Here is a step-by-step breakdown of what happens. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1st time (outer loop index = 0)&lt;/strong&gt;: The inner loop runs and pushes the biggest number (10) to the end. The result is &lt;code&gt;[7,10,6,1] → [7,6,10,1] → [7,6,1,10] → [7,6,1,10]&lt;/code&gt;. After this round, 10 is in the correct place.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2nd time (outer loop index = 1)&lt;/strong&gt;: Now the second-biggest number (7) gets pushed toward its correct place. &lt;code&gt;[7,6,1,10] → [6,7,1,10] → [6,1,7,10] → [6,1,7,10]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3rd time (outer loop index = 2)&lt;/strong&gt;: The smallest numbers (6 and 1) are still in the wrong spots. This time, they get moved into place. &lt;code&gt;[6,1,7,10] → [1,6,7,10] → [1,6,7,10] → [1,6,7,10]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;4th time (outer loop index = 3)&lt;/strong&gt;: Now everything is sorted. Even though nothing changes, the loop still runs just to check.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So why do we need the outer loop? Because just looping once is not enough. You need to keep looping until all numbers are in the right place. Without the outer loop, only the largest number will be in place. The rest will still be scrambled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion.
&lt;/h3&gt;

&lt;p&gt;Bubble sort is one of the simplest JavaScript sorting algorithms to understand and use. However, bubble sort is not the fastest option, especially for large lists. It has a time complexity of &lt;em&gt;O(n^2)&lt;/em&gt;, which means it has a quadratic time complexity. This means the time it takes to finish grows quickly as the list gets longer. It also has a space complexity of &lt;em&gt;O(1)&lt;/em&gt;, which means it has a constant space complexity. It means it doesn’t need any extra memory to do the sorting. So while bubble sort is great for learning how sorting works, it’s also not the best choice for real-world applications where performance matters.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>datastructures</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Challenge Accepted- A Runner H-Powered Makeover.</title>
      <dc:creator>Tochi</dc:creator>
      <pubDate>Mon, 16 Jun 2025 08:42:50 +0000</pubDate>
      <link>https://dev.to/tochi_/challenge-accepted-a-runner-h-powered-makeover-394b</link>
      <guid>https://dev.to/tochi_/challenge-accepted-a-runner-h-powered-makeover-394b</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/runnerh"&gt;Runner H "AI Agent Prompting" Challenge&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I wanted honest feedback on a game I’ve been working on with my team at work — Muzingo, a browser-based music bingo game. It's fun, casual, and made for music lovers. But like most builders, we started wondering: Is this enough? What’s missing? How do we grow this?&lt;/p&gt;

&lt;p&gt;Instead of guessing, I asked Runner H.&lt;/p&gt;

&lt;p&gt;I gave it one job: &lt;em&gt;Act like a Product &amp;amp; Growth Consultant&lt;/em&gt;. Explore the game, find weak spots, and then tear apart our social presence with love.&lt;/p&gt;

&lt;p&gt;The result? A structured audit with product fixes, growth tactics, and social media gold in one document. It returned a response in minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Run link&lt;/strong&gt;: &lt;a href="https://runner.hcompany.ai/chat/a078f4ca-7051-4e2a-bd01-9d6dbc674518/share" rel="noopener noreferrer"&gt;Runner H Audit Run&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Document&lt;/strong&gt;: &lt;a href="https://docs.google.com/document/d/1rL8zzPFSLRWYeWNTuBg0aeSmHj5MkdU2WcpXuuQ7rkc/edit" rel="noopener noreferrer"&gt;PlayMuzingo Product &amp;amp; Social Audit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Used Runner H
&lt;/h2&gt;

&lt;p&gt;Here’s how the workflow went:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;I set the scene: You’re a product and growth consultant for web-based games.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gave it my URL: &lt;a href="https://playmuzingo.com" rel="noopener noreferrer"&gt;https://playmuzingo.com&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Asked it to:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Explore the game and suggest UX and feature improvements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Audit our social media strategy across platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Share clear, actionable growth tactics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Come up with ideas to boost word-of-mouth and repeat play.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Runner H responded and broke things into four key sections:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Product Suggestions&lt;/strong&gt;: It found onboarding gaps, suggested personalised playlists, and proposed multiplayer modes, seasonal events, and better graphics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Social Strategy&lt;/strong&gt;: It offered UGC campaigns, content hooks for music fans, and a strong posting plan using TikTok and Instagram.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Growth Tactics&lt;/strong&gt;: From music influencer outreach to SEO, newsletters, and referral systems — every tactic felt fresh yet doable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Word-of-Mouth Boost&lt;/strong&gt;: Community contests and social sharing features made the list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of this got wrapped up in a Google Doc, ready for execution.&lt;/p&gt;

&lt;h4&gt;
  
  
  My Prompt
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a Product &amp;amp; Growth Consultant for web-based games. Your task is to audit the product and social presence of https://playmuzingo.com— a browser-based music bingo game. You must:

**Product Audit**

- Visit the PlayMuzingo landing page and explore the game.
- Identify any unclear UX flows, missing information, or areas where onboarding could be improved.
- Suggest 10+ new features or tweaks that would improve the user experience or replay value.

**Social Media Strategy**

- Research PlayMuzingo’s current social presence (start with playmuzingo,muzingo or search for mentions).
- Suggest 10+ improvements to the posting strategy. Consider:
- What types of posts will drive shares?
- How can we spark challenges or virality?
- What are good hooks for music fans?
- Recommend 10 high-converting content ideas (tweets, IG Reels, TikToks, etc.) and when/how to post them.

**Growth &amp;amp; Marketing Boost**

- What can marketers and community leads do to attract and retain users better?
- Suggest collaboration, influencer, or UGC strategies to scale awareness fast.

Bonus: Suggest 3 ways to boost word-of-mouth and repeat play.

At the end, compile all findings into a clear, Google Doc with actionable insights split into:

- Product Suggestions
- Social Media Strategy
- Growth Tactics
Generate well-detailed docs. Including execution plans and how to go about everything. Arrange it all in sections and each idea should be explained deeply.

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Case &amp;amp; Impact
&lt;/h2&gt;

&lt;p&gt;If you're building a product and wondering “What next?”, this is the answer.&lt;/p&gt;

&lt;p&gt;Runner H saved me hours of analysis. I didn’t have to scroll through Reddit, second-guess my UX, or overthink marketing posts.&lt;/p&gt;

&lt;p&gt;It gave me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A roadmap of features that could boost replay value.&lt;/li&gt;
&lt;li&gt;A content calendar for TikTok, IG, and more.&lt;/li&gt;
&lt;li&gt;A growth strategy tailored to music and games.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're solo, part of a small team, or running a startup, this is like hiring a strategist who delivers instantly.&lt;/p&gt;

&lt;p&gt;Now I know exactly what to build next. And more importantly, how to get people to care about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Social Love
&lt;/h3&gt;

&lt;p&gt;If you’re a builder, then you should try this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One prompt = full audit&lt;/li&gt;
&lt;li&gt;Real ideas, not fluff&lt;/li&gt;
&lt;li&gt;Run your audit with Runner H&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, play our game at &lt;a href="https://playmuzingo.com/" rel="noopener noreferrer"&gt;playmuzingo.com&lt;/a&gt;. My team and I would appreciate any feedback we can get.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>runnerhchallenge</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
