<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hector Williams</title>
    <description>The latest articles on Forem by Hector Williams (@hectorw_tt).</description>
    <link>https://forem.com/hectorw_tt</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%2F1278449%2F92c080fc-4f97-4860-ba4c-c8e055d0b8ee.jpg</url>
      <title>Forem: Hector Williams</title>
      <link>https://forem.com/hectorw_tt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hectorw_tt"/>
    <language>en</language>
    <item>
      <title>960. Delete Columns to Make Sorted III</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 01 Apr 2026 15:31:29 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/960-delete-columns-to-make-sorted-iii-1272</link>
      <guid>https://forem.com/hectorw_tt/960-delete-columns-to-make-sorted-iii-1272</guid>
      <description>&lt;p&gt;&lt;em&gt;In the last &lt;a href="./300-longest-increasing-subsequence-2bmn"&gt;post&lt;/a&gt;, I discussed how recognizing patterns is important in solving coding challenges and discussed the Longest Increasing Subsequence. I shall talk about applying the basics in this problem to solve one variation of LIS. Follow me here, on Twitter, LinkedIn or Github for more.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;br&gt;
You are given an array of n strings strs, all of the same length.&lt;/p&gt;

&lt;p&gt;We may choose any deletion indices, and we delete all the characters in those indices for each string.&lt;/p&gt;

&lt;p&gt;For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].&lt;/p&gt;

&lt;p&gt;Suppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. (i.e., (strs[0][0] &amp;lt;= strs[0][1] &amp;lt;= ... &amp;lt;= strs[0][strs[0].length - 1]), and (strs[1][0] &amp;lt;= strs[1][1] &amp;lt;= ... &amp;lt;= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.&lt;/p&gt;

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

&lt;p&gt;Input: strs = ["babca","bbazb"]&lt;br&gt;
Output: 3&lt;br&gt;
Explanation: After deleting columns 0, 1, and 4, the final array is strs = ["bc", "az"].&lt;br&gt;
Both these rows are individually in lexicographic order (ie. strs[0][0] &amp;lt;= strs[0][1] and strs[1][0] &amp;lt;= strs[1][1]).&lt;br&gt;
Note that strs[0] &amp;gt; strs[1] - the array strs is not necessarily in lexicographic order.&lt;br&gt;
Example 2:&lt;/p&gt;

&lt;p&gt;Input: strs = ["edcba"]&lt;br&gt;
Output: 4&lt;br&gt;
Explanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.&lt;br&gt;
Example 3:&lt;/p&gt;

&lt;p&gt;Input: strs = ["ghi","def","abc"]&lt;br&gt;
Output: 0&lt;br&gt;
Explanation: All rows are already lexicographically sorted.&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;n == strs.length&lt;br&gt;
1 &amp;lt;= n &amp;lt;= 100&lt;br&gt;
1 &amp;lt;= strs[i].length &amp;lt;= 100&lt;br&gt;
strs[i] consists of lowercase English letters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We apply the same principle in LIS with the double for loops.The only difference is we check all the characters in one column are less than or equal to all the characters in the other. We do this as we are trying to maximize the number of columns to be deleted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;minDeletionSize&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;      
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;          
     &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;       
      &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
         &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;charAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;   
         &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;charAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;  
         &lt;span class="o"&gt;}&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;]&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;]+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;          
        &lt;span class="o"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;  
     &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt; 
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C#&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;MinDeletionSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;          
     &lt;span class="n"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;++){&lt;/span&gt;       
      &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;++){&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++){&lt;/span&gt;
         &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;   
         &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="p"&gt;++;&lt;/span&gt;  
         &lt;span class="p"&gt;}&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="p"&gt;==&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;]&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;]=&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;  
     &lt;span class="n"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;    
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C++&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;minDeletionSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;      
     &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;       
      &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
         &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  
         &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;   
         &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
         &lt;span class="p"&gt;}&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numOfRows&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="n"&gt;strs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;  
     &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;    
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>300. Longest Increasing Subsequence</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 18 Mar 2026 18:02:33 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/300-longest-increasing-subsequence-2bmn</link>
      <guid>https://forem.com/hectorw_tt/300-longest-increasing-subsequence-2bmn</guid>
      <description>&lt;p&gt;&lt;em&gt;A good way to master coding challenges is to recognize patterns. A good way to recognize patterns is to understand the basics. This may involve understanding one core problem and learning to apply it. Think of it as similar to learning to crawl before learning to walk and then learning to run. An example core problem is the Longest Increasing Subsequence. Variations of this problem are frequently asked. Follow me here, on Twitter, LinkedIn or Github for more.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given an integer array nums, return the length of the longest strictly increasing subsequence.&lt;/p&gt;

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

&lt;p&gt;Input: nums = [10,9,2,5,3,7,101,18]&lt;br&gt;
Output: 4&lt;br&gt;
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.&lt;br&gt;
Example 2:&lt;/p&gt;

&lt;p&gt;Input: nums = [0,1,0,3,2,3]&lt;br&gt;
Output: 4&lt;br&gt;
Example 3:&lt;/p&gt;

&lt;p&gt;Input: nums = [7,7,7,7,7,7,7]&lt;br&gt;
Output: 1&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;1 &amp;lt;= nums.length &amp;lt;= 2500&lt;br&gt;
-104 &amp;lt;= nums[i] &amp;lt;= 104&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To solve, we use &lt;em&gt;dynamic programming&lt;/em&gt;. We build a 1-dimensional array &lt;em&gt;lengths&lt;/em&gt; to store the maximum length of the subsequences at each index and initialize it so that each value is 1. &lt;br&gt;
 Then we use two for loops. The first starts at the second index (index 1 in some programming languages) and iterates forward until the end of the array. We shall refer to it as &lt;em&gt;i&lt;/em&gt; .&lt;br&gt;
 The second starts at the first index (index 0 in some languages) and iterates forward until it reaches &lt;em&gt;i&lt;/em&gt;. We shall refer to it as &lt;em&gt;j&lt;/em&gt;. If the number found at &lt;em&gt;j&lt;/em&gt; is less than that found at &lt;em&gt;i&lt;/em&gt; and &lt;em&gt;lengths[i]&lt;/em&gt; is less than or equal to &lt;em&gt;lengths[j]&lt;/em&gt;, we recalculate the value at &lt;em&gt;lengths[i]&lt;/em&gt; as &lt;em&gt;lengths[i]=lengths[j]+1&lt;/em&gt;.&lt;br&gt;
 On finishing the double for loop,we sort &lt;em&gt;lengths&lt;/em&gt; and return the last value which is the largest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;lengthOfLIS&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
       &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;]&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;]+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
     &lt;span class="o"&gt;}&lt;/span&gt;
     &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;C#&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;LengthOfLIS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++)&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++){&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;++){&lt;/span&gt;
       &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]=&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;++)&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;C++&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;lengthOfLIS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
       &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Javascript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;lengthOfLIS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>A practical guide to creating software applications regardless of programming language</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 04 Mar 2026 15:52:58 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/a-practical-guide-to-creating-software-applications-regardless-of-programming-language-54n3</link>
      <guid>https://forem.com/hectorw_tt/a-practical-guide-to-creating-software-applications-regardless-of-programming-language-54n3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Software engineering can be a lucrative, fulfilling career. The world runs on a variety of software applications, whether desktop, mobile or web. There are a lot of university degrees, courses and boot camps that teach the concepts of computer science, software engineering and different programming languages.&lt;br&gt;
 However, what is lacking and is needed is a guide to create software applications regardless of technology stacks and if the software is a mobile, desktop or web application. I attempt to provide such a guide below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Software Engineering Process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The process of building software can be divided into 6 steps: &lt;em&gt;requirements gathering, designing the system, implementation of the system, testing, deployment and maintenance&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements Gathering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step involves gathering the end-user requirements of the software to be designed. This step is necessary as without it, we can't design software that meets the end user's hopes and solves their problems.&lt;br&gt;
 This step involves communicating with the end user in an attempt to understand what problem they would like to solve. As end users may not be technical, steps should be taken to understand their points of view.&lt;br&gt;
 Once this is done, we can build a list of the end user requirements for the software to be designed. From this, we can get technical requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Designing the system&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The second step is designing the system so that it matches the user and technical requirements. This will involve making a tradeoff analysis of the benefits and drawbacks of various technologies and choosing the appropriate ones.&lt;br&gt;
 At the end of this step, we should know what programming languages, databases, operating systems and hardware we will be using and the architecture of the software. We should also have a list of modules that should comprimise the software.&lt;br&gt;
 We can then create a test environment to build the software and a production environment to deploy it once it is ready for the end users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the choice of technologies is made, the next step will involve the writing of the code in the programming languages and creation of the databases along with the creation of the user interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the code has been written it needs to be tested to ensure that it meets the technical and end user requirements. This can involve both &lt;em&gt;user&lt;/em&gt; and &lt;em&gt;integration&lt;/em&gt; &lt;em&gt;testing&lt;/em&gt;. User testing ensures that all the modules work whilst integration testing is needed to ensure that the entire system works.&lt;br&gt;
 If all the necessary tests don't work, the programmer(s) will need to debug their code to ensure that it does. The testing can be done manually or using frameworks such as JUnit. It may also involve code reviews.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deployment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After testing has been concluded, the software is deployed to the production environment. The end users are invited to use the system. If all goes well, the system is "live". If not, the programmers need to fix the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Maintenance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Over time, the user requirements may change, bugs may be discovered or new features may need to be added. The previous 5 steps will need to be done to make the changes. The changes need to be done in a manner so that the existing software's functionality isn't broken.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Considerations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These are the considerations that need to be taken.&lt;/p&gt;

