<?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: Dwiki</title>
    <description>The latest articles on DEV Community by Dwiki (@dwikis17).</description>
    <link>https://dev.to/dwikis17</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%2F1147792%2F3511d514-5459-40e6-a5c7-60362aca398d.jpg</url>
      <title>DEV Community: Dwiki</title>
      <link>https://dev.to/dwikis17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dwikis17"/>
    <language>en</language>
    <item>
      <title>Leetcode75 - Reverse vowels in a string #5</title>
      <dc:creator>Dwiki</dc:creator>
      <pubDate>Mon, 04 Aug 2025 12:21:35 +0000</pubDate>
      <link>https://dev.to/dwikis17/leetcode75-reverse-vowels-in-a-string-5-9pn</link>
      <guid>https://dev.to/dwikis17/leetcode75-reverse-vowels-in-a-string-5-9pn</guid>
      <description>&lt;p&gt;This is the &lt;a href="https://leetcode.com/problems/reverse-vowels-of-a-string/description/?envType=study-plan-v2&amp;amp;envId=leetcode-75" rel="noopener noreferrer"&gt;5th problem&lt;/a&gt; in Leetcode75 ( Array&amp;amp;Hashing ).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Problem Statement&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Given a string s, reverse only all the vowels in the string and return it.&lt;/p&gt;

