<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 0not0</title>
    <description>The latest articles on DEV Community by 0not0 (@0not0).</description>
    <link>https://dev.to/0not0</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1125883%2F71439550-163a-4481-adde-8fa2e7446be6.png</url>
      <title>DEV Community: 0not0</title>
      <link>https://dev.to/0not0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/0not0"/>
    <language>en</language>
    <item>
      <title>AI can solve LeetCode in seconds. Is writing coding tutorials still worth it?</title>
      <dc:creator>0not0</dc:creator>
      <pubDate>Tue, 15 Sep 2026 11:18:51 +0000</pubDate>
      <link>https://dev.to/0not0/ai-can-solve-leetcode-in-seconds-is-writing-coding-tutorials-still-worth-it-1mip</link>
      <guid>https://dev.to/0not0/ai-can-solve-leetcode-in-seconds-is-writing-coding-tutorials-still-worth-it-1mip</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article is based on my own experience and observations. Maybe, if the website is still alive, I'll come back to this article in six months and update it with the results I have at that time.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I run a small website called &lt;a href="https://algobytes.net" rel="noopener noreferrer"&gt;&lt;strong&gt;AlgoBytes&lt;/strong&gt;&lt;/a&gt;, where I write about algorithms, coding interview patterns, and LeetCode problems. A detailed solution post can easily take me from 30 minutes to an hour to write, format, check, and publish. Here, I don't take into account the time spent solving the problem.&lt;br&gt;
Meanwhile, I can give the same problem to an AI assistant and get a working solution with an explanation in seconds.&lt;/p&gt;

&lt;p&gt;That made me ask a simple question: &lt;strong&gt;why am I still doing this, and should I keep doing it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I decided not to guess. I started watching what actually happens to the articles I publish on AlgoBytes - whether Google indexes them, whether people search for these solutions, and whether anyone actually clicks them.&lt;br&gt;
Almost all of my solution posts reached the top 10 in Google search results, even though there are many big competitors in this niche. There are specialized websites, YouTube channels, and many posts on different platforms dedicated to solving specific LeetCode problems. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgtz1vcqmdlauau8suxzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgtz1vcqmdlauau8suxzm.png" alt="search result for 835 leetcode problem solution" width="800" height="1579"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu4zux7cuod9ej04b8qsc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu4zux7cuod9ej04b8qsc.png" alt="search result for 836 leetcode problem solution" width="800" height="1129"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;For a very young website, getting stable positions on the first page of Google looks like a good result. But at the time of writing this post, those positions haven't brought me any real traffic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0bpcask183df8enqymy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0bpcask183df8enqymy.png" alt="google search console result for algobytes.net site" width="800" height="232"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Maybe the way I present the material also affects the results. I intentionally decided not to write long step-by-step explanations of how to solve each problem. Instead, I tried to explain the main idea of the solution in 5 - 10 sentences.&lt;/p&gt;

&lt;p&gt;In my opinion, with a short explanation like this and ready-to-use solutions in popular languages such as C++, Java, Python, JavaScript, and TypeScript, a reader can analyze the code and understand the solution on their own. I think this can be more useful than simply reading a complete step-by-step explanation where everything has already been explained for them.&lt;br&gt;
Still, I think I will experiment with both formats in the future.&lt;br&gt;
But I don't think the format is the main reason why being near the top of the search results doesn't bring much traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The main reason, in my opinion, is AI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgev6e6g3qxo6mq8n17zw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgev6e6g3qxo6mq8n17zw.png" alt="AI block for google search" width="799" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get a solution to almost any coding problem in almost any programming language in a few seconds, together with a detailed explanation of how the solution works and why it works.&lt;br&gt;
Even when AI gives links to websites where you can read a more detailed explanation, the answer generated directly by AI is probably enough for most users. They simply don't need to click another link.&lt;br&gt;
On top of that, if the search results already have two strong competitors and a YouTube video block above you, the chances that even an interested user will scroll down and click the third, fourth, or fifth result become much lower.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I still don't know whether AlgoBytes will be worth the time I put into it. But that's exactly why I'm continuing the experiment.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>algorithms</category>
      <category>leetcode</category>
      <category>interview</category>
    </item>
    <item>
      <title>LeetCode 4000 - 4010 problems: patterns and approaches explained</title>
      <dc:creator>0not0</dc:creator>
      <pubDate>Tue, 15 Sep 2026 08:10:28 +0000</pubDate>
      <link>https://dev.to/0not0/leetcode-4000-4010-problems-patterns-and-approaches-explained-3cig</link>
      <guid>https://dev.to/0not0/leetcode-4000-4010-problems-patterns-and-approaches-explained-3cig</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F16nuazsst62d7lk6ayug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F16nuazsst62d7lk6ayug.png" alt="LeetCode 4000 - 4010 problems: patterns and approaches explained image" width="800" height="533"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;LeetCode has started publishing problems numbered &lt;strong&gt;4000&lt;/strong&gt; and above. At the time of writing this post, there are already &lt;strong&gt;4055&lt;/strong&gt; problems.&lt;br&gt;