&lt;p&gt;1) All steps should be documented for references in the future by different programmers.&lt;/p&gt;

&lt;p&gt;2)The end users should be involved in all but the design and implementation stages.&lt;/p&gt;

&lt;p&gt;3)User interfaces should be easy to use.&lt;/p&gt;

&lt;p&gt;4) The code should be optimized for speed and space requirements and should be easy to change. They should also be written with scalability in mind.&lt;/p&gt;

&lt;p&gt;5) Security should be a major consideration from start to finish.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have given the list of steps to be taken to design a software application. These steps will work regardless of programming languages, databases, operating systems and whether the system is a mobile, desktop or web application. Please leave your opinions below.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
      <category>software</category>
    </item>
    <item>
      <title>LeetCode #1458.Max Dot Product of Two Subsequences</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 04 Feb 2026 17:31:45 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/leetcode-1458max-dot-product-of-two-subsequences-56lb</link>
      <guid>https://forem.com/hectorw_tt/leetcode-1458max-dot-product-of-two-subsequences-56lb</guid>
      <description>&lt;p&gt;&lt;em&gt;Many engineers find leetcode problems hard and not a reflection of the actual work to do. I do have some sympathy for this view. Nonetheless, I do think that these questions can help practice and build programming skills. Due to this and the fact that these prop up in interviews, I will post discussions of these from time to time.Follow me on twitter,github or Linkedin for these and more.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given two arrays nums1 and nums2.&lt;/p&gt;

&lt;p&gt;Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.&lt;/p&gt;

&lt;p&gt;A subsequence of an array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, [2,3,5] is a subsequence of [1,2,3,4,5] while [1,5,3] is not).&lt;/p&gt;

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

&lt;p&gt;Input: nums1 = [2,1,-2,5], nums2 = [3,0,-6]&lt;br&gt;
Output: 18&lt;br&gt;
Explanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.&lt;br&gt;
Their dot product is (2*3 + (-2)*(-6)) = 18.&lt;br&gt;
Example 2:&lt;/p&gt;

&lt;p&gt;Input: nums1 = [3,-2], nums2 = [2,-6,7]&lt;br&gt;
Output: 21&lt;br&gt;
Explanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.&lt;br&gt;
Their dot product is (3*7) = 21.&lt;br&gt;
Example 3:&lt;/p&gt;

&lt;p&gt;Input: nums1 = [-1,-1], nums2 = [1,1]&lt;br&gt;
Output: -1&lt;br&gt;
Explanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.&lt;br&gt;
Their dot product is -1.&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;1 &amp;lt;= nums1.length, nums2.length &amp;lt;= 500&lt;br&gt;
-1000 &amp;lt;= nums1[i], nums2[i] &amp;lt;= 1000&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discussion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was stumped by this question. I read the hints and somebody mentioned that it was similar to Longest Common Subsequence. That got me thinking. I had to use a 2-D dp array to get the result. &lt;/p&gt;

&lt;p&gt;I also had to keep track of the multiplication of each number from each array along with the values from the previous row,current column and the previous column and current row.For edge cases I had to calculate the values for the first row and the first column.I came up with the solution below which passed all 70 cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int maxDotProduct(int[] nums1, int[] nums2) {
     int  [] [] dp=new int[nums1.length] [nums2.length];   
     int firstRowMax=nums1[0]*nums2[0];
     int answer=0;
     dp[0][0]=firstRowMax;
     for(int j=1;j&amp;lt;nums2.length;j++){
      int current=nums1[0]*nums2[j];
      firstRowMax=Math.max(firstRowMax,current);
      dp[0][j]=firstRowMax;
     }
     answer=firstRowMax;
     for(int i=1;i&amp;lt;nums1.length;i++){
      for(int j=0;j&amp;lt;nums2.length;j++){
        int current=nums1[i]*nums2[j];
        if(j==0) dp[i][j]=Math.max(dp[i-1][j],current);   
        else
         dp[i][j]=Math.max(dp[i-1][j-1]+current,Math.max(current,Math.max(dp[i-1][j],dp[i][j-1])));
        answer=Math.max(answer,dp[i][j]);
      }  
     }
     return answer;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>competativeprogramming</category>
    </item>
    <item>
      <title>Why Programs Fail A Guide to Systematic Debugging by Andreas Zeller-A Book Review</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 21 Jan 2026 20:00:47 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/why-programs-fail-a-guide-to-systematic-debugging-by-andreas-zeller-a-book-review-24h8</link>
      <guid>https://forem.com/hectorw_tt/why-programs-fail-a-guide-to-systematic-debugging-by-andreas-zeller-a-book-review-24h8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
  A while back, I was given a list of books to read in order to become a world class software engineer. I have done previous reviews &lt;a href="./"&gt;here&lt;/a&gt;. One of these books is &lt;em&gt;Why Programs Fail A Guide to Systematic Debugging&lt;/em&gt; by Andreas Zeller.&lt;/p&gt;

&lt;p&gt;As experienced engineers may know debugging is an important aspect of our jobs. In complex codebases, this may form the majority of our work. Unfortunately, it isn't something that is usually taught in degrees and bootcamps and we must learn it through practical experience whilst on the job.&lt;/p&gt;

&lt;p&gt;This book helps to ease our task by introducing us to techniques used in debugging. The book is divided into 15 chapters. Each chapter is divided into 5 sections.&lt;/p&gt;

&lt;p&gt;The first section discusses the title of the chapter in detail, the second the core concepts that software engineers should take, the third the tools to use, the fourth points to what we can also read and the final is a number of exercises to do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Do Bugs Arise?&lt;/strong&gt;&lt;br&gt;
 In my experience, bugs are usually caused by incorrect assumptions about the code. Due to programmers being under tight deadlines, bugs are usually discovered by end users. They can usually be very costly. The author discusses this briefly at the end of chapter 1.&lt;/p&gt;

&lt;p&gt;The first chapter discusses how failures in software arise. The author thinks it takes place in 3 stages:&lt;br&gt;
 i) The programmer creates a &lt;em&gt;defect&lt;/em&gt; in the programming code.&lt;br&gt;
 ii) The defect causes an &lt;em&gt;infection&lt;/em&gt; in the programming state&lt;br&gt;
 iii) The infection causes a &lt;em&gt;failure&lt;/em&gt;-an externally observable failure. &lt;/p&gt;

