<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>LeetCode on Junian Dev</title>
    <link>https://www.junian.dev/tags/leetcode/</link>
    <description>Recent content in LeetCode on Junian Dev</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>author@junian.dev (Junian Triajianto)</managingEditor>
    <webMaster>author@junian.dev (Junian Triajianto)</webMaster>
    <copyright>Copyright &amp;copy; 2014 - 2026 Junian.dev</copyright>
    
	    <atom:link href="https://www.junian.dev/tags/leetcode/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Fizz Buzz - LeetCode in C#</title>
      <link>https://www.junian.dev/dev/fizz-buzz/</link>
      <pubDate>Thu, 14 Nov 2024 12:01:57 +0700</pubDate>
      <author>author@junian.dev (Junian Triajianto)</author>
      <guid>https://www.junian.dev/dev/fizz-buzz/</guid>
      <description>&lt;p&gt;The Fizz Buzz problem is a classic exercise that is often used to teach basic programming concepts such as loops and conditionals.&lt;/p&gt;
&lt;p&gt;In this article, I&amp;rsquo;ll show you my attempt to solve this problem.&lt;/p&gt;
&lt;h2 id=&#34;problem-description&#34;&gt;Problem Description&lt;/h2&gt;
&lt;details&gt;
&lt;p&gt;Given an integer &lt;code&gt;n&lt;/code&gt;, return a string array &lt;code&gt;answer&lt;/code&gt; &lt;em&gt;(&lt;strong&gt;1-indexed&lt;/strong&gt;) where&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;answer[i] == &amp;quot;FizzBuzz&amp;quot;&lt;/code&gt; if &lt;code&gt;i&lt;/code&gt; is divisible by &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;answer[i] == &amp;quot;Fizz&amp;quot;&lt;/code&gt; if &lt;code&gt;i&lt;/code&gt; is divisible by &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;answer[i] == &amp;quot;Buzz&amp;quot;&lt;/code&gt; if &lt;code&gt;i&lt;/code&gt; is divisible by &lt;code&gt;5&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;answer[i] == i&lt;/code&gt; (as a string) if none of the above conditions are true.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;example-1&#34;&gt;Example 1:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;n = 3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;[&amp;quot;1&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;Fizz&amp;quot;]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;example-2&#34;&gt;Example 2:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;n = 5&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;[&amp;quot;1&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;Fizz&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;Buzz&amp;quot;]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;example-3&#34;&gt;Example 3:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;n = 15&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;[&amp;quot;1&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;Fizz&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;Buzz&amp;quot;,&amp;quot;Fizz&amp;quot;,&amp;quot;7&amp;quot;,&amp;quot;8&amp;quot;,&amp;quot;Fizz&amp;quot;,&amp;quot;Buzz&amp;quot;,&amp;quot;11&amp;quot;,&amp;quot;Fizz&amp;quot;,&amp;quot;13&amp;quot;,&amp;quot;14&amp;quot;,&amp;quot;FizzBuzz&amp;quot;]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;constraints&#34;&gt;Constraints:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= n &amp;lt;= 10&lt;sup&gt;4&lt;/sup&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;!--adsense--&gt;
&lt;h2 id=&#34;intuition&#34;&gt;Intuition&lt;/h2&gt;
&lt;p&gt;When breaking down the problem, the task is to iterate through a sequence of numbers while applying simple divisibility rules to determine the correct output for each number.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Palindrome Number - LeetCode in C#</title>
      <link>https://www.junian.dev/dev/palindrome-number/</link>
      <pubDate>Sun, 10 Nov 2024 17:03:55 +0700</pubDate>
      <author>author@junian.dev (Junian Triajianto)</author>
      <guid>https://www.junian.dev/dev/palindrome-number/</guid>
      <description>&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;