In this post, I’ll take a look at the first of them, from &lt;strong&gt;4000&lt;/strong&gt; to &lt;strong&gt;4010&lt;/strong&gt; (except &lt;strong&gt;4004&lt;/strong&gt;, &lt;strong&gt;4005&lt;/strong&gt;), including the difficulty level of each problem and the patterns that can be used to solve it.&lt;br&gt;
There are no solutions here, so you can try to solve these problems on your own using the suggested patterns as hints before looking at the actual solutions.&lt;/p&gt;

&lt;p&gt;Here:&lt;br&gt;
&lt;strong&gt;Easy&lt;/strong&gt; level: 4000, 4006, 4010&lt;br&gt;
&lt;strong&gt;Medium&lt;/strong&gt; level: 4001, 4002, 4008&lt;br&gt;
&lt;strong&gt;Hard&lt;/strong&gt; level: 4003, 4007, 4009&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/largest-integer-with-given-digit-sum/" rel="noopener noreferrer"&gt;4000. Largest Integer With Given Digit Sum&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy&lt;/strong&gt; level&lt;br&gt;
This is a &lt;strong&gt;numbers&lt;/strong&gt; (&lt;strong&gt;digit manipulation&lt;/strong&gt;) problem. We need to construct the largest number with at most n digits whose digit sum is equal to &lt;strong&gt;s&lt;/strong&gt;.&lt;br&gt;
To make the number as large as possible, we need to place the largest possible digits on the left - first &lt;strong&gt;9&lt;/strong&gt;, then the remainder, and then &lt;strong&gt;0&lt;/strong&gt;s.&lt;br&gt;
If &lt;strong&gt;s &amp;gt; 9 * n&lt;/strong&gt;, it is impossible to construct such a number.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Greedy, Digit Construction (Math)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://algobytes.net/blog/leetcode-4000-solution/" rel="noopener noreferrer"&gt;Check the solution here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/aggregate-two-time-series/" rel="noopener noreferrer"&gt;4001. Aggregate Two Time Series&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Medium&lt;/strong&gt; level&lt;br&gt;
This is an &lt;strong&gt;array&lt;/strong&gt; (&lt;strong&gt;merge two sorted arrays&lt;/strong&gt;) problem. We need to iterate through two time series and, for each timestamp, calculate the sum of the values from both series. Since both arrays are already sorted by &lt;strong&gt;timestamp&lt;/strong&gt;, the best approach is to move two pointers through &lt;strong&gt;series1&lt;/strong&gt; and &lt;strong&gt;series2&lt;/strong&gt; simultaneously.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n+m)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(n+m)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Two Pointers, Merge Sorted Arrays, Forward Fill or Next Available Value  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://algobytes.net/blog/leetcode-4001-solution/" rel="noopener noreferrer"&gt;Check the solution here&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/count-valid-sequences/" rel="noopener noreferrer"&gt;4002. Count Valid Sequences&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Medium&lt;/strong&gt; level&lt;br&gt;
This is a &lt;strong&gt;combinatorics&lt;/strong&gt; (&lt;strong&gt;integer compositions problem&lt;/strong&gt;). We need to count the number of sequences of &lt;strong&gt;k&lt;/strong&gt; positive integers with sum &lt;strong&gt;n&lt;/strong&gt; whose product is &lt;strong&gt;even&lt;/strong&gt;.&lt;br&gt;
The key idea is to count all sequences with sum &lt;strong&gt;n&lt;/strong&gt; and then subtract those where &lt;strong&gt;all numbers are odd&lt;/strong&gt;, because this is the only case where the product is odd.&lt;/p&gt;