&lt;p&gt;The author lists a series of steps with the acronym TRAFFIC to debug a program.&lt;br&gt;
 i) &lt;em&gt;Track&lt;/em&gt;: Create a problem in the programming database. In the second chapter, the author discusses how to keep track of the problems.&lt;br&gt;
 ii) &lt;em&gt;Reproduce&lt;/em&gt;: Reproduce the failure.This is discussed in chapter 4.&lt;br&gt;
 iii) &lt;em&gt;Automate&lt;/em&gt;: Automate and simplify the test case.&lt;br&gt;
 iv) &lt;em&gt;Find Origins&lt;/em&gt;: Follow back the dependencies from the failure to possible infection origins.&lt;br&gt;
 v) &lt;em&gt;Focus&lt;/em&gt;&lt;br&gt;
 vi) &lt;em&gt;Isolate&lt;/em&gt;: Use the scientific method (see Chapter 6) to isolate the origin of the infection. Continue isolating origins transitively until you have an infection chain from defect to failure.&lt;br&gt;
vii) &lt;em&gt;Correct&lt;/em&gt;: Remove the defect and verify the success of your fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to fix bugs?&lt;/strong&gt;&lt;br&gt;
  As experienced developers know, there can be a number of issues that may arise when fixing a bug. First, we need to know whether the issue is truly fixed. To do this we may a correct understanding of the problem (the problem database mentioned above). Secondly, we need to also ensure that the fix doesn't cause any more problems.&lt;/p&gt;

&lt;p&gt;My approach to debugging which has been gathered from working on different codebases over the years is to understand the problem, read the codebase, understand the workflow using logging statements, make the fix and adapt so that nothing else is broken, verify that the fix works using unit and integration testing and verify that nothing else has been broken running previous unit and integration tests.&lt;/p&gt;

&lt;p&gt;Whilst this does work, it can be time consuming. The author makes a series of recommendations throughout the book that involves both tools and techniques to make the process more efficient.&lt;/p&gt;

&lt;p&gt;The tools he suggests are debuggers and one of the techniques is an adaptation of the scientific method in a process known as &lt;em&gt;scientific debugging&lt;/em&gt;.&lt;br&gt;
 The steps in this method are&lt;br&gt;
i) &lt;em&gt;Observe&lt;/em&gt; a failure.&lt;br&gt;
ii) Invent a &lt;em&gt;hypothesis&lt;/em&gt; as to the failure cause that is consistent with the observations.&lt;br&gt;
iii)Use the hypothesis to make &lt;em&gt;predictions&lt;/em&gt;.&lt;br&gt;
iv)Test the hypothesis by &lt;em&gt;experiments&lt;/em&gt; and further observations.&lt;br&gt;
v) Repeat steps 3 and 4 until the hypothesis can no longer be refined.&lt;/p&gt;

&lt;p&gt;Applying the scientific debugging should help the programmer to find the issue. The author spends a number of chapters discussing in detail how to do so. Once this is done, we must fix the problem. The author discusses in chapter 15.&lt;/p&gt;

&lt;p&gt;As I mentioned above, we need to verify the fix resolves the problem and that it doesn't cause new problems. Other &lt;a href="./a-book-review-of-working-effectively-with-legacy-code-by-michael-feathers-5c47"&gt;books&lt;/a&gt; discuss how to do this. Experienced engineers should recognize that testing will help with both. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
  This is a valuable, practical book. It is well organized and the summaries at the end of each chapter make it easy for programmers to refer to if they should forget or to get summaries of the main deductions. I recommend this book for all software engineers from novices to seniors.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>learning</category>
      <category>books</category>
    </item>
    <item>
      <title>A Book Review of Working Effectively With Legacy Code by Michael Feathers</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 07 Jan 2026 15:42:32 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/a-book-review-of-working-effectively-with-legacy-code-by-michael-feathers-5c47</link>
      <guid>https://forem.com/hectorw_tt/a-book-review-of-working-effectively-with-legacy-code-by-michael-feathers-5c47</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A large part of software engineering involves not only designing and creating new programs, but also working with existing codebases. Due to a number of reasons, we may need to make changes to the codebase. &lt;br&gt;
 There are codebases where changes lead to an increasing number of problems. This is often referred to as legacy code, which the author defines as codebases without tests. The book &lt;em&gt;Working Effectively With Legacy Code&lt;/em&gt; discusses how to work with such codebases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Changes in the system can lead to a disruption in the existing functionality of the system. Why then do we need to make changes to the existing system? The book gives 4 reasons.&lt;br&gt;
  1.Adding a feature&lt;br&gt;
  2.Fixing a bug&lt;br&gt;
  3.Improving the design&lt;br&gt;
  4.Optimizing resource usage &lt;/p&gt;

&lt;p&gt;The challenge when making these changes is to preserve the existing functionality of the system. Preserving the behavior involves some risk. This is because the codebase may have a lot of entanglements and the code to be changed may have some dependencies. Thus changes may result in unwanted changes.&lt;/p&gt;

&lt;p&gt;According to the book to mitigate risk, we have to ask 3 questions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What changes do we have to make?&lt;/li&gt;
&lt;li&gt;How will we know that we've done them correctly?&lt;/li&gt;
&lt;li&gt;How will we know that we haven't broken anything?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Writing tests can help us with the process of mitigating risks as we know what works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
 To solve the problem described above, the author suggests a &lt;em&gt;legacy code change&lt;/em&gt; algorithm of 5 steps. These are:&lt;/p&gt;

&lt;p&gt;1.Identify change points&lt;br&gt;
2.Identify test points&lt;br&gt;
3.Break dependencies&lt;br&gt;
4.Write tests&lt;br&gt;
5.Make changes and refactor &lt;/p&gt;

&lt;p&gt;The rest of the book contains lots of details on how to execute the steps above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
 In a nutshell, the way to deal with legacy codebases is to introduce tests that allow us to understand how the system works,to map out dependencies and where possible break them.The book has lots of details on doing this.&lt;br&gt;
 This is a useful and practical book that discusses how to deal with legacy codebases that are too often prevalent in the real world. I recommend this book for experienced and advanced engineers.&lt;br&gt;
 The advice given can be useful regardless of the programming languages used.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>learning</category>
      <category>books</category>
    </item>
    <item>
      <title>A Book Review of A Philosophy of Software Design-how to create software that is easy to maintain</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 19 Nov 2025 18:16:48 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/a-book-review-of-a-philosophy-of-software-design-how-to-create-software-that-is-easy-to-maintain-d7n</link>
      <guid>https://forem.com/hectorw_tt/a-book-review-of-a-philosophy-of-software-design-how-to-create-software-that-is-easy-to-maintain-d7n</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A while back I was given a list of books to read in order to become a world class software engineer.One of these books was &lt;em&gt;A Philosophy of Software Design&lt;/em&gt; by John Ousterhout. As the title implies, this book describes a way to design software. I would add how to design software that is easy to maintain.&lt;/p&gt;

&lt;p&gt;As experienced engineers know, software engineering isn't just about creating software. User requirements may change in the future and new features may need to be added,bugs may be discovered in the existing functionality or changes in the existing codebase to make the code more efficient may be needed.&lt;/p&gt;

&lt;p&gt;However, changing the existing codebase to incorporate these changes may interrupt existing functionality. This usually occurs because the code written was complex in the first place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complexity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The book describes two reasons for complexity:&lt;em&gt;dependencies&lt;/em&gt;  and &lt;em&gt;obscurity&lt;/em&gt;. Dependency arises when one piece of code can't be changed without affecting others.Obscurity happens when important information isnt obvious.&lt;/p&gt;

&lt;p&gt;The author also describes 3 symptoms of complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Change Amplifications&lt;/strong&gt;&lt;br&gt;
  A simple modification requires a lot of changes due to the fact that there are a lot of dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Cognitive Load&lt;/strong&gt;&lt;br&gt;
 The developer needs to understand a lot of the codebase to make it easy to understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Unknown unknowns&lt;/strong&gt;&lt;br&gt;
  It isn't obvious what pieces of code must be modified to complete a task or what information a developer must have to carry out the task successfully.In the author's opinion,this is the worst of the 3.&lt;/p&gt;