&lt;details&gt;
&lt;p&gt;Given an integer &lt;code&gt;x&lt;/code&gt;, return &lt;code&gt;true&lt;/code&gt; &lt;em&gt;if&lt;/em&gt; &lt;code&gt;x&lt;/code&gt; &lt;em&gt;is a&lt;/em&gt; &lt;em&gt;&lt;strong&gt;palindrome&lt;/strong&gt;&lt;/em&gt; &lt;em&gt;, and&lt;/em&gt; &lt;code&gt;false&lt;/code&gt; &lt;em&gt;otherwise&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;x = 121&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; 121 reads as 121 from left to right and from right to left.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;x = -121&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example 3:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;x = 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Reads 01 from right to left. Therefore it is not a palindrome.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Remove Duplicates From Sorted Array - LeetCode in C#</title>
      <link>https://www.junian.dev/dev/remove-duplicates-from-sorted-array/</link>
      <pubDate>Sat, 09 Nov 2024 14:46:13 +0700</pubDate>
      <author>author@junian.dev (Junian Triajianto)</author>
      <guid>https://www.junian.dev/dev/remove-duplicates-from-sorted-array/</guid>
      <description>&lt;h2 id=&#34;problem-description&#34;&gt;Problem Description&lt;/h2&gt;
&lt;details&gt;
&lt;p&gt;Given an integer array &lt;code&gt;nums&lt;/code&gt; sorted in &lt;strong&gt;non-decreasing order&lt;/strong&gt;, remove the duplicates &lt;a href=&#34;https://en.wikipedia.org/wiki/In-place_algorithm&#34;&gt;&lt;strong&gt;in-place&lt;/strong&gt;&lt;/a&gt; such that each unique element appears only &lt;strong&gt;once&lt;/strong&gt;. The &lt;strong&gt;relative order&lt;/strong&gt; of the elements should be kept the &lt;strong&gt;same&lt;/strong&gt;. Then return &lt;em&gt;the number of unique elements in&lt;/em&gt; &lt;code&gt;nums&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Consider the number of unique elements of &lt;code&gt;nums&lt;/code&gt; to be &lt;code&gt;k&lt;/code&gt;, to get accepted, you need to do the following things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Change the array &lt;code&gt;nums&lt;/code&gt; such that the first &lt;code&gt;k&lt;/code&gt; elements of &lt;code&gt;nums&lt;/code&gt; contain the unique elements in the order they were present in &lt;code&gt;nums&lt;/code&gt; initially. The remaining elements of &lt;code&gt;nums&lt;/code&gt; are not important as well as the size of &lt;code&gt;nums&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Return &lt;code&gt;k&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Custom Judge:&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Two Sum - LeetCode in C# - Hash Table Solution</title>
      <link>https://www.junian.dev/dev/two-sum-hash-table/</link>
      <pubDate>Fri, 08 Nov 2024 18:51:32 +0700</pubDate>
      <author>author@junian.dev (Junian Triajianto)</author>
      <guid>https://www.junian.dev/dev/two-sum-hash-table/</guid>
      <description>&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;
&lt;details&gt;
&lt;p&gt;Given an array of integers &lt;code&gt;nums&lt;/code&gt; and an integer &lt;code&gt;target&lt;/code&gt;, return &lt;em&gt;indices of the two numbers such that they add up to &lt;code&gt;target&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;You may assume that each input would have &lt;strong&gt;&lt;em&gt;exactly&lt;/em&gt; one solution&lt;/strong&gt;, and you may not use the &lt;em&gt;same&lt;/em&gt; element twice.&lt;/p&gt;
&lt;p&gt;You can return the answer in any order.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Input:&lt;/strong&gt; &lt;code&gt;nums = [2,7,11,15], target = 9&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;[0,1]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Because &lt;code&gt;nums[0] + nums[1] == 9&lt;/code&gt;, we return &lt;code&gt;[0, 1]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Two Sum - LeetCode in C# - Brute force approach</title>
      <link>https://www.junian.dev/dev/two-sum-bruteforce/</link>
      <pubDate>Fri, 08 Nov 2024 13:39:47 +0700</pubDate>
      <author>author@junian.dev (Junian Triajianto)</author>
      <guid>https://www.junian.dev/dev/two-sum-bruteforce/</guid>
      <description>&lt;p&gt;&lt;em&gt;You might want to read the &lt;a href=&#34;https://www.junian.dev/leetcode/two-sum-hash-table/&#34;&gt;Hash Table&lt;/a&gt; solution. It&amp;rsquo;s better.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&#34;intuition&#34;&gt;Intuition&lt;/h2&gt;
&lt;p&gt;When I first encountered the Two Sum problem, my initial thought was to check each possible pair of numbers in the array.
If a pair sums to the target value, then that would be our solution.&lt;/p&gt;
&lt;p&gt;This brute force method should work, but intuitively, I thought there might be more efficient ways.&lt;/p&gt;
&lt;p&gt;However, starting with the simplest idea often helps to understand the problem better and refine the approach.&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>