&lt;p&gt;Complexity for the standard solution using &lt;strong&gt;factorials&lt;/strong&gt;:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Combinatorics, Stars and Bars, Parity Counting, Modular Arithmetic  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://algobytes.net/blog/leetcode-4002-solution/" rel="noopener noreferrer"&gt;Check the solution here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/minimum-cost-path-with-alternating-directions-iii/" rel="noopener noreferrer"&gt;4003. Minimum Cost Path with Alternating Directions III&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hard&lt;/strong&gt; level&lt;br&gt;
This is a &lt;strong&gt;graph&lt;/strong&gt; (&lt;strong&gt;shortest path in a grid&lt;/strong&gt;) problem. The state depends not only on the cell &lt;strong&gt;(i, j)&lt;/strong&gt;, but also on the parity of the next action.&lt;br&gt;
So, each cell is effectively represented by two states: &lt;strong&gt;(i, j, odd)&lt;/strong&gt; and &lt;strong&gt;(i, j, even)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(m*n * log(m*n))&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(m*n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Dijkstra, State Graph, Grid Shortest Path, Parity State&lt;/p&gt;

&lt;p&gt;&lt;a href="https://algobytes.net/blog/leetcode-4003-solution/" rel="noopener noreferrer"&gt;Check the solution here&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/count-valid-prefixes/" rel="noopener noreferrer"&gt;4006. Count Valid Prefixes&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy&lt;/strong&gt; level&lt;br&gt;
This is a &lt;strong&gt;strings&lt;/strong&gt; (&lt;strong&gt;prefix counting&lt;/strong&gt;) problem. For each prefix, we need to check whether its characters can be rearranged to form an alternating string.&lt;br&gt;
The key condition is that, for an alternating binary string, the number of &lt;strong&gt;0&lt;/strong&gt;s and &lt;strong&gt;1&lt;/strong&gt;s can differ by &lt;strong&gt;at most 1&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Prefix Counting, Frequency Counting, Parity / Balance Check&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/widest-possible-fence/" rel="noopener noreferrer"&gt;4007. Widest Possible Fence&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hard&lt;/strong&gt; level&lt;br&gt;
This is an &lt;strong&gt;arrays&lt;/strong&gt; (&lt;strong&gt;counting&lt;/strong&gt;) problem. We need to find a height h that allows us to obtain the maximum number of boards, either by using existing boards of height h or by combining pairs of boards whose heights sum to &lt;strong&gt;h&lt;/strong&gt;.&lt;br&gt;
For each pair of different heights &lt;strong&gt;x&lt;/strong&gt; and &lt;strong&gt;y&lt;/strong&gt;, the contribution to height &lt;strong&gt;x + y&lt;/strong&gt; is &lt;strong&gt;min(count[x], count[y])&lt;/strong&gt;. For equal heights &lt;strong&gt;x + x&lt;/strong&gt;, we can create &lt;strong&gt;count[x] / 2&lt;/strong&gt; boards. Existing boards of height &lt;strong&gt;x&lt;/strong&gt; are also added directly to the result for that height.&lt;/p&gt;

&lt;p&gt;Complexity in worst case:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Frequency Counting, Hash Map, Pair Sum / Two Sum, Enumeration&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/minimum-initial-strength-to-defeat-all-monsters/" rel="noopener noreferrer"&gt;4008. Minimum Initial Strength to Defeat All Monsters&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Medium&lt;/strong&gt; level&lt;br&gt;
This is an &lt;strong&gt;arrays&lt;/strong&gt; (&lt;strong&gt;range updates, prefix sums&lt;/strong&gt;) problem. First, we need to calculate the total bonus for each monster, and then determine the minimum initial strength required to defeat all monsters from left to right.&lt;br&gt;
Using a &lt;strong&gt;Difference Array pattern&lt;/strong&gt; lets us apply all boosts &lt;strong&gt;[l, r, v]&lt;/strong&gt; in &lt;strong&gt;O(n + boosts.length)&lt;/strong&gt; time without processing each range separately.&lt;br&gt;
For each &lt;strong&gt;i&lt;/strong&gt;, we effectively determine the minimum initial strength that would have been required, taking into account the strength already spent and the temporary bonus.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n+b)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Difference Array, Prefix Sum, Prefix Maximum / Greedy&lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/minimum-possible-maximum-waiting-time/" rel="noopener noreferrer"&gt;4009. Minimum Possible Maximum Waiting Time&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hard&lt;/strong&gt; level&lt;br&gt;
This is a &lt;strong&gt;dynamic programming&lt;/strong&gt; (&lt;strong&gt;scheduling with two resources&lt;/strong&gt;) problem. We need to assign cars to one of two dispensers so that we first maximize the number of cars served and, among those solutions, minimize the maximum waiting time.&lt;br&gt;
The DP state needs to track how much fuel remains in both dispensers, when each dispenser becomes available, and the waiting time accumulated so far.&lt;br&gt;
Because of the small constraints &lt;strong&gt;fuel[j] &amp;lt;= 50&lt;/strong&gt; and &lt;strong&gt;demand[i] &amp;lt;= 20&lt;/strong&gt;, we can build a DP over the possible states of the two dispensers.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n*F&lt;sup&gt;2&lt;/sup&gt;)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(F&lt;sup&gt;2&lt;/sup&gt;)&lt;/code&gt;&lt;br&gt;
Here, &lt;strong&gt;F &amp;lt;= 50&lt;/strong&gt; is the maximum fuel capacity of a single dispenser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Dynamic Programming, State Compression, Scheduling, Minimax Optimization &lt;/p&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/maximize-pair-strength-using-gcd/" rel="noopener noreferrer"&gt;4010. Maximize Pair Strength Using GCD&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy&lt;/strong&gt; level&lt;br&gt;
This is an &lt;strong&gt;arrays&lt;/strong&gt; (&lt;strong&gt;number theory&lt;/strong&gt;) problem. We need to iterate over pairs of numbers and maximize a value that depends on their product and &lt;strong&gt;gcd&lt;/strong&gt;.&lt;br&gt;
For each pair &lt;strong&gt;(i, j)&lt;/strong&gt;, we calculate &lt;strong&gt;gcd(nums[i], nums[j])&lt;/strong&gt; and the corresponding strength.&lt;/p&gt;