&lt;p&gt;The author's proposed solution to eliminate or reduce code complexity is to make the code obvious. The book lists a number of ways that this can be done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Programming Mindset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Software engineers are often in a rush to meet tight deadlines. As a result, they focus on writing code which works without thinking about the future. The author labels this as &lt;em&gt;tactical programming&lt;/em&gt; and advises against it as due to its short sighted nature,it can lead to increases in the complexity of the code.&lt;/p&gt;

&lt;p&gt;Instead the author recommends thinking with a &lt;em&gt;strategic programming&lt;/em&gt; mindset. Here, developers must try not to introduce unnecessary complexity in the system. The focus must be on improving the design of the system where possible thus making it easier for other programmers to work in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modular Design&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A technique the author recommends to reduce complexity is to use modules.This ensures that developers face a fraction of the system's overall completixy.The author advises to use &lt;em&gt;deep modules&lt;/em&gt;-systems with a simple interface but a lot of complexity and advises against &lt;em&gt;shallow modules&lt;/em&gt;-systems with a complex interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Information Hiding and Leakage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One way of creating deep modules is to use a technique known as &lt;em&gt;information hiding&lt;/em&gt;. It involves providing other modules and users with a simple interface whilst hiding the implementation. People familiar with object oriented programming may know this as encapsulation.&lt;/p&gt;

&lt;p&gt;In contrast, the author recommends against &lt;em&gt;information leakage&lt;/em&gt;. This involves sharing of critical design information in multiple modules.This is a violation of the &lt;em&gt;Dont Repeat Yourself&lt;/em&gt; principle of software engineering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General purpose vs Special purpose Modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another approach the author proposes to reduce complexity is to use modules that are &lt;em&gt;somewhat general purpose&lt;/em&gt; rather than &lt;em&gt;special purpose&lt;/em&gt;. The former modules can cover a lot of use cases whilst the latter covers special cases. The difficulty is of course knowing what problems a module may solve today versus tomorrow.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exception Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The author gives some advice that is controversial which is &lt;em&gt;to define errors out of existence&lt;/em&gt;. This is because exceptions and errors may increase the code needed to deal with them and thus their complexity. However, this may not be always practical. I would say to minimize the errors you are dealing with where necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The author makes another recommendation that is controversial. For those of us familiar with the book Clean Code by Uncle Bob, we were advised there to avoid comments where unnecessary. The author takes the opposite approach and recommends using comments as part of the system's design. We should start with comments.&lt;/p&gt;

&lt;p&gt;He gives the reasons people give for not using comments and a reply as to why you should. He does raise some valid points. My recommendation having read both schools of thought is to use comments to explain design decisions and where the code may not be obvious. This should decrease the cognitive load.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage of Proper Names in Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The author recommends the use of variable names that are easy to understand, consistent and that create the right image in the minds of developers. This is one of the clean code guidelines recommended by Uncle Bob.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The author recommends the use of consistency in naming, coding styles, interfaces, design patterns and invariants. This should reduce the cognitive load on developers. Those of us familiar with working on complex codebases will appreciate how much consistency helps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Optimization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As experienced engineers know, the speed and memory usage of software is important when designing and implementing software. The author agrees but he does not think that this should come at the expense of increased code complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;The book argues that software design is an important part of the software engineering process. Designs where the code is obvious will make future work on that codebase easier. In contrast, code that is complex increases future work and makes bugs likelier.&lt;/p&gt;

&lt;p&gt;This is something I agree with. Some of the recommendations are a bit controversial. You should look at the pros and cons of the error handling and comments advice before deciding.&lt;/p&gt;

&lt;p&gt;The ideas put forward in this book are clear and practical. The book is short along with the chapters. In conclusion, I recommend this book for all software engineers.Which of Ousterhout’s design principles do you think is hardest to apply in your codebase, and why?&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>learning</category>
      <category>books</category>
    </item>
    <item>
      <title>Designing Data-Intensive Applications [Book Review]-The Big Ideas Behind Reliable, Scalable and Maintainable Systems</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 05 Nov 2025 16:11:35 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/designing-data-intensive-applications-book-review-the-big-ideas-behind-reliable-scalable-and-298m</link>
      <guid>https://forem.com/hectorw_tt/designing-data-intensive-applications-book-review-the-big-ideas-behind-reliable-scalable-and-298m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most backend developers eventually reach a point where they realize: learning another framework won’t meaningfully move them up to senior level. You can know Spring, Quarkus, Node, Nest, Django, whatever – and still not actually understand the deeper architectural forces that make large scale systems reliable.&lt;/p&gt;

&lt;p&gt;That’s where “Designing Data-Intensive Applications” (DDIA) hits like a hammer.&lt;/p&gt;

&lt;p&gt;This book doesn’t care about trends or hype. It forces you to understand the realities behind storage engines, distributed systems, data pipelines, fault tolerance, replication, consistency, and durability. And when you get this – you start thinking like a system designer, not just a code implementer.&lt;/p&gt;

&lt;p&gt;This is a review, but also a recommendation: if you want to level up from mid-level to senior backend, this book should be on your “mandatory” list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why I read this Book&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I follow many software engineers on LinkedIn and Twitter. One of them gave a list of books that I would need to become a world class engineer. This book was on that list. As the title suggests this book is about designing applications that process huge amounts of data-possibly limitless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The single biggest value of the book&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DDIA teaches you that modern backend engineering is less about functions and classes… and more about data flow and correctness across failure conditions. It is about building systems that can be reliable under any conditions, that are maintainable and easy to change and that can handle large amounts of data easily.&lt;br&gt;
Most production systems are not CPU-bound.&lt;/p&gt;

&lt;p&gt;They are data-bound.&lt;/p&gt;

&lt;p&gt;Data movement.&lt;br&gt;
Data reliability.&lt;br&gt;
Data transformations.&lt;br&gt;
Data structure evolution over time.&lt;/p&gt;

&lt;p&gt;This book explains how real world systems survive reality: partial failures, retries, network partitions, schema drift, state synchronization, and replayability.&lt;/p&gt;

&lt;p&gt;It gives you the mental model to see why large systems behave the way they do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topics Covered&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The book is divided into 3 parts. Part I is titled &lt;em&gt;Foundations of Data Systems&lt;/em&gt;. It is composed of 4 chapters. Chapter 1 introduces the concepts of reliability, scalability and maintainability. Chapter 2 discusses data models and compares relational and non relational databases. Chapter 3 discusses briefly the internals of databases. Chapter 4 discusses encoding data. &lt;br&gt;
 Part II is titled &lt;em&gt;Distributed data&lt;/em&gt; and is divided into 5 chapters. Chapter 5 discusses Replication of databases across distributed systems and the issues involved. Chapter 6 discusses partitioning databases across distributed systems and the problems involved. Chapter 7 discusses the concept of transactions in databases. Chapter 8 discusses the problems encountered with distributed systems and chapter 9 discusses consistency and consensus.&lt;br&gt;
 Part III is titled &lt;em&gt;Derived Data&lt;/em&gt; is divided into 3 chapters. Chapter 10 discusses batch processing, Chapter 11 discusses stream processing and Chapter 12 discusses the future of data systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5 concepts from DDIA that permanently improved how I think&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Immutable logs create sanity and replayability.&lt;/strong&gt;&lt;br&gt;
Append-only logs aren’t just a Kafka pattern – they are a way to make systems auditable, recoverable, and debuggable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Consistency is not binary.&lt;/strong&gt;&lt;br&gt;
There isn’t just “strong vs eventual”. There are reliability tradeoffs you choose. Most developers never consciously choose their consistency model. Seniors do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Protocols matter more than frameworks.&lt;/strong&gt;&lt;br&gt;
When systems break across nodes or services, the protocol is what saves you. APIs are not just endpoints. They are agreements. Durable ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Batch vs stream is a philosophical divide.&lt;/strong&gt;&lt;br&gt;
Batch is a snapshot of the past. Streaming is the present unfolding in motion. Great systems often use both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Schema evolution is a design problem, not an afterthought.&lt;/strong&gt;&lt;br&gt;
If you design your data structures to evolve safely… you avoid entire categories of distributed bugs.&lt;/p&gt;