&lt;p&gt;The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Solution Strategy&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;we're gonna create a variable that holds an array of strings of vowels&lt;/li&gt;
&lt;li&gt;also create a variable that holds a list of given string, since string in python is  immutable, we need to do it on a list&lt;/li&gt;
&lt;li&gt;create 2 variables for pointer, left and right, left starts at first index of given string, and right starts at the last index of given string&lt;/li&gt;
&lt;li&gt;then we will do a while-loop while left &amp;lt; right&lt;/li&gt;
&lt;li&gt;we check if the character in left and right index are vowels ( by checking if its in the array that contains vowel that we crated), if yes then swap it , if no then -&amp;gt;&lt;/li&gt;
&lt;li&gt;check if the character in left index is vowel then, we decrease the value of right&lt;/li&gt;
&lt;li&gt;otherwise we increase the value of left, ( moving the pointer ) until the 5th conditions are met&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;code:&lt;/strong&gt;&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:
    def reverseVowels(self, s: str) -&amp;gt; str:
        vowels = ['a','i','u','e','o']

        s_list = list(s)

        left = 0
        right = len(s) - 1

        while left &amp;lt; right:
            if s_list[left].lower() in vowels and s_list[right].lower() in vowels:
                temp = s_list[left]
                s_list[left] = s_list[right]
                s_list[right] = temp
                left += 1
                right -= 1

            elif s_list[left].lower() in vowels:
                right -= 1 
            else:
                left += 1 


        return ''.join(s_list)```

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

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Leetcode75 - Can Place Flowers #4</title>
      <dc:creator>Dwiki</dc:creator>
      <pubDate>Wed, 05 Mar 2025 12:45:45 +0000</pubDate>
      <link>https://dev.to/dwikis17/leetcode75-can-place-flowers-4-2kmb</link>
      <guid>https://dev.to/dwikis17/leetcode75-can-place-flowers-4-2kmb</guid>
      <description>&lt;p&gt;This is the &lt;a href="https://leetcode.com/problems/can-place-flowers/description/?envType=study-plan-v2&amp;amp;envId=leetcode-75" rel="noopener noreferrer"&gt;4th problem&lt;/a&gt; in Leetcode75 ( Array&amp;amp;Hashing ).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Problem Statement&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.&lt;/p&gt;

&lt;p&gt;Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Solution Strategy&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;we're going to modify the array of flowers, by adding 0 at first index and at the last index.&lt;/li&gt;
&lt;li&gt;then we're going to iterate through the modified array with pointer, starting from 1 ( since the first element is definitely 0, cuz we just inserted that ).&lt;/li&gt;
&lt;li&gt;on each iteration we're gonna check if the current element in the array is 0, and we're also checking the previous element of current index and the next element also 0, if so, then we're going to place the flower there by changing the current element to 1, and and we move the pointer by 2 steps, then substracting the n numbers of flower that will be placed&lt;/li&gt;
&lt;li&gt;then if no such conditions met, we're just going to increase the pointer value to iterate to the next indices&lt;/li&gt;
&lt;li&gt;then after the while loop, we're going to return if the placed flowers equal to zero, since we have to return a boolean.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;code:&lt;/strong&gt;&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 {
    func canPlaceFlowers(_ flowerbed: [Int], _ n: Int) -&amp;gt; Bool {
        var modifiedArray = flowerbed
        var pointer = 1
        var totalFlowers = n

        modifiedArray.insert(0, at: modifiedArray.startIndex)
        modifiedArray.insert(0, at: modifiedArray.endIndex)

        while pointer &amp;lt; modifiedArray.count - 1 &amp;amp;&amp;amp; totalFlowers &amp;gt; 0 {
            if modifiedArray[pointer] == 0 &amp;amp;&amp;amp; modifiedArray[pointer-1] == 0 &amp;amp;&amp;amp; modifiedArray[pointer+1] == 0 {
                modifiedArray[pointer] = 1
                pointer += 2
                totalFlowers -= 1
            } else {
              pointer += 1
            }

        }

        return totalFlowers == 0 

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Leetcode75 - Kids with the Greatest Number of Candies #3</title>
      <dc:creator>Dwiki</dc:creator>
      <pubDate>Fri, 24 Jan 2025 08:29:44 +0000</pubDate>
      <link>https://dev.to/dwikis17/leetcode75-kids-with-the-greatest-number-of-candies-3m9k</link>
      <guid>https://dev.to/dwikis17/leetcode75-kids-with-the-greatest-number-of-candies-3m9k</guid>
      <description>&lt;p&gt;This is the 3rd problem in Leetcode75 ( Array&amp;amp;Hashing ).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Problem Statement&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.&lt;/p&gt;

&lt;p&gt;Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.&lt;/p&gt;

&lt;p&gt;Note that multiple kids can have the greatest number of candies.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Solution Strategy&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create an array of boolean, we're going to store the result here&lt;/li&gt;
&lt;li&gt;Find the current maximum number of candies&lt;/li&gt;
&lt;li&gt;Iterate through the array of candies. For each candy, add the extra candies and check if this addition makes it the greatest. If so, append true to the results array; otherwise, append false
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    func kidsWithCandies(_ candies: [Int], _ extraCandies: Int) -&amp;gt; [Bool] {
       var result = [Bool]()
       let greatestCandies = candies.max()

       guard let greatestCandies = greatestCandies else {
        fatalError("error")
       }

       for candy in candies {
        if candy + extraCandies &amp;gt;= greatestCandies {
            result.append(true)
        } else {
            result.append(false)
        }
       }

       return result
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;## SOLUTION 2 ##&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;if you are familiar with .map() function, you could do it like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func kidsWithCandies(_ candies: [Int], _ extraCandies: Int) -&amp;gt; [Bool] {
    guard let maxCandies = candies.max() else { return [] }
    return candies.map { candy in
        candy + extraCandies &amp;gt;= maxCandies
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>LeetCode75 - Greatest Common Divisor of Strings #2</title>
      <dc:creator>Dwiki</dc:creator>
      <pubDate>Thu, 23 Jan 2025 02:21:23 +0000</pubDate>
      <link>https://dev.to/dwikis17/leetcode75-greatest-common-divisor-of-strings-2-1f8c</link>
      <guid>https://dev.to/dwikis17/leetcode75-greatest-common-divisor-of-strings-2-1f8c</guid>
      <description>&lt;p&gt;Hi there!&lt;/p&gt;

&lt;p&gt;So this is the &lt;a href="https://leetcode.com/problems/greatest-common-divisor-of-strings/description" rel="noopener noreferrer"&gt;2nd challenge in leetcode 75&lt;/a&gt;, we're still tackling with array&amp;amp;hashing problem, so let's jump right into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given two strings str1 and str2, find the largest string x that divides both strings. If no such string exists, return an empty string.&lt;br&gt;
Example Scenarios&lt;/p&gt;

&lt;p&gt;str1 = "ABCABC", str2 = "ABC"&lt;/p&gt;

&lt;p&gt;Output: "ABC"&lt;br&gt;
Explanation: "ABC" divides both input strings perfectly&lt;/p&gt;

&lt;p&gt;str1 = "ABABAB", str2 = "ABAB"&lt;/p&gt;

&lt;p&gt;Output: "AB"&lt;br&gt;
Explanation: "AB" divides both input strings perfectly&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution Strategy
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Start from the length of the shorter string&lt;/li&gt;
&lt;li&gt;Decrease length in each iteration&lt;/li&gt;
&lt;li&gt;Validate if current length produces a valid divisor&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Key Validation Conditions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Divisor length must evenly divide both string lengths&lt;/li&gt;
&lt;li&gt;Repeating the divisor should reconstruct original strings
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func gcdOfStrings(_ str1: String, _ str2: String) -&amp;gt; String {
   func isDivisor(_ factor: Int) -&amp;gt; Bool {
       if str1.count % factor != 0 || str2.count % factor != 0 {
           return false
       }

       let stringDivisor = String(str1.prefix(factor))

       return String(repeating: stringDivisor, count: str1.count / factor) == str1 &amp;amp;&amp;amp; 
              String(repeating: stringDivisor, count: str2.count / factor) == str2
   }

   for i in stride(from: min(str1.count, str2.count), to: 0, by: -1) {
       if isDivisor(i) {
           return String(str1.prefix(i))
       }
   }

   return ""
}

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>LeetCode75 - Merge Strings Alternately #1</title>
      <dc:creator>Dwiki</dc:creator>
      <pubDate>Tue, 21 Jan 2025 06:58:19 +0000</pubDate>
      <link>https://dev.to/dwikis17/leetcode75-merge-strings-alternately-1-m7n</link>
      <guid>https://dev.to/dwikis17/leetcode75-merge-strings-alternately-1-m7n</guid>
      <description>&lt;p&gt;Hi there ! &lt;/p&gt;

&lt;p&gt;This is going to be my first post on this platform. I decided to write down everything I find useful so I don't forget it easily. I'm starting with this LeetCode series because I'm studying Data Structures and Algorithms (DSA).&lt;/p&gt;

&lt;p&gt;The first challenge is called &lt;a href="https://leetcode.com/problems/merge-strings-alternately/description" rel="noopener noreferrer"&gt;Merge Strings Alternately&lt;/a&gt;. In this problem, we are given 2 strings as parameters, and we need to merge them by adding letters in alternating order.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
word1: abc&lt;br&gt;
word2: pqr&lt;br&gt;
output: apbqcr&lt;br&gt;
Example 2:&lt;br&gt;
word1: ab&lt;br&gt;
word2: pqrs&lt;br&gt;
output: apbqrs&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
We'll start by creating a variable 'word' and initializing it as an empty string, along with 'left' and 'right' variables starting at 0. We'll use the left and right variables as indices for word1 and word2 respectively as we iterate through them using a while loop.&lt;/p&gt;

&lt;p&gt;The while loop condition will check if either the left or right pointer is still within the index range. If both pointers are within range, we'll append each character from word1 and word2 to our previously created variable 'word', and then increment the left and right values to move to the next indices.&lt;/p&gt;

&lt;p&gt;Then we'll check for the case where one of the pointers goes out of range. In this situation, we just need to append the remaining characters from the other string and break out of the while loop.&lt;br&gt;
Finally, we return the 'word' variable that contains our merged result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func mergeAlternately(_ word1: String, _ word2: String) -&amp;gt; String {
    var word = String()
    var (left, right) = (0, 0)

    while left &amp;lt; word1.count || right &amp;lt; word2.count {
        if left &amp;lt; word1.count &amp;amp;&amp;amp; right &amp;lt; word2.count {
            word.append(word1[word1.index(word1.startIndex, offsetBy: left)])
            word.append(word2[word2.index(word2.startIndex, offsetBy: right)])
            left += 1
            right += 1
        } else if left &amp;lt; word1.count {
            word.append(contentsOf: word1[word1.index(word1.startIndex, offsetBy: left)...])
            break
        } else {
            word.append(contentsOf: word2[word2.index(word2.startIndex, offsetBy: right)...])
            break
        }
    }

    return word
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>leetcode</category>
      <category>swift</category>
    </item>
  </channel>
</rss>
