<?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: Jerin</title>
    <description>The latest articles on Forem by Jerin (@jerin_babu).</description>
    <link>https://forem.com/jerin_babu</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%2F3914172%2F1f1a253f-2ad3-4a2d-bd94-81f77f4d85de.png</url>
      <title>Forem: Jerin</title>
      <link>https://forem.com/jerin_babu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jerin_babu"/>
    <language>en</language>
    <item>
      <title>LeetCode 819: Most Common Word — Simple Explanation with Carry Logic (Java)</title>
      <dc:creator>Jerin</dc:creator>
      <pubDate>Wed, 06 May 2026 07:05:19 +0000</pubDate>
      <link>https://forem.com/jerin_babu/leetcode-819-most-common-word-simple-explanation-with-carry-logic-java-190e</link>
      <guid>https://forem.com/jerin_babu/leetcode-819-most-common-word-simple-explanation-with-carry-logic-java-190e</guid>
      <description>&lt;p&gt;&lt;strong&gt;Difficulty&lt;/strong&gt;: Easy&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topics&lt;/strong&gt;: Array, Math, Hash Table, String, Counting&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Platform&lt;/strong&gt;: Leetcode&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique.&lt;/p&gt;

&lt;p&gt;The words in paragraph are case-insensitive and the answer should be returned in lowercase.&lt;/p&gt;

&lt;p&gt;Note that words can not contain punctuation symbols.&lt;/p&gt;

&lt;p&gt;Problem Statement Simplified&lt;br&gt;
If in the paragraph string have the word in banned array, then discard it. If the paragraph string have ‘.’ or ‘ ’ then remove it. Make everything lowercase. Then give back the word that is most frequent.&lt;/p&gt;

&lt;p&gt;Mistakes and Learning&lt;br&gt;
Forgetting about removing ‘.’ or ‘ ’.&lt;br&gt;
Look out for rare cases (ex:[a.])&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 1
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]&lt;br&gt;
Output: "ball"&lt;br&gt;
Explanation: &lt;br&gt;
"hit" occurs 3 times, but it is a banned word.&lt;br&gt;
"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. &lt;br&gt;
Note that words in the paragraph are not case sensitive,&lt;br&gt;
that punctuation is ignored (even if adjacent to words, such as "ball,"), &lt;br&gt;
and that "hit" isn't the answer even though it occurs more because it is banned.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 2
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Input: paragraph = "a.", banned = []&lt;br&gt;
Output: "a"&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Insight
&lt;/h2&gt;

&lt;p&gt;Initialize a HashMap and HashSet for paragraph String and banned array.&lt;br&gt;
If not a word from banned array then add to HashMap and increment the counter&lt;br&gt;
If a word from banned array then move to next word.&lt;/p&gt;

&lt;h2&gt;
  
  
  Algorithm
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Remove everything from string other than [a-z] and make it lowercase.&lt;/li&gt;
&lt;li&gt;Initialize a String array and add the string words to it using split function.&lt;/li&gt;
&lt;li&gt;Initialize HashMap and HashSet for string array and banned word array respectively.&lt;/li&gt;
&lt;li&gt;Initialize an int max and string maxWord to check and return the max repeating word.&lt;/li&gt;
&lt;li&gt;Initialize a for loop and add the banned array to HashSet.
end for loop&lt;/li&gt;
&lt;li&gt;Initialize a for loop.&lt;/li&gt;
&lt;li&gt;Store the current word in String array to a string.&lt;/li&gt;
&lt;li&gt;If not a word in HashSet.&lt;/li&gt;
&lt;li&gt;Put in HashMap and increment the value if not already present.&lt;/li&gt;
&lt;li&gt;If value is greater than max.&lt;/li&gt;
&lt;li&gt;Assign the value to max.&lt;/li&gt;
&lt;li&gt;Assign word to maxWord.&lt;/li&gt;
&lt;li&gt;end if.&lt;/li&gt;
&lt;li&gt;end if&lt;/li&gt;
&lt;li&gt;end for loop.&lt;/li&gt;
&lt;li&gt;return max word.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Algorithm in simple words
&lt;/h2&gt;

&lt;p&gt;First, remove everything from string other than [a-z] and make it lowercase. Then split the string and store it in an array.&lt;br&gt;
Initialize a HashMap to store the string and integer - so that we can just look at this hashmap and check how many times the string repeated. everytime we loop through the string array (we created earlier), we will store the words in hashmap and assign a value to it which will increment when the word is repeated in the array.&lt;/p&gt;

&lt;p&gt;Initialize a HashSet to store the string — so that the banned word array can be stored and compared with hashmap.&lt;/p&gt;

&lt;p&gt;Initialize an int max and string maxWord to check and return the max repeating word.&lt;/p&gt;

&lt;p&gt;Initialize a for loop which will go thorugh the banned words array and add them to HashSet.&lt;/p&gt;

&lt;p&gt;Then we will loop through the string array and check the HashSet and current word from String array. If same then we will move to next word from String array. If not then we will add it to HashMap and if the word already exists then we will increment the value of it ( using map.getOrDefault(word,0) it will return the current value, if the word doesnt exists then it wil return 0 otherwise the current value of that word from HashMap ).&lt;/p&gt;