&lt;p&gt;You can take any one of these ideas and elevate your code review intuition immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DDIA changes how you study and practice engineering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;.This book indirectly forces a career mindset shift:&lt;/p&gt;

&lt;p&gt;.Senior dev interviews? They’re testing these concepts.&lt;/p&gt;

&lt;p&gt;.Architecture discussions at real companies? They’re anchored in these tradeoffs.&lt;/p&gt;

&lt;p&gt;Debugging production outages? Almost always related to assumptions this book teaches you how to avoid.&lt;/p&gt;

&lt;p&gt;It moves you away from “coding tasks” and into “system outcomes”.&lt;/p&gt;

&lt;p&gt;That is literally the identity shift between mid-level and senior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who should read this book?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;*mid-level backend devs who want to do proper system design&lt;/p&gt;

&lt;p&gt;*people preparing for senior interviews or staff level interviews&lt;/p&gt;

&lt;p&gt;*anyone going into infrastructure, distributed systems, or data engineering&lt;/p&gt;

&lt;p&gt;future AppSec engineers (yes, security without understanding distributed systems is incomplete)&lt;/p&gt;

&lt;p&gt;You don’t need to read it in one shot. This is a book you study over months and revisit repeatedly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;“Designing Data-Intensive Applications” is not a coding book. It’s a “how the real world actually works” book.&lt;/p&gt;

&lt;p&gt;If you want a single resource to help you break out of “framework-level thinking” and start thinking as a distributed systems engineer – this is it.&lt;/p&gt;

&lt;p&gt;This book is where backend engineering grows up.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>backenddevelopment</category>
      <category>database</category>
    </item>
    <item>
      <title>Review of the pragmatic programmer</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 01 Oct 2025 17:54:33 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/review-of-the-pragmatic-programmer-4pio</link>
      <guid>https://forem.com/hectorw_tt/review-of-the-pragmatic-programmer-4pio</guid>
      <description>&lt;p&gt;Review of The Pragmatic Programmer: Lessons for Every Developer&lt;/p&gt;

&lt;p&gt;As a developer, I often look for books that go beyond syntax and frameworks—books that shape how I think about coding and problem-solving. While browsing my LinkedIn feed one day, I came across a list of recommended books to become a world-class software engineer by Neo Kim. Intrigued, I took notes and acquired most of the books on the list. I decided to start with The Pragmatic Programmer by Andrew Hunt and David Thomas, as its title suggested it would address the realities of being a programmer/software engineer.&lt;/p&gt;

&lt;p&gt;Here’s what I learned from it and how it applies to my work in software development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Think Critically, Not Just Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The book emphasizes understanding the problem before writing code. Too often, developers jump straight into implementation. Hunt and Thomas remind us to:&lt;/p&gt;

&lt;p&gt;Analyze requirements deeply&lt;/p&gt;

&lt;p&gt;Question assumptions&lt;/p&gt;

&lt;p&gt;Consider future maintainability&lt;/p&gt;

&lt;p&gt;This mindset is invaluable in projects where complexity grows over time, like backend systems I've worked on in Java and Spring Boot. In the real world, the best software isn't the cleverest or the most efficient in terms of space and memory—but software that solves user problems. Designing such software involves understanding the problem through the eyes of the end user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Write Flexible, Maintainable Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Two principles stood out:&lt;/p&gt;