&lt;p&gt;Complexity should be:&lt;br&gt;
&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n&lt;sup&gt;2&lt;/sup&gt; log M)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Here, &lt;strong&gt;M = max(nums[i])&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns:&lt;/strong&gt; Greatest Common Divisor (GCD), Number Theory, Pair Enumeration&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>datastructures</category>
      <category>interview</category>
    </item>
    <item>
      <title>LeetCode 1 Two Sum: Imperative C++/Java vs Functional Elixir</title>
      <dc:creator>0not0</dc:creator>
      <pubDate>Fri, 11 Sep 2026 09:29:42 +0000</pubDate>
      <link>https://dev.to/0not0/leetcode-1-two-sum-imperative-cjava-vs-functional-elixir-1a6e</link>
      <guid>https://dev.to/0not0/leetcode-1-two-sum-imperative-cjava-vs-functional-elixir-1a6e</guid>
      <description>&lt;p&gt;&lt;strong&gt;First of all, I'm not an Elixir developer, so maybe someone can solve this problem in a more optimal way&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can find the original post &lt;a href="https://algobytes.net/leetcode-1-elixir-solution/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the problem description and solutions in all programming languages supported by LeetCode &lt;a href="https://github.com/0not0/algorithms/blob/master/leetcode/1-100/1.%20Two%20Sum/solution.md" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The general approach for different programming languages is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For the current &lt;strong&gt;nums[i]&lt;/strong&gt;, calculate &lt;strong&gt;target - nums[i]&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Check whether we have seen this number before.&lt;/li&gt;
