<?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: BMega</title>
    <description>The latest articles on DEV Community by BMega (@bmega).</description>
    <link>https://dev.to/bmega</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%2F2400971%2F006c446b-9f3c-404c-b698-881291f49e0b.png</url>
      <title>DEV Community: BMega</title>
      <link>https://dev.to/bmega</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bmega"/>
    <language>en</language>
    <item>
      <title>Is AI Ready to Replace Software Developers?</title>
      <dc:creator>BMega</dc:creator>
      <pubDate>Sat, 01 Feb 2025 13:51:21 +0000</pubDate>
      <link>https://dev.to/bmega/is-ai-ready-to-replace-software-developers-3h19</link>
      <guid>https://dev.to/bmega/is-ai-ready-to-replace-software-developers-3h19</guid>
      <description>&lt;p&gt;We are currently in the AI bubble. AI is the new buzzword being thrown into every conversation lately.&lt;br&gt;&lt;br&gt;
We now have Deepseek, which seems to be better than ChatGPT. Multiple AI startups and evangelists have emerged, all claiming that AI is the future and will replace many existing jobs, including software developers. Being a software engineer myself, I was curious to know if AI is really ready to replace me.  &lt;/p&gt;

&lt;p&gt;First, I've been an avid user of ChatGPT, and I can attest that it has indeed improved my productivity — from brainstorming ideas to solving bugs. But it's not perfect. It still requires a lot of correction and refinement. This is where another popular buzzword comes in &lt;strong&gt;Prompt Engineering&lt;/strong&gt;. Prompt engineering is the process of refining prompts to get the desired output. This is a tedious process and still requires human intervention.  &lt;/p&gt;

&lt;p&gt;I stumbled upon a startup called &lt;a href="https://lovable.dev/" rel="noopener noreferrer"&gt;Lovable.dev&lt;/a&gt;, which claims to be a &lt;strong&gt;superhuman&lt;/strong&gt; full-stack engineer. The process of using it is quite simple—just prompt it to create anything, and it will generate a Git repository with the code, which you can then add to your own GitHub account. It also has the ability to create a database on &lt;a href="https://supabase.com/" rel="noopener noreferrer"&gt;Supabase&lt;/a&gt; and connect it to your app. I decided to test it out by creating a simple chatbot app that:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allows users to log in via email providers and regular email/password authentication
&lt;/li&gt;
&lt;li&gt;Uses the ChatGPT Assistant API for message responses
&lt;/li&gt;
&lt;li&gt;Saves the message history for each user
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sounds simple, right?&lt;br&gt;&lt;br&gt;
I was impressed by how fast it created the app, but this didn't come without bugs and errors—though, surprisingly, it did attempt to self-correct. It took multiple prompts to get everything right, but still, the results were impressive. Even though the app was very lean and bare-bones, it was a good starting point for a POC or MVP.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Who is this for?
&lt;/h3&gt;

&lt;p&gt;This is for non-technical founders or PMs who want to quickly prototype an idea before committing an entire dev team or sprint to it.  &lt;/p&gt;

&lt;p&gt;Given the simple app I built, if I wanted to add more complex features, it would be faster to do it myself rather than continuously prompting the AI. Secondly, &lt;strong&gt;context&lt;/strong&gt; is a huge factor in software development. AI does not have context regarding business requirements or users’ needs that are not explicitly documented—especially those that are implicit or inferred. It can only do what it's told, and this is where the &lt;strong&gt;human touch&lt;/strong&gt; comes in. For example, designing the data layer isn’t always straightforward.&lt;br&gt;&lt;br&gt;
Thirdly, most developers work on existing codebases, which requires a deep understanding of the architecture before making changes. Even though some AI agents can explain code, you still need context to understand how everything fits together to meet user needs.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;AI is not ready to replace software developers, but it can significantly speed up the development process.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Valid Anagram</title>
      <dc:creator>BMega</dc:creator>
      <pubDate>Fri, 27 Dec 2024 22:20:18 +0000</pubDate>
      <link>https://dev.to/bmega/valid-anagram-1hm1</link>
      <guid>https://dev.to/bmega/valid-anagram-1hm1</guid>
      <description>&lt;p&gt;This article will highlight two approaches to this problem&lt;/p&gt;