&lt;p&gt;DRY (Don't Repeat Yourself): Avoid redundancy to make code easier to maintain.&lt;/p&gt;

&lt;p&gt;Orthogonality: Keep modules independent to reduce unexpected side effects.&lt;/p&gt;

&lt;p&gt;Following these principles has helped me refactor legacy code and improve code quality, even in nearshore development projects with tight deadlines. These ideas are similar to clean code practices but focus more on mindset and thinking like a pragmatic programmer, rather than just formatting or naming conventions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Keep Learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The authors stress that continuous learning is essential. Technology evolves fast, and the pragmatic programmer adapts, experiments, and improves constantly.&lt;/p&gt;

&lt;p&gt;I’ve applied this by:&lt;/p&gt;

&lt;p&gt;Exploring new frameworks like Spring Boot and Hibernate&lt;/p&gt;

&lt;p&gt;Practicing coding challenges on LeetCode&lt;/p&gt;

&lt;p&gt;Engaging in bug bounty hunting and security research&lt;/p&gt;

&lt;p&gt;Hunt and Thomas reinforce the idea that you should invest in your knowledge portfolio—a collection of lessons, references, and tools that grow over time. This portfolio helps you think critically and tackle new problems effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Practical, Everyday Advice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The book isn’t just theory; it includes actionable tips:&lt;/p&gt;

&lt;p&gt;Using version control effectively&lt;/p&gt;

&lt;p&gt;Writing clear, meaningful comments&lt;/p&gt;

&lt;p&gt;Debugging strategies and problem-solving methods&lt;/p&gt;

&lt;p&gt;Even small tips like these save hours of frustration in real-world development. Some ideas, like tracer bullets and rubber duck debugging, are small techniques that have an outsized impact on efficiency and clarity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Boiling the Frog – Avoid Gradual Drift&lt;/strong&gt;&lt;br&gt;
One lesson that really stuck with me is the “boiling the frog” analogy. Hunt and Thomas explain that small, incremental compromises in code quality or practices—if ignored—can accumulate into big problems over time.&lt;/p&gt;

&lt;p&gt;My take: “Just like a frog in gradually heated water won’t notice the danger until it’s too late, small shortcuts in code—quick fixes, skipping tests, ignoring refactoring—can silently create massive technical debt.”&lt;/p&gt;

&lt;p&gt;Example: Adding quick fixes without refactoring might feel harmless at first, but over months it becomes much harder to maintain and debug.&lt;/p&gt;

&lt;p&gt;Lesson: Address small issues immediately and consistently improve your codebase, even if it feels minor.&lt;/p&gt;

&lt;p&gt;This analogy has changed how I approach long-term projects. It reinforces the importance of discipline, foresight, and small, steady improvements in coding practices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Building a Knowledge Portfolio&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another principle I found extremely practical is the idea of a knowledge portfolio. It’s not just a concept—it’s about taking actionable steps to build and maintain it:&lt;/p&gt;

&lt;p&gt;Collect lessons learned: Keep notes on challenges you’ve faced and how you solved them.&lt;/p&gt;

&lt;p&gt;Save useful code snippets: Organize patterns, functions, or tricks you can reuse in future projects.&lt;/p&gt;

&lt;p&gt;Maintain references and resources: Document books, articles, blog posts, or tutorials that helped you.&lt;/p&gt;

&lt;p&gt;Review and update regularly: A portfolio is only valuable if you revisit it, prune outdated content, and add new insights.&lt;/p&gt;

&lt;p&gt;Example: I maintain a folder of Java patterns, security tips, and LeetCode solutions that I can reference anytime—this saves hours and helps me think more like a “pragmatic programmer.”&lt;/p&gt;

&lt;p&gt;💡 Application to SDLC: Maintaining a knowledge portfolio helps across the entire software development life cycle—from requirements gathering, design, and coding, to testing, deployment, and maintenance. Having organized lessons, snippets, and resources allows you to make informed decisions at every stage and avoid repeating mistakes.&lt;/p&gt;

&lt;p&gt;This portfolio concept emphasizes continuous learning and documentation, making you more adaptable and effective as a developer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Pragmatic Programmer is more than a coding book—it’s a guide to thinking, designing, and working like a professional software developer. Whether you’re starting your career or are an experienced developer, the lessons in this book are timeless.&lt;/p&gt;

&lt;p&gt;📚 Question for readers: Which book has influenced the way you code the most? I’d love to hear your recommendations!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>books</category>
    </item>
    <item>
      <title>Clean Coding Guidelines Every Developer Should Know</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 17 Sep 2025 15:35:11 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/clean-coding-guidelines-every-developer-should-know-1717</link>
      <guid>https://forem.com/hectorw_tt/clean-coding-guidelines-every-developer-should-know-1717</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
 Software is a critical part of the modern world and it needs people to design, develop, test and maintain it. Due to the nature of life, there are often turnovers on a company's payroll. Employees retire, die or leave their role for other reasons. This presents the company with a challenge-how to create code that can be maintained and upgraded by other software engineers. Due to this, clean coding guidelines have been invented. The term was popularized by Robert C.Martin aka "Uncle Bob" and explained in his book. &lt;em&gt;Clean Code&lt;/em&gt; These guidelines ensure that code is easy to read, easy to maintain and easy to change. They are as follows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Meaningful Naming&lt;/strong&gt;&lt;br&gt;
Descriptive names should be used for variables, methods and classes that reflect their purpose and behavior. Single letter names should usually be avoided. This makes the code easier to read and understand and the logic easier to follow. It can also help in debugging the code.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int d; // days since creation

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int daysSinceCreation;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Small, Focused Functions&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
As an application of the Single Responsibility Principle, functions and methods should be designed so that they carry out one goal. They should also be small. This way functions will be easier to read ,reuse, test and maintain.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void processOrder(Order order) {
   // validate order
   // calculate totals
   // apply discounts
   // update inventory
   // notify user
}

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Example {
    public void doWork() {
        System.out.println("Working");
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Consistent Formatting&lt;/strong&gt;&lt;br&gt;
Formatting should be consistent. Spacing should be minimal in both the horizontal and vertical directions and the code should appear neat. Font sizes should be consistent. Following these rules should make the code easy to read.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Example{
public void doWork( ){System.out.println("Working");}}

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Example {
    public void doWork() {
        System.out.println("Working");
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Comment wisely&lt;/strong&gt;&lt;br&gt;
Comments are unnecessary if the code is well written. Good code will be self expressive. Don’t state the obvious. Use comments to explain “why” something is done, not “what.” If code is too confusing and you feel the need to over-comment, it’s usually a sign the code itself needs refactoring.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i++; // increment i by 1

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Retry up to 3 times because the external API is unreliable
retryOperation();

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Avoid Duplication&lt;/strong&gt;&lt;br&gt;
Duplicated code will lead to copies of the same code snippets all over the code base. Whenever a change needs to be made, the changes need to be made in a number of places. Otherwise, the code will break. Changes will also be time consuming. Hence, we need to centralize the code in order to make maintenance easier.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (userType.equals("Admin")) { /* logic */ }
if (userType.equals("Manager")) { /* same logic */ }

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (isPrivilegedUser(userType)) {
   // logic
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Error Handling&lt;/strong&gt;&lt;br&gt;
As with life, the unexpected happens during software execution and we thus need to design and implement code in such a way to handle errors. Handling of the errors should also produce the correct error messages in order to debug the system. Proper error handling ensures failures are visible and recoverable, making systems more robust.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
   doSomething();
} catch (Exception e) {
   // ignore
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
   doSomething();
} catch (IOException e) {
   log.error("File operation failed", e);
   throw e; // or handle gracefully
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. KISS (Keep it Simple Stupid)&lt;/strong&gt;&lt;br&gt;
 Write code that is code that’s easy to read, understand, and maintain. Avoid clever tricks or overly complex logic that only the original author can follow. Simpler code reduces bugs, makes future changes easier,helps onboards new members faster and encourages modularity.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ((user.isActive() &amp;amp;&amp;amp; user.hasSubscription()) || 
    (user.isAdmin() &amp;amp;&amp;amp; !user.hasSubscription() &amp;amp;&amp;amp; config.isEnabled())) {
    allowAccess();
}//Hard to read,easy to make mistakes later.

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (canAccess(user)) {
    allowAccess();
}

private boolean canAccess(User user) {
    return (user.isActive() &amp;amp;&amp;amp; user.hasSubscription()) || user.isAdmin();
}//The logic is isolated; The main flow is readable at a glance and easier to test and maintain.

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8.Follow SOLID Principles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/hectorw_tt/the-solid-principles-of-object-oriented-programming-4bff"&gt;https://dev.to/hectorw_tt/the-solid-principles-of-object-oriented-programming-4bff&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9.Write Tests&lt;/strong&gt;&lt;br&gt;
Tests are your safety net. Unit tests confirm small pieces work correctly, while integration tests check the bigger picture-how well multiple components work together. Writing tests ensures that your code does what it should do. Without tests, “clean” code can still hide regressions and future breakages. Clean code is testable code.&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
Suppose you have a method that calculates the area of a rectangle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int area(int width, int height) {
    return width * height;
}

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

&lt;/div&gt;



&lt;p&gt;Unit Test&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
@Test
public void testArea() {
    Rectangle rect = new Rectangle();
    assertEquals(20, rect.area(4, 5));
    assertEquals(0, rect.area(0, 5));
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10.Refactor Regularly&lt;/strong&gt;&lt;br&gt;
Refactoring means improving the structure of your code without changing its behavior. It’s like cleaning up a messy room: you don’t throw anything away, you just organize it so it’s easier to use.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void processOrders(List&amp;lt;Order&amp;gt; orders) {
    for (Order o : orders) {
        if (o.isValid() &amp;amp;&amp;amp; !o.isShipped()) {
            double total = 0;
            for (Item i : o.getItems()) {
                total += i.getPrice() * i.getQuantity();
            }
            if (total &amp;gt; 1000) {
                // apply discount
            }
        }
    }
}

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

&lt;/div&gt;



&lt;p&gt;After refactoring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void processOrders(List&amp;lt;Order&amp;gt; orders) {
    for (Order order : orders) {
        if (canProcess(order)) {
            applyDiscountIfNeeded(order);
        }
    }
}

private boolean canProcess(Order order) {
    return order.isValid() &amp;amp;&amp;amp; !order.isShipped();
}

private void applyDiscountIfNeeded(Order order) {
    double total = calculateTotal(order);
    if (total &amp;gt; 1000) {
        applyDiscount(order);
    }
}

private double calculateTotal(Order order) {
    return order.getItems().stream()
                .mapToDouble(i -&amp;gt; i.getPrice() * i.getQuantity())
                .sum();
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In the ever-evolving field of software development, writing clean code is paramount. It ensures that codebases are maintainable, scalable, and understandable, facilitating easier collaboration and long-term project success. In conclusion, following these habits will lead to code that is easy to read, maintain and update even when the team that is working with this codebase changes on a regular basis.What are your clean coding recommendations?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Resources&lt;/strong&gt;: Clean Code by Robert C.Martin&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>programming</category>
      <category>code</category>
    </item>
    <item>
      <title>Secure Coding guidelines</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 03 Sep 2025 15:14:48 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/secure-coding-guidelines-9kb</link>
      <guid>https://forem.com/hectorw_tt/secure-coding-guidelines-9kb</guid>
      <description>&lt;p&gt;&lt;strong&gt;1.Introduction&lt;/strong&gt;&lt;br&gt;
 Software now plays an important role in the modern world and is  critical to aspects of life such as finance, health care, communication and even military. It is thus essential that we secure disruptions to this software from hackers and cyber criminals that affect its confidentiality, data integrity and availability. Currently, there are 2 ways to do this. One involves fixing code after the discovery of security bugs. This is risky because the damage may already be done. The other is to follow secure coding guidelines. This article discusses the principles involved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Core Guidelines&lt;/strong&gt;&lt;br&gt;
  Secure coding guidelines are the best practices, software engineers follow to prevent vulnerabilities and security flaws in software applications. The following is a list of such guidelines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I.) Validate All Input.&lt;/strong&gt;&lt;br&gt;
 Programs need input data but unfortunately they present an attack surface that can allow attackers to exploit the application and execute a potentially devastating attack. Examples include SQL injection and Cross Site Scripting (XSS) attacks. The software needs to be written so that the inputs match a whitelist of valid inputs or a blacklist of inputs that arent allowed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;II) Access Control&lt;/strong&gt;&lt;br&gt;
  Software needs access control measures to ensure that users cant take actions that arent allowed to do.The access control measures take the form of authentication-ensuring that users are who they say are and authorization-ensuring that users are authorized to take whatever actions they desire to take.The principle of least privilege is followed where each user operates using the fewest number of privileges possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;III) Data Protection &amp;amp; Cryptography&lt;/strong&gt;&lt;br&gt;
   Data needs to be protected during communication from unauthorized eavesdropping. This can be done using cryptography which has been around for thousands of years and hashing which is used to ensure the integrity of data. That is data hasnt been tampered with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IV) Error Handling &amp;amp; Logging&lt;/strong&gt;&lt;br&gt;
   Error handling and logging are crucial parts of software applications. Unfortunately, they may produce information that will allow attackers to exploit. These are called information disclosure bugs. Care must be taken not to expose stack traces or sensitive information in error messages; to log messages but not sensitive information and to restrict the access to sensitive logs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;V)Session Management&lt;/strong&gt;&lt;br&gt;
  Web applications often involve the use of sessions which allow users to login and have built in security mechanisms.These include the use of secure cookies; the invalidation of sessions after logging out and the regeneration of session ids after login. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.The Defensive Programming Mindset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Defensive programming is about writing code with the assumption that things will go wrong. Instead of expecting the “happy path” to always succeed, you prepare for bad inputs, unexpected states, and failures. The goal is to make your code resilient, predictable, and secure—even when users (or attackers) try to break it.&lt;/p&gt;

&lt;p&gt;Here are some key principles of the defensive mindset:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I)Assume inputs are malicious&lt;/strong&gt;&lt;br&gt;
Never trust data from users, APIs, or files. Validate and sanitize everything before using it. For example, if you expect an age field, don’t just check that it’s a number—also make sure it’s within a sensible range (e.g., 0–120).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;II)Fail securely&lt;/strong&gt;&lt;br&gt;
When something goes wrong, default to the safest option. If a login check fails, deny access, even if you’re not sure why. Error handling should protect the system, not expose it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;III)Check for unexpected states&lt;/strong&gt;&lt;br&gt;
Defensive code doesn’t assume a function always returns valid data. Check for nulls, empty lists, or invalid responses. In Java, prefer Optional to handle absent values safely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IV)Limit assumptions&lt;/strong&gt;&lt;br&gt;
Don’t assume a file exists, a network call will succeed, or a database query will always return results. Build in checks and fallback logic so the application remains stable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;V)Design with least privilege&lt;/strong&gt;&lt;br&gt;
Give code, services, and users only the access they truly need. If one part of the system is compromised, least privilege limits how far the damage can spread.&lt;/p&gt;