&lt;li&gt;If yes, return the two indices.&lt;/li&gt;
&lt;li&gt;If not, store the current number and its index.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What is more interesting is the difference in implementation in C++ or Java and Elixir.&lt;br&gt;
The biggest conceptual difference here is between the &lt;strong&gt;imperative style&lt;/strong&gt; of C++/Java and the &lt;strong&gt;functional style&lt;/strong&gt; of Elixir with recursion and immutable data.&lt;br&gt;&lt;br&gt;
Let's see two solutions: on Java and Elixir.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java&lt;/strong&gt;&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="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;twoSum&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="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;)&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;Integer&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="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;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="o"&gt;{&lt;/span&gt;
      &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target&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;i&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;

      &lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;index&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;val&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;index&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&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;index&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;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;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="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;return&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="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;&lt;strong&gt;Elixir&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;Solution&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;@spec&lt;/span&gt; &lt;span class="n"&gt;two_sum&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="n"&gt;integer&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="n"&gt;integer&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;integer&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;two_sum&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;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;find&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;target&lt;/span&gt;&lt;span class="p"&gt;,&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="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;defp&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;map&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;do&lt;/span&gt;
    &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&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="ss"&gt;:error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&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;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="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;defp&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;([],&lt;/span&gt; &lt;span class="n"&gt;_target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_map&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;do&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see the difference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;strong&gt;C++&lt;/strong&gt; and &lt;strong&gt;Java&lt;/strong&gt; use a loop &lt;strong&gt;for&lt;/strong&gt;. &lt;strong&gt;Elixir&lt;/strong&gt;, on the other hand, uses &lt;strong&gt;recursion&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each recursive call processes one element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means: &lt;strong&gt;num&lt;/strong&gt; is the first element of the list, &lt;strong&gt;rest&lt;/strong&gt; is all remaining elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Another important difference is immutability.  &lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;C++&lt;/strong&gt;&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="n"&gt;map&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;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;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we change the existing &lt;code&gt;unordered_map&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Java&lt;/strong&gt;&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="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;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="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we also change existing &lt;strong&gt;Map&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;In Elixir &lt;strong&gt;map&lt;/strong&gt; doesn't change and &lt;strong&gt;Map.put&lt;/strong&gt; returns new &lt;strong&gt;map&lt;/strong&gt;, we pass it to the next recursive call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&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;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&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;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; The difference in search.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C++&lt;/strong&gt;&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;auto&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&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;it&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;map&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Java&lt;/strong&gt;&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="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;index&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;val&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;index&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;strong&gt;Elixir&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="ss"&gt;:error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Map.fetch/2&lt;/strong&gt; explicitly returns one of two possible results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt;
