<?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: Mostafa Said</title>
    <description>The latest articles on DEV Community by Mostafa Said (@mostafa_samir).</description>
    <link>https://dev.to/mostafa_samir</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%2F2357441%2Fe1e499b6-3496-42bb-82cd-a5ca5aa37efc.jpeg</url>
      <title>DEV Community: Mostafa Said</title>
      <link>https://dev.to/mostafa_samir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mostafa_samir"/>
    <language>en</language>
    <item>
      <title>Two Sum in C# – From Brute Force to Optimal Hash Map &amp; Beyond</title>
      <dc:creator>Mostafa Said</dc:creator>
      <pubDate>Wed, 18 Jun 2025 19:59:38 +0000</pubDate>
      <link>https://dev.to/mostafa_samir/two-sum-in-c-from-brute-force-to-optimal-hash-map-beyond-4kph</link>
      <guid>https://dev.to/mostafa_samir/two-sum-in-c-from-brute-force-to-optimal-hash-map-beyond-4kph</guid>
      <description>&lt;h2&gt;
  
  
  🔍 Problem Description
&lt;/h2&gt;

&lt;p&gt;Given an integer array &lt;code&gt;nums&lt;/code&gt; and an integer &lt;code&gt;target&lt;/code&gt;, return the &lt;strong&gt;indices&lt;/strong&gt; of the two numbers whose sum equals &lt;code&gt;target&lt;/code&gt;. You may assume exactly one solution exists and you can't use the same element twice.&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.amazonaws.com%2Fuploads%2Farticles%2Fr943up6jslgj9hpkxk0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr943up6jslgj9hpkxk0k.png" alt=" " width="800" height="582"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;TwoSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nums = [2,7,11,15], target = 9  // → [0,1]
nums = [3,2,4],    target = 6   // → [1,2]
nums = [3,3],      target = 6   // → [0,1]