&lt;p&gt;Adopting this mindset doesn’t just improve security—it makes your code more reliable and easier to maintain. When you think defensively, you’re not just coding for today’s happy path—you’re protecting against tomorrow’s worst-case scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Practical Tips&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Writing secure code is easier when you adopt practical habits and tools. Here are some tips every developer should follow:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;I)Follow OWASP Secure Coding Practices *&lt;/em&gt;– Use the official OWASP guidelines as a baseline for secure development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;II)Use SAST/DAST tools&lt;/strong&gt; – Static and dynamic analysis tools like SonarQube or OWASP Dependency Check help catch vulnerabilities early.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;III)Keep dependencies updated&lt;/strong&gt; – Outdated libraries are a common source of security flaws; regularly update and patch them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IV)Perform code reviews with a security checklist&lt;/strong&gt; – Incorporate security-focused questions during code reviews to catch risks before they reach production.&lt;/p&gt;

&lt;p&gt;By integrating these practices into your workflow, you make secure coding a habit rather than an afterthought.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Secure coding isn’t just a checklist—it’s a mindset. By validating inputs, protecting data, handling errors carefully, and thinking defensively, developers can build software that is resilient, reliable, and resistant to attacks.&lt;/p&gt;

&lt;p&gt;Adopting practical habits—like following OWASP guidelines, using analysis tools, keeping dependencies updated, and performing security-focused code reviews—turns secure coding from a one-time effort into a consistent practice.&lt;/p&gt;

&lt;p&gt;Ultimately, writing secure code protects users, safeguards sensitive data, and saves organizations from costly breaches. The best time to start is today—every line of code you write with security in mind makes a difference. Like this article? Feel free to comment or share.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>programming</category>
    </item>
    <item>
      <title>From Struggle to Solution-An Approach to Solving a programming problem using #650.Leetcode's 2 keys keyboard as an example</title>
      <dc:creator>Hector Williams</dc:creator>
      <pubDate>Wed, 09 Jul 2025 18:15:06 +0000</pubDate>
      <link>https://forem.com/hectorw_tt/from-struggle-to-solution-an-approach-to-solving-a-programming-problem-using-650leetcodes-2-keys-1a6i</link>
      <guid>https://forem.com/hectorw_tt/from-struggle-to-solution-an-approach-to-solving-a-programming-problem-using-650leetcodes-2-keys-1a6i</guid>
      <description>&lt;p&gt;&lt;strong&gt;1.Introduction&lt;/strong&gt;&lt;br&gt;
 I regularly practice leetcode if not always on a daily basis. The reasons that I do this are: to keep my coding skills sharp, to deepen my understanding of algorithms and data structures and to prepare for coding challenges and technical interviews. Recently, I solved Leetcode's #650-the 2 keys keyboard using dynamic programming and I have decided to share my approach to solving this problem.Below is a description of the problem.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;2 Keys Keyboard&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:&lt;/p&gt;

&lt;p&gt;Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).&lt;br&gt;
Paste: You can paste the characters which are copied last time.&lt;br&gt;
Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.&lt;/p&gt;

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

&lt;p&gt;Input: n = 3&lt;br&gt;
Output: 3&lt;br&gt;
Explanation: Initially, we have one character 'A'.&lt;br&gt;
In step 1, we use Copy All operation.&lt;br&gt;
In step 2, we use Paste operation to get 'AA'.&lt;br&gt;
In step 3, we use Paste operation to get 'AAA'.&lt;br&gt;
Example 2:&lt;/p&gt;

&lt;p&gt;Input: n = 1&lt;br&gt;
Output: 0&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;

&lt;p&gt;1 &amp;lt;= n &amp;lt;= 1000&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.First Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I read the problem and the topics it was listed under. It was listed as Math and Dynamic Programming. My understanding was that there were 2 types of operations: a copy and paste and a paste. I was at first baffled and confused about where to start. I mean how could I minimize the number of operations to achieve this task? The fact that it was listed as dynamic programming gave me an idea-use a 1-d array to store the results of subproblems but I was still baffled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Attempts &amp;amp; Failures&lt;/strong&gt;&lt;br&gt;
  I read the hints. Only 1 was provided. It said "How many characters may be there in the clipboard at the last step if n = 3? n = 7? n = 10? n = 24?". This confused me more. I decided to try something. I could not come up with anything so I decided to reread the problem. On doing so, I realized my first error. &lt;em&gt;2 types of operations were allowed: a copy all and a paste&lt;/em&gt;.This helped. I did some thinking and realized that for a final string of 6,I could do a copy and paste of 3 characters and ditto for a string of 4 characters. It was progress but unfortunately not enough. I decided to read the discussion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2 observations.
