<?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: WhereIsLijah</title>
    <description>The latest articles on DEV Community by WhereIsLijah (@whereislijah).</description>
    <link>https://dev.to/whereislijah</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%2F1536475%2Fca75574d-f255-4e0f-905b-e2595b508ba2.png</url>
      <title>DEV Community: WhereIsLijah</title>
      <link>https://dev.to/whereislijah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/whereislijah"/>
    <language>en</language>
    <item>
      <title>977. Squares of a Sorted Array</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Wed, 14 Aug 2024 16:05:38 +0000</pubDate>
      <link>https://dev.to/whereislijah/977-squares-of-a-sorted-array-47f</link>
      <guid>https://dev.to/whereislijah/977-squares-of-a-sorted-array-47f</guid>
      <description>&lt;p&gt;Here we employ 2 pointers to keep track of the indices &lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
Since it is in a non-decreasing order e.g [-4,-1,0,3,10], we need to compare values of both pointers and also keep track of the indices after each iteration. &lt;/p&gt;

&lt;p&gt;1 - Initialize left pointer to 0, representing the start of the list.&lt;br&gt;
2 - Initialize right pointer to the last index of the list (len(nums) - 1).&lt;br&gt;
3 - Create an empty list result to store the squares of the elements.&lt;br&gt;
4 - Loop while left is less than or equal to right:&lt;br&gt;
4a - Compare the absolute values of the elements at the left and right pointers.&lt;br&gt;
4b - If the absolute value of the element at left is greater than that at right, append the square of the element at left to result, and increment the left pointer by 1.&lt;br&gt;
4c - Else, append the square of the element at right to result, and decrement the right pointer by 1.&lt;br&gt;
5 - After the loop, reverse the result list to ensure the squares are in non-decreasing order.&lt;br&gt;
6 - Return the result list, which now contains the squared values sorted in non-decreasing order.&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 sortedSquares(self, nums: List[int]) -&amp;gt; List[int]:
        left = 0
        right = len(nums)-1
        result = []

        while left &amp;lt;= right:
            if abs(nums[left]) &amp;gt; abs(nums[right]):
                result.append(nums[left] ** 2)
                left +=1
            else:
                result.append(nums[right] ** 2)
                right -=1

        result.reverse()

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>20. Valid Parentheses</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Mon, 29 Jul 2024 14:28:05 +0000</pubDate>
      <link>https://dev.to/whereislijah/20-valid-parentheses-9jc</link>
      <guid>https://dev.to/whereislijah/20-valid-parentheses-9jc</guid>
      <description>&lt;p&gt;We must consider that each bracket is closed in the correct order, which is vital logic we must pay attention to for our program to work. &lt;/p&gt;

&lt;p&gt;Since this is a stack-based question, an easy way would be to represent our stack as a list and also use a mapping (dictionary) of each closing bracket to their corresponding opening brackets.&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
1 - create an empty stack&lt;/p&gt;

&lt;p&gt;2 - create a map that contains key-value pairs with the closing brackets being the key and their corresponding opening brackets being the value&lt;/p&gt;

&lt;p&gt;3 - loop through each character in the string&lt;br&gt;
3a - if the character is not Mapped (it means it is an opening bracket) then we append it to the stack and continue to the next character.&lt;/p&gt;

