<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Carlos Dario Castañeda Mendoza on Medium]]></title>
        <description><![CDATA[Stories by Carlos Dario Castañeda Mendoza on Medium]]></description>
        <link>https://medium.com/@dario_85947?source=rss-408d8c29ef64------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OVzsv_SsX0t2GXA6gc0_7A@2x.jpeg</url>
            <title>Stories by Carlos Dario Castañeda Mendoza on Medium</title>
            <link>https://medium.com/@dario_85947?source=rss-408d8c29ef64------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:19:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dario_85947/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[75. Sort Colors (Java)]]></title>
            <link>https://medium.com/@dario_85947/75-sort-colors-java-a2193da60a37?source=rss-408d8c29ef64------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2193da60a37</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <dc:creator><![CDATA[Carlos Dario Castañeda Mendoza]]></dc:creator>
            <pubDate>Wed, 20 Nov 2024 10:28:54 GMT</pubDate>
            <atom:updated>2024-11-20T10:28:54.175Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an array nums with n objects colored red, white, or blue, sort them <a href="https://en.wikipedia.org/wiki/In-place_algorithm"><strong>in-place</strong></a><strong> </strong>so that objects of the same color are adjacent, with the colors in the order red, white, and blue.</p><p>We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.</p><p>You must solve this problem without using the library’s sort function.</p><p><strong>Example 1:</strong></p><pre>Input: nums = [2,0,2,1,1,0]<br>Output: [0,0,1,1,2,2]</pre><p><strong>Example 2:</strong></p><pre>Input: nums = [2,0,1]<br>Output: [0,1,2]</pre><p><strong>Constraints:</strong></p><ul><li>n == nums.length</li><li>1 &lt;= n &lt;= 300</li><li>nums[i] is either 0, 1, or 2.</li></ul><p>Solution:</p><pre>//leetcode 75<br>public class SortColors {<br><br><br>    public static void main(String[] args) {<br>        int[] nums = {2, 0, 2, 1, 1, 0};<br>        new SortColors().sortColors(nums);<br>        for (int i = 0; i &lt; nums.length; i++) {<br>            System.out.print(nums[i] + &quot; &quot;);<br>        }<br>    }<br><br>    public void sortColors(int[] nums) {<br><br>        int[] count = new int[3];<br><br>        for (int num : nums) {<br>            count[num] = count[num] + 1;<br>        }<br><br>        int i = 0;<br>        int value = 0;<br>        for (int n : count) {<br>            for (int j = 0; j &lt; n; j++) {<br>                nums[i++] = value;<br>            }<br>            ++value;<br>        }<br><br>    }<br><br><br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*06lyNmqS7J1Tb3Xi7FL9JA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2193da60a37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leetcode — 13. Roman to Integer (Java 22)]]></title>
            <link>https://medium.com/@dario_85947/leetcode-13-roman-to-integer-java-22-fc25661a7e3f?source=rss-408d8c29ef64------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc25661a7e3f</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[java22]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Carlos Dario Castañeda Mendoza]]></dc:creator>
            <pubDate>Sun, 12 May 2024 08:24:04 GMT</pubDate>
            <atom:updated>2024-05-13T09:43:45.545Z</atom:updated>
            <content:encoded><![CDATA[<h3>Leetcode — 13. Roman to Integer (Java-Switch Expressions)</h3><p>Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.</p><pre>Symbol       Value<br>I             1<br>V             5<br>X             10<br>L             50<br>C             100<br>D             500<br>M             1000</pre><p>For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.</p><p>Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:</p><ul><li>I can be placed before V (5) and X (10) to make 4 and 9.</li><li>X can be placed before L (50) and C (100) to make 40 and 90.</li><li>C can be placed before D (500) and M (1000) to make 400 and 900.</li></ul><p>Given a roman numeral, convert it to an integer.</p><p><strong>Example 1:</strong></p><pre>Input: s = &quot;III&quot;<br>Output: 3<br>Explanation: III = 3.</pre><p><strong>Example 2:</strong></p><pre>Input: s = &quot;LVIII&quot;<br>Output: 58<br>Explanation: L = 50, V= 5, III = 3.</pre><p><strong>Example 3:</strong></p><pre>Input: s = &quot;MCMXCIV&quot;<br>Output: 1994<br>Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.</pre><p><strong>Constraints:</strong></p><ul><li>1 &lt;= s.length &lt;= 15</li><li>s contains only the characters (&#39;I&#39;, &#39;V&#39;, &#39;X&#39;, &#39;L&#39;, &#39;C&#39;, &#39;D&#39;, &#39;M&#39;).</li><li>It is <strong>guaranteed</strong> that s is a valid roman numeral in the range [1, 3999].</li></ul><p><strong>Solution:</strong></p><pre>public int romanToInt(String s) {<br><br>        int total = 0, previous = 0;<br>        //Read from Right to Left<br>        for (int i = s.length() - 1; i &gt;= 0; i--) {<br><br>            var current = switch (s.charAt(i)) {<br>                case &#39;I&#39; -&gt; 1;<br>                case &#39;V&#39; -&gt; 5;<br>                case &#39;X&#39; -&gt; 10;<br>                case &#39;L&#39; -&gt; 50;<br>                case &#39;C&#39; -&gt; 100;<br>                case &#39;D&#39; -&gt; 500;<br>                case &#39;M&#39; -&gt; 1000;<br>                default -&gt; 0;<br>            };<br><br>            if (previous &gt; current) { // 4 = IV, 9 = IX for example<br>                total -= current;<br>            } else {<br>                total += current; // 6 = VI, 11 = XI for example<br>                previous = current;<br>            }<br>        }<br><br>        return total;<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*uG4NpLH4TguXER3y6oB94Q.jpeg" /><figcaption><a href="https://leetcode.com/problems/roman-to-integer/submissions/1255947805?envType=study-plan-v2&amp;envId=top-interview-150">https://leetcode.com/problems/roman-to-integer/submissions/1255947805?envType=study-plan-v2&amp;envId=top-interview-150</a></figcaption></figure><p>Runtime: <strong>2 ms</strong></p><p>Memory Usage: <strong>44.2 MB</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc25661a7e3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[274. H-Index (Java)]]></title>
            <link>https://medium.com/@dario_85947/274-h-index-java-d1cf3de79d18?source=rss-408d8c29ef64------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1cf3de79d18</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Carlos Dario Castañeda Mendoza]]></dc:creator>
            <pubDate>Thu, 02 May 2024 05:49:03 GMT</pubDate>
            <atom:updated>2024-05-02T05:49:03.641Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return <em>the researcher&#39;s h-index</em>.</p><p>According to the <a href="https://en.wikipedia.org/wiki/H-index">definition of h-index on Wikipedia</a>: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.</p><p><strong>Example 1:</strong></p><pre>Input: citations = [3,0,6,1,5]<br>Output: 3<br>Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.<br>Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.</pre><p><strong>Example 2:</strong></p><pre>Input: citations = [1,3,1]<br>Output: 1</pre><p><strong>Solution :</strong></p><pre>public int hIndex(int[] citations) {<br><br>        // sorted the array<br>        Arrays.sort(citations);<br>        //System.out.println(Arrays.toString(citations));<br><br>        int h = 0;<br>        int i = 0;<br>        for (var count : citations) {<br>            h = Math.max(h, Math.min(citations.length - i, count));<br>            i++;<br>        }<br><br>        //System.out.println(&quot; &gt;&gt;&gt;&gt;&gt;&gt;&gt; &quot; + h);<br><br>        return h;<br>    }</pre><p>Runtime</p><p>2ms</p><p>Beats65.88%of users with Java</p><p>Memory</p><p>41.27MB</p><p>Beats73.35%of users with Java</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1cf3de79d18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode][Medium][26]Remove Duplicates from Sorted Array]]></title>
            <link>https://medium.com/@dario_85947/leetcode-medium-26-remove-duplicates-from-sorted-array-fbfb59a3f283?source=rss-408d8c29ef64------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbfb59a3f283</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Carlos Dario Castañeda Mendoza]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 12:47:27 GMT</pubDate>
            <atom:updated>2024-04-04T12:47:27.276Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an integer array nums sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong> of the elements should be kept the <strong>same</strong>. Then return <em>the number of unique elements in </em>nums.</p><p>Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:</p><ul><li>Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.</li><li>Return k.</li></ul><p><strong>Custom Judge:</strong></p><p>The judge will test your solution with the following code:</p><pre>int[] nums = [...]; // Input array<br>int[] expectedNums = [...]; // The expected answer with correct length</pre><pre>int k = removeDuplicates(nums); // Calls your implementation</pre><pre>assert k == expectedNums.length;<br>for (int i = 0; i &lt; k; i++) {<br>    assert nums[i] == expectedNums[i];<br>}</pre><p>If all assertions pass, then your solution will be <strong>accepted</strong>.</p><p><strong>Example 1:</strong></p><pre>Input: nums = [1,1,2]<br>Output: 2, nums = [1,2,_]<br>Explanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.<br>It does not matter what you leave beyond the returned k (hence they are underscores).</pre><p><strong>Example 2:</strong></p><pre>Input: nums = [0,0,1,1,1,2,2,3,3,4]<br>Output: 5, nums = [0,1,2,3,4,_,_,_,_,_]<br>Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.<br>It does not matter what you leave beyond the returned k (hence they are underscores).</pre><p>Solution Java</p><pre>public int removeDuplicates(int[] nums) {<br><br>        Set&lt;Integer&gt; set = new LinkedHashSet&lt;Integer&gt;();<br><br>        int i = 0;<br>        for (int num : nums) {<br>            if(set.add(num)){<br>                nums[i] = num;<br>                i++;<br>            }<br>        }<br><br>        return set.size();<br>    }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbfb59a3f283" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>