If n is a prime=&amp;gt; ans=n
If n=2^k=&amp;gt; ans=2*k
Something to do with prime factorization, maybe Sieve method can play again, not very necessary.
Have a nice day.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was helpful but still I struggled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The Breakthrough&lt;/strong&gt;&lt;br&gt;
 I decided to give it a rest and to come back to it later. I was eating lunch and my mind thought about it. I had a realization!!! If the final string was 1000 characters, I could minimize by performing a copy and paste on a string of 500 problems. If it was prime, I could perform a copy and paste of 1 character n times. If it was a string of 27 characters, I could copy a string of 9 characters and paste it twice. So I found a solution. Create a 1-d array of length n+1.Iterate from the index 2 to the end of the array,if the current index is prime, record its number.Otherwise,get its greatest factor,go to that position in the array and calculate the current value by adding the dp value of the highest factor and the quotient of the current value/highest factor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(isPrime(i) dp[i]=i;
else dp[i]=dp[highestFactor(i)]+(i/highestFactor(i)).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this in mind, I attempted a solution. I attempted to do this in Java. Here was my first solution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int minSteps(int n) {
      int []dp= new int[n+1];
      for(int i=2;i&amp;lt;n+1;i++){
       if(isPrime(i))dp[i]=i;
       else {
        //System.out.println
        dp[i] =dp[highestDivisor(i)]+(i/highestDivisor(i));
       } 
      }  
      return dp[n];
    }

    public int highestDivisor(int n) {
        if (n &amp;lt;= 1) return -1; // No proper divisor exists for 0 or 1

        for (int i = n / 2; i &amp;gt;= 1; i--) {
            if (n % i == 0) {
                return i; // First divisor found from the top is the highest
            }
        }
        return -1; // Should never reach here for n &amp;gt; 1
    }

    public  boolean isPrime(int n) {
        if (n &amp;lt;= 1) return false; // 0 and 1 are not prime
        if (n &amp;lt;= 3) return true;  // 2 and 3 are prime
        if (n % 2 == 0 || n % 3 == 0) return false; // eliminate multiples of 2 and 3

        // Only check up to √n using 6k ± 1 optimization
        for (int i = 5; i * i &amp;lt;= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        }
        return true;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As part of my recent decision to try and get solutions in at least 4 languages (Java, c# ,c++ and javascript),I attempted to achieve solutions in c#,c++ and javascript. I first tried c# and the following solution was accepted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Solution {
    public int MinSteps(int n) {
     int []dp= new int[n+1];
      for(int i=2;i&amp;lt;n+1;i++){
       if(IsPrime(i))dp[i]=i;
       else dp[i] =dp[HighestDivisor(i)]+(i/HighestDivisor(i));        
      }  
      return dp[n];
    }

    public int HighestDivisor(int n) {
        if (n &amp;lt;= 1) return -1; // No proper divisor exists for 0 or 1

        for (int i = n / 2; i &amp;gt;= 1; i--) {
            if (n % i == 0) {
                return i; // First divisor found from the top is the highest
            }
        }
        return -1; // Should never reach here for n &amp;gt; 1
    }

    public  bool IsPrime(int n) {
        if (n &amp;lt;= 1) return false; // 0 and 1 are not prime
        if (n &amp;lt;= 3) return true;  // 2 and 3 are prime
        if (n % 2 == 0 || n % 3 == 0) return false; // eliminate multiples of 2 and 3

        // Only check up to √n using 6k ± 1 optimization
        for (int i = 5; i * i &amp;lt;= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        }
        return true;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I then attempted c++ and my solution was again accepted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    int minSteps(int n) {
      vector&amp;lt;int&amp;gt;dp;
      for(int i=0;i&amp;lt;n+1;i++)dp.push_back(0);
      for(int i=2;i&amp;lt;n+1;i++){
       if(isPrime(i))dp[i]=i;
       else dp[i] =dp[highestDivisor(i)]+(i/highestDivisor(i));        
      }  
      return dp[n];
    }

    int highestDivisor(int n) {
        if (n &amp;lt;= 1) return -1; // No proper divisor exists for 0 or 1

        for (int i = n / 2; i &amp;gt;= 1; i--) {
            if (n % i == 0) {
                return i; // First divisor found from the top is the highest
            }
        }
        return -1; // Should never reach here for n &amp;gt; 1
    }

    bool isPrime(int n) {
        if (n &amp;lt;= 1) return false; // 0 and 1 are not prime
        if (n &amp;lt;= 3) return true;  // 2 and 3 are prime
        if (n % 2 == 0 || n % 3 == 0) return false; // eliminate multiples of 2 and 3

        // Only check up to √n using 6k ± 1 optimization
        for (int i = 5; i * i &amp;lt;= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        }
        return true;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Feeling very proud, I decided to try in javascript, I tried the following but saw that it was rejected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var minSteps = function(n) {
      const []dp;
      for(let i=2;i&amp;lt;n+1;i++){
       let highestDivisor=i;
       for(let j=i/2;j&amp;gt;1;j--){
        if(i%j==0){
          highestDivisor=j;
          break;  
        }
       } 
       if(highestDivisor==i)dp[i]=i; 
       else dp[i] =dp[highestDivisor]+(i/highestDivisor);        
      }  
      return dp[n];  
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I got a runtime error and was flabbergasted. I decided to come back later and to first attempt an optimized java solution. I decided to come up with the following approach. Instead of determining if a number is prime to find the highest divisor. I used the following which was accepted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int minSteps(int n) {
      int []dp= new int[n+1];
      for(int i=2;i&amp;lt;n+1;i++){
       if(isPrime(i))dp[i]=i;
       else {
        //System.out.println
        dp[i] =dp[highestDivisor(i)]+(i/highestDivisor(i));
       } 
      }  
      return dp[n];
    }

    public int highestDivisor(int n) {
        if (n &amp;lt;= 1) return -1; // No proper divisor exists for 0 or 1

        for (int i = n / 2; i &amp;gt;= 1; i--) {
            if (n % i == 0) {
                return i; // First divisor found from the top is the highest
            }
        }
        return -1; // Should never reach here for n &amp;gt; 1
    }

    public  boolean isPrime(int n) {
        if (n &amp;lt;= 1) return false; // 0 and 1 are not prime
        if (n &amp;lt;= 3) return true;  // 2 and 3 are prime
        if (n % 2 == 0 || n % 3 == 0) return false; // eliminate multiples of 2 and 3

        // Only check up to √n using 6k ± 1 optimization
        for (int i = 5; i * i &amp;lt;= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        }
        return true;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was accepted and was slightly better than the original. I felt happy. I decided to retry the javascript solution. I attempted to debug using print statements and realized that j was initialized as 1.5.So,I made some changes. I used j=i-1 and reran and came up with this solution which was accepted!!! I felt I was on a roll!!!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var minSteps = function(n) {
      const dp=[];
      for(let i=0;i&amp;lt;n+1;i++)dp.push(0);
      for(let i=2;i&amp;lt;n+1;i++){
       let highestDivisor=i;
       for(let j=i-1;j&amp;gt;1;j--){
        if(i%j==0){
          highestDivisor=j;
          break;  
        }
       } 
       if(highestDivisor==i)dp[i]=i; 
       else dp[i] =dp[highestDivisor]+(i/highestDivisor);        
      }
      return dp[n];  
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Lessons Learned&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This experience has taught me/helped reinforce a number of lessons.&lt;br&gt;
1) Fully understand the problem a program/coding challenge is trying to solve by careful reading, asking the necessary questions. A problem cant be solved if you have misunderstood or dont understand it.&lt;/p&gt;

&lt;p&gt;2) Research how previous or similar problems were solved by other programmers.&lt;/p&gt;

&lt;p&gt;3) Develop a first draft solution to the problem.&lt;/p&gt;

&lt;p&gt;4) If stuck, take a break. Solutions can come when your mind is at rest.&lt;/p&gt;

&lt;p&gt;5) Optimize your solutions where possible. It can save time and memory. In production environments, this can make a noticeable difference.&lt;/p&gt;

&lt;p&gt;6) Different programming languages handle variables differently. Understand how.&lt;/p&gt;

&lt;p&gt;7) Debugging with print statements is an unsophisticated but simple way to troubleshoot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Wrap-Up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hope my post has been helpful, please feel free to like,comment and share. Please check out my github profile for this and more solutions.It is here : &lt;a href="https://github.com/HectorwTT" rel="noopener noreferrer"&gt;https://github.com/HectorwTT&lt;/a&gt;&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>java</category>
      <category>dsa</category>
    </item>
  </channel>
</rss>