&lt;span class="ss"&gt;:error&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is why &lt;strong&gt;case&lt;/strong&gt; is very useful in this situation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But we also have a solution without recursion using built-in Enum functions:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;Solution&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;@spec&lt;/span&gt; &lt;span class="n"&gt;two_sum&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="n"&gt;integer&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="n"&gt;integer&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;integer&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;two_sum&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;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;nums&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;with_index&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reduce_while&lt;/span&gt;&lt;span class="p"&gt;(%{},&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;num&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;map&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
      &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;

      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:halt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&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="ss"&gt;:error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:cont&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&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;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference is in the way we iterate:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manual tail recursion&lt;/strong&gt; - we control the transition to the next element yourself through a recursive call.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Enum abstraction&lt;/strong&gt; - iteration is handled by built-in &lt;strong&gt;Enum&lt;/strong&gt; functions such as &lt;strong&gt;Enum.with_index()&lt;/strong&gt; and &lt;strong&gt;Enum.reduce_while()&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>elixir</category>
      <category>java</category>
    </item>
    <item>
      <title>LeetCode 3870 &amp; 3871: from a simple to a general solution</title>
      <dc:creator>0not0</dc:creator>
      <pubDate>Thu, 10 Sep 2026 05:34:59 +0000</pubDate>
      <link>https://dev.to/0not0/leetcode-3870-3871-from-a-simple-to-a-general-solution-ac9</link>
      <guid>https://dev.to/0not0/leetcode-3870-3871-from-a-simple-to-a-general-solution-ac9</guid>
      <description>&lt;p&gt;LeetCode problems &lt;a href="https://algobytes.net/blog/leetcode-3870-solution/" rel="noopener noreferrer"&gt;3870&lt;/a&gt; and &lt;a href="https://algobytes.net/blog/leetcode-3871-solution/" rel="noopener noreferrer"&gt;3871&lt;/a&gt; clearly show the transition from a simple case to a generalized one depending on the constraints. &lt;strong&gt;I would say this is a good example of why you should always ask about the problem constraints.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The problems are very similar, but different constraints lead to completely different solutions.&lt;/p&gt;

&lt;p&gt;Both problems have the same description:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You are given an integer &lt;code&gt;n&lt;/code&gt;.&lt;br&gt;
Return the &lt;strong&gt;total&lt;/strong&gt; number of commas used when writing all integers from &lt;code&gt;[1, n]&lt;/code&gt; (inclusive) in &lt;strong&gt;standard&lt;/strong&gt; number formatting.&lt;br&gt;
In &lt;strong&gt;standard&lt;/strong&gt; formatting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A comma is inserted after every three digits from the right.&lt;/li&gt;
&lt;li&gt;Numbers with fewer than 4 digits contain no commas.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;And the answer to which solution we should choose lies in the constraints themselves.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;3870&lt;/strong&gt; constrain is &lt;code&gt;1 &amp;lt;= n &amp;lt;= 10&lt;sup&gt;5&lt;/sup&gt;&lt;/code&gt;&lt;br&gt;
For &lt;strong&gt;3871&lt;/strong&gt; constrain is &lt;code&gt;1 &amp;lt;= n &amp;lt;= 10&lt;sup&gt;15&lt;/sup&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3870. Count Commas in Range I&lt;/strong&gt;: the constraints allow us to take advantage of the fact that each number can have at most one comma - a simple solution.&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="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt;  &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="n"&gt;commas&lt;/span&gt;
&lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;comma&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is why we use &lt;strong&gt;max(0, n - 999)&lt;/strong&gt; in the solution.&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;countCommas&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;n&lt;/span&gt;&lt;span class="p"&gt;)&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;999&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;&lt;strong&gt;3871. Count Commas in Range II&lt;/strong&gt;: &lt;strong&gt;n&lt;/strong&gt; can be much larger (&lt;code&gt;n &amp;lt;= 10&lt;sup&gt;15&lt;/sup&gt;&lt;/code&gt; ), so numbers can contain &lt;code&gt;2&lt;/code&gt;, &lt;code&gt;3&lt;/code&gt;, &lt;code&gt;4&lt;/code&gt;, or &lt;code&gt;5&lt;/code&gt; commas, which requires a more general solution.&lt;/p&gt;

&lt;p&gt;The idea from LeetCode 3870 is no longer enough for LeetCode 3871 because numbers can now contain more than one comma.&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="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mo"&gt;000&lt;/span&gt;          &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;comma&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mo"&gt;000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mo"&gt;000&lt;/span&gt;      &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;additional&lt;/span&gt; &lt;span class="n"&gt;comma&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mo"&gt;000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mo"&gt;000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mo"&gt;000&lt;/span&gt;  &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;additional&lt;/span&gt; &lt;span class="n"&gt;comma&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Need to understand&lt;/strong&gt;: for 3871 due to the specific constraint, the loop runs only a few times at most, so within the given constraints, it can also be considered constant-time bounded work.&lt;/p&gt;