&lt;p&gt;4 - else if the character is in the map then we check if the stack is empty (if it is then there's a problem because we have nothing to compare our closing brackets with) or also peek/check the most recent entry(top) into the stack and compare to the value of the current key in the Map, If they are not equal then return False. &lt;/p&gt;

&lt;p&gt;5 - if the element matches, we pop the last entry into the stack to move to the next character/bracket. &lt;/p&gt;

&lt;p&gt;6 - (Outside the loop) Then we return the length of the stack, if empty then it is valid, else it is invalid&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    stack = []
    Map = {")":"(","]":"[","}":"{"}

    for c in s:
        if c not in Map:
            stack.append(c)
            continue
        elif c in Map:
            if len(stack) == 0 or stack[-1] != Map[c]:
                return False
            stack.pop()
    return len(stack) == 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Data structures - Stack</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Mon, 29 Jul 2024 13:53:47 +0000</pubDate>
      <link>https://dev.to/whereislijah/data-structures-stack-40lk</link>
      <guid>https://dev.to/whereislijah/data-structures-stack-40lk</guid>
      <description>&lt;p&gt;Stack, Array, and linked list are linear data structures &lt;/p&gt;

&lt;p&gt;Stack operations (LIFO):&lt;br&gt;
1 - Push&lt;br&gt;
2 - Pop&lt;br&gt;
3 - Peek/Top: returns the last element without removing it&lt;br&gt;
4 - Check if the stack is empty -&amp;gt; boolean&lt;br&gt;
5 - Check Size&lt;br&gt;
6 - Check if the stack is full&lt;/p&gt;

</description>
    </item>
    <item>
      <title>167. Two Sum II - Input Array Is Sorted</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Thu, 25 Jul 2024 03:18:53 +0000</pubDate>
      <link>https://dev.to/whereislijah/167-two-sum-ii-input-array-is-sorted-4llo</link>
      <guid>https://dev.to/whereislijah/167-two-sum-ii-input-array-is-sorted-4llo</guid>
      <description>&lt;p&gt;Refer to Two Sum Solution and add +1 to the indices!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>125. Valid Palindrome</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Wed, 12 Jun 2024 16:43:54 +0000</pubDate>
      <link>https://dev.to/whereislijah/125-valid-palindrome-4lc6</link>
      <guid>https://dev.to/whereislijah/125-valid-palindrome-4lc6</guid>
      <description>&lt;p&gt;Topic: Arrays &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;Soln 1 (isalnum):&lt;/p&gt;

&lt;p&gt;A not so efficient solution:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create a new list to store the palindrome&lt;/li&gt;
&lt;li&gt;loop through the characters in the string:&lt;/li&gt;
&lt;li&gt;check if it is alphanumeric, if it is then append to list&lt;/li&gt;
&lt;li&gt;assign a variable, then convert palindrome list to string&lt;/li&gt;
&lt;li&gt;assign another variable, then reverse palindrome&lt;/li&gt;
&lt;li&gt;return and compare both variables
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def isPalindrome(self, s: str) -&amp;gt; bool:
    palin = []

    for c in s:
        if c.isalnum():
            palin.append(c.lower())
    x = ''.join(palin)
    y = x[::-1]

    return x == y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soln 2 (isalnum):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Filter and Normalize: Create palindrome by joining all alphanumeric characters from s and converting them to lowercase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check Palindrome: Return True if palindrome is equal to its reverse, otherwise return False.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def isPalindrome(self, s: str) -&amp;gt; bool:
        palindrome = ''.join(filter(str.isalnum, s)).lower()
        return palindrome == palindrome[::-1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes: Attempt to understand 2 pointer solution.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>238. Products of Array Discluding Self</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Tue, 11 Jun 2024 18:59:50 +0000</pubDate>
      <link>https://dev.to/whereislijah/products-of-array-discluding-self-4mb2</link>
      <guid>https://dev.to/whereislijah/products-of-array-discluding-self-4mb2</guid>
      <description>&lt;p&gt;Topic: Arrays &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;Soln 1 (prefix &amp;amp; suffix):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Get the length of the input list and create 2 lists (prefix and suffix) and assign 1 to them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate through the input list starting from the second element (index 1) because the first element (index 0) has no elements to its left.&lt;br&gt;
For each element, set the current position in the prefix list to the product of the previous position in the prefix list and the previous element in the original list nums. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate through the input list in reverse order starting from the second-to-last element (index n-2) because the last element (index n-1) has no elements to its right.&lt;br&gt;
For each element, set the current position in the suffix list to the product of the next position in the suffix list and the next element in the original list nums.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;return a combined multiplication of both list.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = len(nums)
prefix = [1] * x
suffix = [1] * x

for index in range(1, x):
    prefix[index] = prefix[index - 1] * nums[index - 1]    

for index in range(x -2, -1, -1):
    suffix[index] = suffix[index+1] * nums[index + 1]   

return [prefix[i] * suffix[i] for i in range(x)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soln 2 (prefix &amp;amp; suffix)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an array result of the same length as nums, with all elements set to 1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialize prefix to 1, Iterate over nums from left to right, For each element i, set result[i] to prefix and update prefix by multiplying it with nums[i].&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialize suffix to 1, Iterate over nums from right to left, For each element i, multiply result[i] by suffix and update suffix by multiplying it with nums[i].&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return the result array.&lt;br&gt;
&lt;/p&gt;&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:
    def productExceptSelf(self, nums: List[int]) -&amp;gt; List[int]:
        result = [1] * len(nums)
        pre = 1

        for i in range(len(nums)):
            result[i] = pre
            pre *= nums[i]
        suf = 1
        for i in range(len(nums) -1, -1, -1):
            result[i] *=suf
            suf *= nums[i]  

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

&lt;/div&gt;



&lt;p&gt;Soln 3:&lt;/p&gt;

&lt;p&gt;There is a lazy solution where all you have to do is multiply all the elements in the list to get the total product, e.g using &lt;strong&gt;reduce&lt;/strong&gt; (imported from functool) then divide by the element and return a list of the solution.&lt;br&gt;
The drawback of this is it uses division and it fails when any element in the list is zero.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def productExceptSelf(self, nums: List[int]) -&amp;gt; List[int]:
        total_product = reduce(lambda x, y: x * y, nums)

        result = [total_product // num for num in nums]

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

&lt;/div&gt;



&lt;p&gt;Notes: None&lt;/p&gt;

</description>
    </item>
    <item>
      <title>347. Top K Frequent Elements</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Tue, 11 Jun 2024 05:22:47 +0000</pubDate>
      <link>https://dev.to/whereislijah/347-top-k-frequent-elements-4o39</link>
      <guid>https://dev.to/whereislijah/347-top-k-frequent-elements-4o39</guid>
      <description>&lt;p&gt;Topic: Arrays &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;Soln 1 (dictionary + lambda):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty dictionary &lt;/li&gt;
&lt;li&gt;Iterate through the list "nums" with num:&lt;/li&gt;
&lt;li&gt;if the key [num] is not in the dictionary, then add to both the key [num] and the value [occurrence] 1 as the first occurence of that key [num]&lt;/li&gt;
&lt;li&gt;else it means the key [num] already exists and you need to increment the value [occurrence] in the dictionary &lt;/li&gt;
&lt;li&gt;Sort the dictionary items by their values in descending order, extract the keys of the top k items, and return.
&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:
    def topKFrequent(self, nums: List[int], k: int) -&amp;gt; List[int]:
        freq_dict = {}

        for i in nums:
            if i not in freq_dict:
                freq_dict[i] = 1
            else:
                freq_dict[i] +=1

        return [item[0] for item in (sorted(freq_dict.items(), key=lambda item: item[1], reverse=True)[:k])]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soln 2 (dictionary + lambda):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty dictionary &lt;/li&gt;
&lt;li&gt;iterate through the list "nums" using num:&lt;/li&gt;
&lt;li&gt;get the value of num, if it exists,  increment by 1, else, assign a default value of 0&lt;/li&gt;
&lt;li&gt;Sort the dictionary items by their values in descending order using a lambda function&lt;/li&gt;
&lt;li&gt;Return a list of the first k keys from the sorted dictionary.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dic = {}
        for num in nums:
            dic[num] = dic.get(num, 0) + 1

        freq = dict(sorted(dic.items(), key=lambda x: x[1], reverse=True))
        return list(freq.keys())[:k]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes:&lt;br&gt;
A lambda is an anonymous function that can be used in place of a normal function. It can take arguments and is often used with higher-order functions.&lt;/p&gt;

&lt;p&gt;Syntax: &lt;strong&gt;Lambda arguments: expression&lt;/strong&gt;&lt;br&gt;
e.g&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cubed = lambda x: x**3
nums = [1, 2, 3]
cubed_nums = list(map(cubed, nums))
# Output: [1, 8, 27]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Higher-order functions, e.g map, reduce, filter, zip, sorted&lt;/p&gt;

</description>
    </item>
    <item>
      <title>49. Group Anagrams</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Sun, 09 Jun 2024 05:41:36 +0000</pubDate>
      <link>https://dev.to/whereislijah/49-group-anagrams-2fhg</link>
      <guid>https://dev.to/whereislijah/49-group-anagrams-2fhg</guid>
      <description>&lt;p&gt;Topic: Arrays &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;Soln 1 (dictionary):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a dictionary&lt;/li&gt;
&lt;li&gt;iterate through the string of wordsa&lt;/li&gt;
&lt;li&gt;sort the word alphabetically&lt;/li&gt;
&lt;li&gt;if the key[sorted word] is not in the dictionary then add it and use the original word as its value &lt;/li&gt;
&lt;li&gt;else append the word to the already existing key
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    word_dict = {}

    for word in strs:
        sorted_word = ''.join(sorted(word))

        if sorted_word not in word_dict:
            word_dict[sorted_word] = [word]
        else:
            word_dict[sorted_word].append(word)

    return list(word_dict.values())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soln 2 (tuples + defaultdict):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize a Dictionary: Create an empty dictionary.&lt;/li&gt;
&lt;li&gt;Iterate Through the List of Strings: Loop through each string in the input list.&lt;/li&gt;
&lt;li&gt;Sort Each String and Convert to a Tuple: For each string, sort the characters and convert the sorted list to a tuple.&lt;/li&gt;
&lt;li&gt;Use Tuple as Key and Append String as Value: Use the tuple as the key in the dictionary. Append the original string to the list corresponding to this key.&lt;/li&gt;
&lt;li&gt;Return the Values of the Dictionary: Extract the values from the dictionary which are the groups of anagrams.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from collections import defaultdict

def group_anagrams(strs):
    count = defaultdict(list)

    for i in strs:
        count[tuple(sorted(i))].append(i)

    return count.values()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: &lt;strong&gt;defaultdict&lt;/strong&gt; is a sub-class of the dictionary class that returns a dictionary-like object. The functionality of both dictionaries and defaultdict are almost same except for the fact that defaultdict never raises a KeyError. It provides a default value for the key that does not exists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tuple&lt;/strong&gt; is an ordered, immutable collection of elements.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>1. Two Sum</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Sat, 08 Jun 2024 20:20:12 +0000</pubDate>
      <link>https://dev.to/whereislijah/1-two-sum-4a4n</link>
      <guid>https://dev.to/whereislijah/1-two-sum-4a4n</guid>
      <description>&lt;p&gt;Topic: Array &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;Soln 1 (dictonary solution):&lt;br&gt;
After learning how to use dictionaries in the previous leetcode questions, i decided to see how many more solutions i can provide for using it. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty dictionary to store the key-value pairs (this will be where the values and it's respective indiced will be stored)&lt;/li&gt;
&lt;li&gt;loop through the list nums with both the indices and the values:&lt;/li&gt;
&lt;li&gt;Initialize a variable (complement); its value will be the result of the target minus the current number [Major logic of the solution] - for every number in the list&lt;/li&gt;
&lt;li&gt;if the complement exists in the dictionary, then we return the index of the complement in the dictionary and the current index from the loop we are iterating with.&lt;/li&gt;
&lt;li&gt;else we add this complement into our dictionary (both key and value) which means
&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:
    def twoSum(self, nums: List[int], target: int) -&amp;gt; List[int]:
        num_index = {}

        for i, num in enumerate(nums):
            complement = target - num

            if complement in num_index:
                return [num_index[complement], i]
            else:
                num_index[nums[i]] = i

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

&lt;/div&gt;



&lt;p&gt;Soln 2 (Bruteforce):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; iterate through the list using index i (outer loop)&lt;/li&gt;
&lt;li&gt; iterate through the list using index j starting from (i + j) to avoid duplicates (inner loop)&lt;/li&gt;
&lt;li&gt;compare the sum of both elements at indices i and j to the target&lt;/li&gt;
&lt;li&gt;if the sum is equal to the target then return the indices [i, j]
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(len(nums)):
    for j in range(i + 1, len(nums)):
        if nums[i] + nums[j] == target:
            return([i, j])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Hashmaps use key-value pairs, try to solve questions with methods you know before trying to improve them. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>242. Valid Anagram</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Fri, 07 Jun 2024 16:31:46 +0000</pubDate>
      <link>https://dev.to/whereislijah/242-valid-anagram-35o7</link>
      <guid>https://dev.to/whereislijah/242-valid-anagram-35o7</guid>
      <description>&lt;p&gt;Topic: Array &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;Soln 1 (dictonary solution):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compare the lengths of both strings.&lt;/li&gt;
&lt;li&gt;If they are not the same length, they are not anagrams.&lt;/li&gt;
&lt;li&gt;Create a new dictionary called count.&lt;/li&gt;
&lt;li&gt;Loop through the characters in s:&lt;/li&gt;
&lt;li&gt;If the character already exists in the dictionary, then increment its value by 1.&lt;/li&gt;
&lt;li&gt;Else, assign the value of the key to 1.&lt;/li&gt;
&lt;li&gt;Loop through the characters in t:&lt;/li&gt;
&lt;li&gt;If the character does not exist in the dictionary or the character count is 0, then return False.&lt;/li&gt;
&lt;li&gt;Else, decrement the value of the character by 1.&lt;/li&gt;
&lt;li&gt;Return True.
&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:
    def isAnagram(self, s: str, t: str) -&amp;gt; bool:
        if len(s) != len(t):
            return False

        count = {}

        for char in s:
            if char in count:
                count[char]+=1
            else:
                count[char] = 1

        for char in t:
            if char not in count or count[char] == 0:
                return False
            count[char]-=1
        return True 

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

&lt;/div&gt;



&lt;p&gt;Soln 2 (set solution):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compare the lengths of both strings.&lt;/li&gt;
&lt;li&gt;If they are not the same length, they are not anagrams.&lt;/li&gt;
&lt;li&gt;Loop through the characters in the set of s (set removes the duplicates):&lt;/li&gt;
&lt;li&gt;If the count of any character in s is not equal to the count of the same character in t:&lt;/li&gt;
&lt;li&gt;then return False.&lt;/li&gt;
&lt;li&gt;If all character counts match, then the strings are anagrams (return True).
&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:
    def isAnagram(self, s: str, t: str) -&amp;gt; bool:
        if len(s) != len(t):
            return False 
        for i in set(s): 
            if s.count(i) != t.count(i):
                return False
        return True   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soln 3:&lt;br&gt;
A very obvious solution:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Alphabetically sort both strings (s, t) and compare them. 
Returns True if they both are the same length and contain the same characters, else False if they do not. (Yes, all on the same line.)
&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:
    def isAnagram(self, s: str, t: str) -&amp;gt; bool:
        return sorted(s) == sorted(t)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes:&lt;br&gt;
Sets &amp;amp; dictionaries are unordered and unique, although dictionaries can contain duplicates values &lt;/p&gt;

</description>
    </item>
    <item>
      <title>217. Contains Duplicate</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Fri, 07 Jun 2024 06:09:59 +0000</pubDate>
      <link>https://dev.to/whereislijah/217-contains-duplicate-4nc8</link>
      <guid>https://dev.to/whereislijah/217-contains-duplicate-4nc8</guid>
      <description>&lt;p&gt;Topic: Array &amp;amp; Hashing&lt;/p&gt;

&lt;p&gt;I came up with 2 different solutions&lt;/p&gt;

&lt;p&gt;Soln 1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compare the length of the array with the length of the set created from the array&lt;/li&gt;
&lt;li&gt;Sets is a data structure that does not contain duplicates elements
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return len(nums) != len(set(nums))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soln 2: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declare a set as a variable&lt;/li&gt;
&lt;li&gt;loop through the integers in the array&lt;/li&gt;
&lt;li&gt;if the integer does not exist in the set, add it to the set&lt;/li&gt;
&lt;li&gt;else, it means a duplicate exists
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         count = set()

         for n in nums:
             if n in count:
               return True
             count.add(n)

         return False

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

&lt;/div&gt;



&lt;p&gt;Notes: I worked on this before and just needed it to re-introduce myself into leetcoding&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Leetcode accountability yet again...</title>
      <dc:creator>WhereIsLijah</dc:creator>
      <pubDate>Fri, 07 Jun 2024 04:13:05 +0000</pubDate>
      <link>https://dev.to/whereislijah/leetcode-accountability-yet-again-43pd</link>
      <guid>https://dev.to/whereislijah/leetcode-accountability-yet-again-43pd</guid>
      <description>&lt;p&gt;One thing I have struggled with in recent months is leetcoding, Due to a lack of accountability, I solve a few questions and then just forget about doing them. I know most developers do them for the sole purpose of interviewing, but I guess I primarily want to do this to get better at solving problems. &lt;/p&gt;

&lt;p&gt;I'm restarting with Neetcode 150 questions, 1 question a day, due to other life activities, and the moment i get sucked back in i'll increase the number of daily questions i solve. &lt;/p&gt;

&lt;p&gt;I'll be solving all questions in &lt;strong&gt;Python&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>python</category>
      <category>beginners</category>
      <category>neetcode</category>
    </item>
  </channel>
</rss>