&lt;p&gt;Then we will check of this value is greater than max, if yes then we will set this value as new max and this word as new maxWord.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java code
&lt;/h2&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="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;mostCommonWord&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;paragraph&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;banned&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;paragraph&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;paragraph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toLowerCase&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;replaceAll&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"[^a-z]"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="s"&gt;" "&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;words&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;paragraph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;split&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\\s+"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;bannedWord&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;counter&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="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;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;maxWord&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;""&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;banned&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;bannedWord&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;banned&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;toLowerCase&lt;/span&gt;&lt;span class="o"&gt;());&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;words&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="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;words&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;if&lt;/span&gt;&lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;bannedWord&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;)){&lt;/span&gt;
            &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOrDefault&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&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="mi"&gt;1&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;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;)&amp;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;max&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;maxWord&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;word&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="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;maxWord&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;h2&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h2&gt;

&lt;p&gt;Time Complexity: O(n+m)&lt;/p&gt;

&lt;p&gt;Space Complexity: O(n+m)&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>hashmap</category>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>LeetCode 66: Plus One — Simple Explanation with Carry Logic (Java)</title>
      <dc:creator>Jerin</dc:creator>
      <pubDate>Tue, 05 May 2026 13:54:59 +0000</pubDate>
      <link>https://forem.com/jerin_babu/leetcode-66-plus-one-simple-explanation-with-carry-logic-java-2i59</link>
      <guid>https://forem.com/jerin_babu/leetcode-66-plus-one-simple-explanation-with-carry-logic-java-2i59</guid>
      <description>&lt;p&gt;&lt;strong&gt;Difficulty&lt;/strong&gt;: Easy&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topics&lt;/strong&gt;: Array, Math&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Platform&lt;/strong&gt;: Leetcode&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.Increment the large integer by one and return the resulting array of digits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement Simplified
&lt;/h2&gt;

&lt;p&gt;Check the last digit, add 1, then return&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistakes and Learning
&lt;/h2&gt;

&lt;p&gt;Do not turn the array into number.&lt;br&gt;
Only check/change last digit.&lt;br&gt;
Look out for rare cases (ex:[9,9,9,…]&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 1
&lt;/h2&gt;

&lt;p&gt;Input: digits = [1,2,3]&lt;br&gt;
Output: [1,2,4]&lt;br&gt;
Explanation: The array represents the integer 123.&lt;br&gt;
Incrementing by one gives 123 + 1 = 124.&lt;br&gt;
Thus, the result should be [1,2,4].&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 2
&lt;/h2&gt;

&lt;p&gt;Input: digits = [4,3,2,1]&lt;br&gt;
Output: [4,3,2,2]&lt;br&gt;
Explanation: The array represents the integer 4321.&lt;br&gt;
Incrementing by one gives 4321 + 1 = 4322.&lt;br&gt;
Thus, the result should be [4,3,2,2].&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Insight
&lt;/h2&gt;

&lt;p&gt;Addition starts from the last digit&lt;br&gt;
If digit &amp;lt; 9 → just increment and stop&lt;br&gt;
If digit = 9 → set to 0 and carry forward&lt;/p&gt;

&lt;h2&gt;
  
  
  Algorithm
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Initialize a for loop with i starting from last digit and i decrement at each loop.&lt;/li&gt;
&lt;li&gt;Check if the digit[i] is less than 9&lt;/li&gt;
&lt;li&gt;If less than 9, then increment (digit[i]++).
return digit.&lt;/li&gt;
&lt;li&gt;end if.&lt;/li&gt;
&lt;li&gt;then digit[i]=0.&lt;/li&gt;
&lt;li&gt;end for loop&lt;/li&gt;
&lt;li&gt;Initialize an array with digits.length+1.&lt;/li&gt;
&lt;li&gt;Assign the first digit of new array as 1.&lt;/li&gt;
&lt;li&gt;return the new array.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Algorithm in simple words
&lt;/h2&gt;

&lt;p&gt;First, initialize a for loop that will start from the end of the array and check if that digit is less than 9, if yes then just increment that digit by 1 and return it, SIMPLE ! (ex: suppose the digits array is [4,2,3,2] check the last digit, it is less than 9 , which is 2. So when we increment 2 the final result will be [4,2,3,3], that is the final output).&lt;/p&gt;

&lt;p&gt;Suppose the last digit is 9 then make it 0 and then go to the second last digit and check in the if statment. if it is less than 9 then increment by 1 then return. (ex : suppose the digits array iss [4,3,2,9] check if less than 9, NO. Then digits&lt;a href="https://dev.toin%20here%20that%20is%209"&gt;i&lt;/a&gt; will become 0 the array will be [4,3,2,0], i decrease then check for the second last digit (here it is 2) it is less than 9 so increamnet by 1 then return so the final result will be [4,3,3,0]).&lt;/p&gt;

&lt;p&gt;Suppose the entire is 9 ie the array is [9,9,9] then we will initialize a new array increment the array length by 1, and make the first digit of the array 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java code
&lt;/h2&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="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;plusOne&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;digits&lt;/span&gt;&lt;span class="o"&gt;)&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="n"&gt;digits&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="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;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;--)&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;digits&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;lt;&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;digits&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;return&lt;/span&gt; &lt;span class="n"&gt;digits&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;digits&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;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;newDigits&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;digits&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="n"&gt;newDigits&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="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;return&lt;/span&gt; &lt;span class="n"&gt;newDigits&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;h2&gt;
  
  
  Time &amp;amp; Space Complexity
&lt;/h2&gt;

&lt;p&gt;Time Complexity: O(n)&lt;/p&gt;

&lt;p&gt;Space Complexity: O(1) (except when new array is created)&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>java</category>
      <category>challenge</category>
    </item>
  </channel>
</rss>