&lt;p&gt;Since a new comma appears every three additional digits we have &lt;code&gt;start *= 1000&lt;/code&gt;.&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;long&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;countCommas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;result&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;long&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
      &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&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>algorithms</category>
      <category>jobinterview</category>
      <category>programming</category>
    </item>
    <item>
      <title>Essential coding interview preparation tips you should know before you start</title>
      <dc:creator>0not0</dc:creator>
      <pubDate>Mon, 07 Sep 2026 12:06:30 +0000</pubDate>
      <link>https://dev.to/0not0/essential-coding-interview-preparation-tips-you-should-know-before-you-start-c09</link>
      <guid>https://dev.to/0not0/essential-coding-interview-preparation-tips-you-should-know-before-you-start-c09</guid>
      <description>&lt;h2&gt;
  
  
  What you need to understand before you start preparing for a Coding Interview
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7caho321q0psok6ad10p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7caho321q0psok6ad10p.jpg" alt="coding interview preparation image" width="800" height="533"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Previously, I wrote about why you need to solve &lt;a href="https://algobytes.net/thoughts/leetcode-in-the-ai-era/" rel="noopener noreferrer"&gt;LeetCode problems in the AI era&lt;/a&gt;. And if you've decided to prepare for a coding interview, I hope these tips will be useful to you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;. You need to understand that you are spending your free time developing a purely practical skill that you will need only at the interview stage. That is what this skill is for - passing a specific stage of the interview process. Nothing more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;. You need to set a clear timeframe for your preparation and decide when you are going to start interviewing. You can prepare forever and still never feel completely confident that you are ready to solve coding interview problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third&lt;/strong&gt;, and this is closely related to the second point. During your preparation, you will constantly experience emotional ups and downs: I can do it - I can't do it. That is exactly why it is important to set a clear deadline for yourself. For example: I have three months to prepare, and then I enter the job market. When you have a fixed deadline, you reduce your chances of burning out during the preparation stage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fourth&lt;/strong&gt;. A clear deadline allows you to plan your preparation, while intermediate checkpoints allow you to adjust its direction. For example, you may be comfortable solving problems involving strings and arrays but struggle with Binary Search. In that case, add more Binary Search problems to your preparation and spend less time on strings and arrays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fifth&lt;/strong&gt;. You should accept that there will be problems you simply cannot solve on your own, especially during the early stages of preparation. This is completely normal. There is no reason to feel bad about it or think that it makes you a failure or a bad programmer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sixth&lt;/strong&gt;. Don't spend too much time trying to solve a single problem. If you cannot find a solution within an hour, there is usually no point in stubbornly sitting there trying to figure it out. Most likely, you will just waste your time without making much progress. Google, ChatGPT, or any other resource - use whatever helps you move forward. Your free time is limited. Don't waste it on stubbornness just because you feel that you have to prove something to yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Seventh&lt;/strong&gt;, and probably the most important point. Consistency is the foundation of the entire preparation process. Many people who start this coding interview preparation marathon never reach the finish line. And that is exactly what it is - a marathon that lasts several months. Only consistent, persistent, routine work every day can produce results. Motivation usually disappears after a few weeks. After that, what remains is the simple routine of solving LeetCode problems, accompanied by constant emotional ups and downs.&lt;/p&gt;

&lt;p&gt;You need to be ready for this.&lt;br&gt;
Before you start preparing, ask yourself whether you are really ready to invest your free time for several months into this emotional marathon. But you should also remember why you are developing this coding interview problem-solving skill in the first place. Behind it may be new professional opportunities, better career prospects, and possibilities that are currently unavailable to you. And all you need to do to reach them is finish this marathon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And most importantly, that part depends entirely on you&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>interview</category>
      <category>leetcode</category>
      <category>career</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why do you need to solve LeetCode problems in the AI era?</title>
      <dc:creator>0not0</dc:creator>
      <pubDate>Sun, 06 Sep 2026 13:18:53 +0000</pubDate>
      <link>https://dev.to/0not0/why-do-you-need-to-solve-leetcode-problems-in-the-ai-era-1g08</link>
      <guid>https://dev.to/0not0/why-do-you-need-to-solve-leetcode-problems-in-the-ai-era-1g08</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frvyxs1gt18ywk7kymxm1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frvyxs1gt18ywk7kymxm1.png" alt="solving hard LeetCode problem in flipchart" width="800" height="533"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;I often hear and read on forums and in my LinkedIn feed that solving coding problems yourself, such as LeetCode problems, is the old way, and AI can do it quickly and accurately. And that's absolutely true. AI can solve a hard-level problem in one minute, while a trained person doing it may take much longer, and their solution is more likely to be suboptimal. But AI writes code faster and more efficiently than the average programmer. So, does that mean we shouldn't write code at all? This is a controversial question. &lt;/p&gt;