#### 🔁 1. Brute‑Force (Nested Loops)

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int[] TwoSumBrute(int[] nums, int target) {
    for (int i = 0; i &amp;lt; nums.Length; i++) {
        for (int j = i + 1; j &amp;lt; nums.Length; j++) {
            if (nums[i] + nums[j] == target)
                return new int[]{ i, j };
        }
    }
    return Array.Empty&amp;lt;int&amp;gt;();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;🕒 Time: O(n²) – checks every possible pair&lt;/li&gt;
&lt;li&gt;💾 Space: O(1) – constant space usage&lt;/li&gt;
&lt;li&gt;✅ Best for tiny arrays or as a conceptual starting point &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🗂️ 2. Two‑Pass Hash Map
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int[] TwoSumTwoPass(int[] nums, int target) {
    var map = new Dictionary&amp;lt;int, int&amp;gt;(nums.Length);
    for (int i = 0; i &amp;lt; nums.Length; i++)
        map[nums[i]] = i;

    for (int i = 0; i &amp;lt; nums.Length; i++) {
        int comp = target - nums[i];
        if (map.TryGetValue(comp, out int j) &amp;amp;&amp;amp; j != i)
            return new int[]{ i, j };
    }
    return Array.Empty&amp;lt;int&amp;gt;();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;🕒 Time: O(n) – two passes&lt;/li&gt;
&lt;li&gt;💾 Space: O(n) – storing elements in map &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🔥 3. One‑Pass Hash Map (Optimal)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int[] TwoSumOnePass(int[] nums, int target) {
    var map = new Dictionary&amp;lt;int, int&amp;gt;(nums.Length);
    for (int i = 0; i &amp;lt; nums.Length; i++) {
        int comp = target - nums[i];
        if (map.TryGetValue(comp, out int j))
            return new int[]{ j, i };
        map[nums[i]] = i;
    }
    return Array.Empty&amp;lt;int&amp;gt;();
}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;🕒 Time: O(n) – single traversal&lt;/li&gt;
&lt;li&gt;💾 Space: O(n) – map tracks seen values&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🧪 4. Benchmark Insights
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;“The brute force solution outperforms the Dictionary solution … for small or skewed inputs” &lt;/li&gt;
&lt;li&gt;“Arrays will be faster no matter the size. … dense buffers pretty often perform best” &lt;/li&gt;
&lt;li&gt;Reddit benchmarking shows brute force beating hash-map for small inputs, but hash-map scales much better on larger, randomized datasets &lt;/li&gt;
&lt;li&gt;stackoverflow.com&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📊 Quick Comparison Table
&lt;/h2&gt;

&lt;p&gt;Method  Time    Space   Ideal Use Case&lt;br&gt;
Brute Force O(n²)  O(1)    Tiny arrays, simple logic&lt;br&gt;
Two‑Pass Hash Map O(n)    O(n)    Good clarity, two-stage logic&lt;br&gt;
One‑Pass Hash Map O(n)    O(n)    Interview-friendly, single-scan optimal&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀 5. Visual Explanation
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &lt;a href="https://www.youtube.com/watch?time_continue=2&amp;amp;v=oVNznag_QOE&amp;amp;embeds_referring_euri=https%3A%2F%2Fchatgpt.com%2F&amp;amp;source_ve_path=MjM4NTE" rel="noopener noreferrer"&gt;link Youtube&lt;/a&gt;&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  🧠 6. Challenges &amp;amp; Extensions&lt;br&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;✅ Return all unique pairs — avoid duplicates using sets&lt;/li&gt;
&lt;li&gt;🎯 Adapt to streaming input — handle data in chunks&lt;/li&gt;
&lt;li&gt;📉 Space-optimized variant: sort + two-pointer, then map back indices&lt;/li&gt;
&lt;li&gt;⚡ Benchmark with BenchmarkDotNet — validate real-world performance&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;🟢 Brute Force: easiest but becomes impractical as n grows&lt;/li&gt;
&lt;li&gt;🟢 One-Pass Hash Map: balanced, efficient, ideal for interviews&lt;/li&gt;
&lt;li&gt;🎯 Always consider data size, distribution, and cache behavior when choosing your approach&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📝 Call to Action
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Implement all three methods in C# code.&lt;/li&gt;
&lt;li&gt;Benchmark them using BenchmarkDotNet across diverse datasets.&lt;/li&gt;
&lt;li&gt;Share surprising results—especially browser-based micro-benchmark behaviors 👇&lt;/li&gt;
&lt;li&gt;Need help setting up benchmarks, visual diagrams, or tackling streaming data? Just ask!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  🔗 References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://medium.com/@olegkomarov_77860/a-commented-journey-through-the-advent-of-code-2019-by-an-average-joe-257bbf4855d7" rel="noopener noreferrer"&gt;Reddit: brute-force vs dictionary benchmark insights medium.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/answers/detail/comparing-brute-force-vs-optimized-solutions-to-show-progression" rel="noopener noreferrer"&gt;DesignGurus: step-by-step from brute force to optimized solution junian.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/the-toit-take/hash-maps-that-dont-hate-you-1a96150b492a" rel="noopener noreferrer"&gt;Junian Network – hash map solution in C# meheedihasaan.medium.com&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Big Issues in Vue 3: What Developers Need to Know</title>
      <dc:creator>Mostafa Said</dc:creator>
      <pubDate>Mon, 03 Feb 2025 19:56:20 +0000</pubDate>
      <link>https://dev.to/mostafa_samir/big-issues-in-vue-3-what-developers-need-to-know-4ekj</link>
      <guid>https://dev.to/mostafa_samir/big-issues-in-vue-3-what-developers-need-to-know-4ekj</guid>
      <description>&lt;p&gt;Vue 3 has been out for a while now, and while it brings many improvements over Vue 2, it also comes with its own set of challenges. If you’re a Vue developer making the transition or considering Vue 3 for your next project, you should be aware of some key issues. In this post, we’ll discuss the biggest pain points developers have encountered with Vue 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Composition API Learning Curve
&lt;/h2&gt;

&lt;p&gt;The Composition API is one of the biggest changes in Vue 3. While it provides better code organization and reusability, many developers—especially those used to the Options API—find it difficult to grasp initially. The shift from the familiar data, methods, and computed structure to functions like setup() can be intimidating.&lt;/p&gt;

&lt;p&gt;Common issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher complexity for simple use cases.&lt;/li&gt;
&lt;li&gt;Harder to read for those unfamiliar with functional programming concepts.&lt;/li&gt;
&lt;li&gt;More boilerplate for small components.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Possible solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stick to the Options API when building simple components.&lt;/li&gt;
&lt;li&gt;Use a hybrid approach: gradually integrate the Composition API where needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Reactivity Caveats
&lt;/h2&gt;

&lt;p&gt;Vue 3’s new reactivity system, built on Proxies, is powerful but introduces some unexpected behavior, especially when dealing with reactivity tracking and nested objects.&lt;/p&gt;

&lt;p&gt;Common issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Losing reactivity when destructuring reactive objects.&lt;/li&gt;
&lt;li&gt;ref and reactive behaving differently than expected.&lt;/li&gt;
&lt;li&gt;Difficulties with deeply nested object mutations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Possible solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use toRefs() or toRef() when destructuring reactive objects.&lt;/li&gt;
&lt;li&gt;Understand when to use ref vs. reactive.&lt;/li&gt;
&lt;li&gt;Avoid excessive nesting of objects and consider normalizing data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Ecosystem &amp;amp; Library Support
&lt;/h2&gt;

&lt;p&gt;Although Vue 3 has been officially stable for a while, some popular libraries and third-party plugins took time to update. Some still lack full Vue 3 support or have breaking changes.&lt;/p&gt;

&lt;p&gt;Common issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Legacy Vue 2 libraries don’t work out of the box.&lt;/li&gt;
&lt;li&gt;Nuxt 2 doesn’t support Vue 3 (Nuxt 3 is needed but still evolving).&lt;/li&gt;
&lt;li&gt;Some UI frameworks (e.g., Vuetify) had delayed support.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Possible solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the Vue 3 compatibility of any library before using it.&lt;/li&gt;
&lt;li&gt;Consider alternatives like PrimeVue, Quasar, or BootstrapVue 3.&lt;/li&gt;
&lt;li&gt;If possible, contribute to open-source projects to speed up migrations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Suspense and Async Components Challenges
&lt;/h2&gt;

&lt;p&gt;Vue 3 introduced Suspense to handle async components more elegantly, but it has its own quirks and limitations.&lt;/p&gt;

&lt;p&gt;Common issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Doesn’t work well with server-side rendering (SSR).&lt;/li&gt;
&lt;li&gt;Requires careful structuring of async components to prevent blank screens.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Possible solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use fallbacks wisely.&lt;/li&gt;
&lt;li&gt;Ensure data fetching logic is properly handled to avoid unnecessary renders.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. TypeScript Adoption Difficulties
&lt;/h2&gt;

&lt;p&gt;Vue 3 has significantly better TypeScript support, but working with TypeScript in Vue can still be cumbersome.&lt;/p&gt;

&lt;p&gt;Common issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Steep learning curve for those new to TypeScript.&lt;/li&gt;
&lt;li&gt;Inconsistent typing when dealing with defineProps and defineEmits.&lt;/li&gt;
&lt;li&gt;Lack of comprehensive TypeScript documentation in Vue ecosystem.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Possible solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Volar instead of Vetur for better TypeScript support in Vue 3.&lt;/li&gt;
&lt;li&gt;Follow best practices for defining component props and emits.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Vue 3 is a powerful and evolving framework, but transitioning from Vue 2 or starting fresh with it requires understanding some key challenges. By being aware of these pain points and potential solutions, developers can make the most of Vue 3 while minimizing frustration.&lt;/p&gt;

&lt;p&gt;Are you facing any other issues with Vue 3? Let’s discuss in the comments!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
