<?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: Yoges</title>
    <description>The latest articles on DEV Community by Yoges (@yoges).</description>
    <link>https://dev.to/yoges</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%2F4111270%2F3c1e0a35-699f-4f01-add1-fd05b99c0403.jpg</url>
      <title>DEV Community: Yoges</title>
      <link>https://dev.to/yoges</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yoges"/>
    <language>en</language>
    <item>
      <title>Top K Frequent Elements</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Thu, 17 Sep 2026 16:08:13 +0000</pubDate>
      <link>https://dev.to/yoges/top-k-frequent-elements-klj</link>
      <guid>https://dev.to/yoges/top-k-frequent-elements-klj</guid>
      <description>&lt;p&gt;Today i try to solve &lt;strong&gt;Top K Frequent Elements&lt;/strong&gt; the problem is simple you need to return the k most frequent elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem:
&lt;/h2&gt;

&lt;p&gt;Given an integer array nums and an integer k, return the k most frequent elements within the array.&lt;/p&gt;

&lt;p&gt;The test cases are generated such that the answer is always unique.&lt;/p&gt;

&lt;p&gt;You may return the output in any order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution:
&lt;/h2&gt;

&lt;p&gt;I choose HashMap to track the frequency of the element&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%2Fa1gch1hzfium9bzauutg.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%2Fa1gch1hzfium9bzauutg.png" alt=" " width="468" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we need to take the largest k elements &lt;br&gt;
this is the tricky part&lt;/p&gt;

&lt;p&gt;How can i get the largest value(count of the element) from the map and store the exact k largest values?? &lt;/p&gt;

&lt;p&gt;Then i endup with Min Heap. But the challenge is store the key, value pairs in Priority Queue.&lt;br&gt;
For that i use map.entry to store in Priority Queue it compares the values in the map. It's sounds confusing but it too easy..&lt;/p&gt;

&lt;p&gt;JAVA code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int[] topKFrequent(int[] nums, int k) {
        HashMap&amp;lt;Integer, Integer&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
        //we have to return most frequent elements.Elements count should be k
        //ex: k=2 you have to return 2 element. that element should be have most frequency

        //step 1: store the element with frequency as a key, value pair in map
        for(int num : nums){
            map.put(num, map.getOrDefault(num, 0)+1);
        }

        //Use MinHeap to get the most frequent value
        // the will be store k elements if the size of pq &amp;gt; k we need remove smallest element so just use poll method to remove it.

        PriorityQueue&amp;lt;Map.Entry&amp;lt;Integer, Integer&amp;gt;&amp;gt; pq =
                    new PriorityQueue&amp;lt;&amp;gt;(
                        Comparator.comparingInt(Map.Entry::getValue) // pq compare the value here we are storing the map entry so we need to mentain which value should be compared here
                        //Here we need compare the values inorder to get the highest frequency
                    );

         for(Map.Entry&amp;lt;Integer, Integer&amp;gt; entry : map.entrySet()){
            pq.offer(entry);
            if(pq.size() &amp;gt; k){
                pq.poll();
            }
         }
         int[] ans = new int[k];
         int i = 0;
        // Then finally store it in array return it
         while(!pq.isEmpty()){
             Map.Entry&amp;lt;Integer, Integer&amp;gt; entry = pq.poll();
             ans[i++] = entry.getKey();
         }
         return ans;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>dsa</category>
      <category>java</category>
    </item>
    <item>
      <title>How i learn to how to learn?!😵</title>
      <dc:creator>Yoges</dc:creator>
      <pubDate>Wed, 16 Sep 2026 09:19:08 +0000</pubDate>
      <link>https://dev.to/yoges/how-i-learn-to-how-to-learn-4ilf</link>
      <guid>https://dev.to/yoges/how-i-learn-to-how-to-learn-4ilf</guid>
      <description>&lt;p&gt;I learned about HTML, CSS, JS.&lt;/p&gt;

&lt;p&gt;Mostly I start learning using tutorials. Yeah, it's hell. At the end of the video, I learned about nothing, just a few pieces of memorized knowledge. But this time I dig into a different way. I use the dev challenge &lt;a href="https://devchallenges.io/" rel="noopener noreferrer"&gt;devchallenges&lt;/a&gt; to read the article and then build it with no AI involved, just me and that article. Sometimes I get stuck between thoughts, and then I use the world's most powerful tool, &lt;strong&gt;GOOGLE&lt;/strong&gt;. Yeah, you read it correctly. I use Google, Stack Overflow, etc. This thing taught me how to solve your problem using your brain, not an AI's brain. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIPS FOR THE PAST ME&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Read other people's code and understand it. (The more you read it, the less you ask AI.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are endless possibilities to learn in today's tech world; just utilize it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/" rel="noopener noreferrer"&gt;https://www.w3schools.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/&lt;/a&gt;
I mainly use these two for theory stuffs of HTML, CSS, JS. you can prefer whatever you want like GFG,..etc&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(I am not good at English. Forgive me if anything is wrong.)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