&lt;p&gt;If solving LeetCode-style problems is a hobby for someone, obviously they will keep doing it regardless of how much faster and more efficiently AI can solve them, or whether AI exists at all. But a lot of people spend a lot of time solving LeetCode-style problems, not out of love for them.   &lt;/p&gt;

&lt;p&gt;We can rewrite this question: &lt;strong&gt;Why do we need to solve LeetCode problems in the AI era?&lt;/strong&gt; on: &lt;strong&gt;Why do we need to spend our free time solving LeetCode-style problems in the AI era?&lt;/strong&gt; Or much more detailed:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why do we need to spend our limited free time solving LeetCode-style problems in the AI era instead of spending it with our families, pursuing our hobbies, or doing something else?   &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Why spend time on LeetCode problems in the AI era?
&lt;/h3&gt;

&lt;p&gt;Time is a very valuable resource. We need a good reason to spend it solving algorithmic coding problems. And the only real motivation for doing it is finding a job and preparing for job interviews. This is what forces a lot of people to put off other, much more enjoyable things and solve coding interview problems instead. Even now, LeetCode-style problems still exist and, in many cases, are part of the interview process for many IT professionals. From my point of view, preparing for job interviews is the only reason why we need to spend our free time solving algorithmic coding problems. The skill of solving such tasks quickly is almost never needed in day-to-day work.   &lt;/p&gt;

&lt;p&gt;We can develop the ability to structure our thoughts without spending time on a skill that we won't need in our actual work. The ability to write compact code, which you develop after solving enough LeetCode-style problems, is more of a disadvantage than an advantage in real-world projects. What matters there is not brevity, but code readability. The ability to use data structures in practice? Yes, that's a valid point, but this skill can also be developed by solving real-world problems. The ability to analyze algorithmic complexity? If you really need it in your job, you'll know how to do it. If you don't, you won't.  &lt;/p&gt;

&lt;p&gt;In addition, we need to understand that solving LeetCode problems is a skill. And like any other skill, it fades if you don't practice it regularly. Motivation can't last forever either. &lt;br&gt;
So, to repeat my point, &lt;strong&gt;the only reason to solve algorithmic coding problems in the AI era is to pass one of the stages of the interview process and get a job&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  LeetCode as a skill for technical interview preparation
&lt;/h3&gt;

&lt;p&gt;The ability to pass job interviews is a separate skill that has little to do with what you will actually be doing at work. And this skill needs to be practiced too. An interviewer has very limited time - an hour or two - to decide whether you are a good fit. The better you present yourself, the better your chances of moving forward in the interview process. &lt;/p&gt;

&lt;p&gt;And as long as different variations of LeetCode-style problems are used in job interviews, people will continue to invest their free time and effort in learning how to solve these problems as quickly as possible and with the most optimal solution they can find. Because in this case, they aren't simply wasting their free time - they are investing it in their future.  &lt;/p&gt;

&lt;p&gt;It should be a focused push for a few months. A period with a clear beginning and end, and a &lt;a href="https://algobytes.net/thoughts/coding-interview-preparation-tips-you-should-know" rel="noopener noreferrer"&gt;strictly defined deadline&lt;/a&gt;. Only in this case will the time and effort spent on LeetCode problems be an investment that pays off rather than time wasted for nothing.  &lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://algobytes.net" rel="noopener noreferrer"&gt;https://algobytes.net&lt;/a&gt;  &lt;/p&gt;

</description>
      <category>ai</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>leetcode</category>
    </item>
  </channel>
</rss>