&lt;h2&gt;
  
  
  Question
&lt;/h2&gt;

&lt;p&gt;Leetcode link -&amp;gt; &lt;a href="https://leetcode.com/problems/valid-anagram/description/" rel="noopener noreferrer"&gt;https://leetcode.com/problems/valid-anagram/description/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given two strings s and t, return true if t is an anagram of s, and false otherwise.&lt;/p&gt;

&lt;p&gt;An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, &lt;br&gt;
typically using all the original letters exactly once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example 1:

Input: s = "anagram", t = "nagaram"
Output: true


Example 2:

Input: s = "rat", t = "car"
Output: false


Constraints:

1 &amp;lt;= s.length, t.length &amp;lt;= 5 * 104
s and t consist of lowercase English letters.

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Two approaches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For both approaches if the length of both strings is not equal return &lt;code&gt;False&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1.  &lt;strong&gt;Using Counters&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create two counters for each string&lt;/li&gt;
&lt;li&gt;loop through each string counting the number of occurrences for each character&lt;/li&gt;
&lt;li&gt;Compare the two counters and return the boolean output&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Complexity
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Time
&lt;/h5&gt;

&lt;p&gt;𝑂(𝑛)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;loop the two string (s and t) =  𝑂(𝑛) + 𝑂(𝑛)&lt;/li&gt;
&lt;li&gt;insertion into dict counters = 𝑂(1) + 𝑂(1)&lt;/li&gt;
&lt;li&gt;compare dicts = 𝑂(1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2𝑂(𝑛) + 3𝑂(1) = 𝑂(𝑛)&lt;/p&gt;

&lt;h5&gt;
  
  
  Space
&lt;/h5&gt;

&lt;p&gt;𝑂(1)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; 2 counters = 𝑂(1) + 𝑂(1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2𝑂(1)&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;isAnagram&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

        &lt;span class="n"&gt;s_counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="n"&gt;t_counter&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="n"&gt;char&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;s_counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;s_counter&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;char&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="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;s_counter&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;char&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t_counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;t_counter&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;char&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="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;t_counter&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;char&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s_counter&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;t_counter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. &lt;strong&gt;Using inbuilt sort method&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use python's inbuilt &lt;code&gt;sorted()&lt;/code&gt; method for each string&lt;/li&gt;
&lt;li&gt;Compare if the two sorted strings are equal&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Complexity
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Time
&lt;/h5&gt;

&lt;p&gt;𝑂(𝑛 log 𝑛 )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The python's &lt;code&gt;sorted()&lt;/code&gt; function uses a &lt;code&gt;Timsort algorithm&lt;/code&gt; = 𝑂(𝑛 log 𝑛 ) + 𝑂(𝑛 log 𝑛 )&lt;/li&gt;
&lt;li&gt;compare the two strings  = 𝑂(𝑛)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2𝑂(𝑛 log 𝑛 ) + 𝑂(𝑛) = 𝑂(𝑛 log 𝑛 )&lt;/p&gt;

&lt;h5&gt;
  
  
  Space
&lt;/h5&gt;

&lt;p&gt;𝑂(𝑛)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Sort function will create a new sorted string from the input string = 𝑂(𝑛) + 𝑂(𝑛)&lt;/li&gt;
&lt;li&gt;compare the two strings  = 𝑂(𝑛)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3𝑂(𝑛) = 𝑂(𝑛)&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;isAnagram&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&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>anagram</category>
      <category>100daysofcode</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>Two sum</title>
      <dc:creator>BMega</dc:creator>
      <pubDate>Sun, 10 Nov 2024 18:16:00 +0000</pubDate>
      <link>https://dev.to/bmega/two-sum-3l65</link>
      <guid>https://dev.to/bmega/two-sum-3l65</guid>
      <description>&lt;p&gt;This article will highlight two approaches the brute force and the efficient approach&lt;/p&gt;

&lt;h3&gt;
  
  
  Question
&lt;/h3&gt;

&lt;p&gt;Leetcode link -&amp;gt; &lt;a href="https://leetcode.com/problems/two-sum/description/" rel="noopener noreferrer"&gt;https://leetcode.com/problems/two-sum/description/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.&lt;/p&gt;

&lt;p&gt;You may assume that each input would have exactly one solution, and you may not use the same element twice.&lt;/p&gt;

&lt;p&gt;You can return the answer in any order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example 1

Input: nums = [2,7,11,15], target = 9
Output: [0,1]

Explanation: Because nums[0] + nums[1] == 9, 
we return [0, 1].

Example 2:

Input: nums = [3,2,4], target = 6
Output: [1,2]


Example 3:

Input: nums = [3,3], target = 6
Output: [0,1]


Constraints:

2 &amp;lt;= nums.length &amp;lt;= 104
-109 &amp;lt;= nums[i] &amp;lt;= 109
-109 &amp;lt;= target &amp;lt;= 109
Only one valid answer exists.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow-up: Can you come up with an algorithm that is less than 𝑂( 𝑛 &lt;sup&gt;2&lt;/sup&gt; ) time complexity?&lt;/p&gt;

&lt;h2&gt;
  
  
  Brute Force
&lt;/h2&gt;

&lt;p&gt;Use double for loop, for each value add the values and check if they equal the target&lt;/p&gt;

&lt;h3&gt;
  
  
  Complexity
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Time
&lt;/h4&gt;

&lt;p&gt;𝑂( 𝑛 &lt;sup&gt;2&lt;/sup&gt; )&lt;/p&gt;

&lt;p&gt;Since its a double for loop, each element is paired with every other element exactly once&lt;/p&gt;

&lt;h5&gt;
  
  
  Space
&lt;/h5&gt;

&lt;p&gt;𝑂( &lt;em&gt;1&lt;/em&gt; )&lt;/p&gt;

&lt;p&gt;This approach does not use any extra data structures that grow with the size of the input.&lt;/p&gt;

&lt;p&gt;which means it is constant space.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&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="nf"&gt;len&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="nf"&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;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;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;]&lt;/span&gt; &lt;span class="o"&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;return&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;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Efficient approach
&lt;/h2&gt;

&lt;p&gt;Use a hashmap&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use one for loop and enumerate list&lt;/li&gt;
&lt;li&gt;target minus each element &lt;/li&gt;
&lt;li&gt;if compliment in hashmap return the index of the compliment in the hashmap and the current index in loop&lt;/li&gt;
&lt;li&gt;else add element as key and index as value&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Complexity
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Time
&lt;/h4&gt;

&lt;p&gt;𝑂(𝑛)&lt;/p&gt;

&lt;p&gt;Because we traverse the list once, and dictionary operations (insertion and lookup) are &lt;em&gt;O( 1 )&lt;/em&gt; on average&lt;/p&gt;

&lt;h5&gt;
  
  
  Space
&lt;/h5&gt;

&lt;p&gt;𝑂(𝑛)&lt;/p&gt;

&lt;p&gt;In the worst case, if there are no two numbers that sum up to the target, every element will be stored in the hash map.&lt;br&gt;
Therefore, the space complexity is 𝑂(𝑛) where 𝑛 is the number of elements in the list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;twoSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&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;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&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="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="n"&gt;two_hash&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="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&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;compliment&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;if&lt;/span&gt; &lt;span class="n"&gt;compliment&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;two_hash&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;two_hash&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;compliment&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;two_hash&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>leetcode</category>
      <category>blind75</category>
      <category>interview</category>
      <category>twosum</category>
    </item>
  </channel>
</rss>
