πŸš€ 90 Days of DSA – Day 7: Strings & Arrays Deep Dive

Piyush KumarPiyush Kumar
2 min read

πŸ“… Day 7 of my #90DaysOfDSA journey was packed with string and array-based problems. From detecting duplicates to checking isomorphism between strings β€” it was all about pattern recognition and data structure efficiency.

πŸ”— Full Repo Link: DSA-Problems β†’ Day 7


βœ… Problem 1: Contains Duplicate

πŸ”— View Code

pythonCopyEditclass Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        return len(set(nums)) < len(nums)

πŸ“Œ Logic: Convert the list to a set and compare lengths. If set size is smaller, duplicates exist.


βœ… Problem 2: First Unique Character in a String

πŸ”— View Code

from collections import Counter
class Solution:
    def firstUniqChar(self, s: str) -> int:
        dict1=Counter(s)
        for i in dict1.keys():
            if dict1[i] == 1:
                return s.index(i)
        return -1

πŸ“Œ Logic: Iterate through characters and return the index of the first character that appears exactly once.


βœ… Problem 3: Isomorphic Strings

πŸ”— View Code

pythonCopyEditclass Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        return len(set(s)) == len(set(t)) == len(set(zip(s, t)))

πŸ“Œ Logic: Ensure the number of unique characters and their mappings match using set(zip(s, t)).


βœ… Problem 4: Valid Anagram

πŸ”— View Code

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        if len(s)!=len(t):
            return False
        sets=set(s)
        for i in sets:
            if s.count(i)!=t.count(i):
                return False
        return True

πŸ“Œ Logic: Check if both strings have the same character counts.


βœ… Problem 5: Intersection of Two Arrays II

πŸ”— View Code

from collections import Counter

class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        count1 = Counter(nums1)
        result = []

        for num in nums2:
            if count1[num] > 0:
                result.append(num)
                count1[num] -= 1

        return result

πŸ“Œ Logic: Use Counter to track occurrences and build the intersection using minimum counts.


πŸ”— All Code Files

Browse and fork the complete Day 7 progress here:
πŸ“ GitHub Repo – Day 7


πŸ“ˆ Reflections

  • Practiced frequency-based solutions and mapping logic

  • Learned more about efficient Python tricks like set(zip(s, t))

  • Starting to spot patterns quickly in string and array problems!


πŸš€ Connect with Me

Follow my journey on Twitter @CodeWithPiyush and explore my projects and tools built with AI and Python.

0
Subscribe to my newsletter

Read articles from Piyush Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Piyush Kumar
Piyush Kumar

Hey there! I’m Piyush Kumar, a curious mind on a mission to master Data Structures & Algorithms β€” one problem at a time. I’m not just solving questions; I’m building habits, debugging my thinking, and documenting the highs and lows of my coding grind. Whether it’s arrays at midnight, graph theory before coffee, or that satisfying β€œAC” moment after 17 failed attempts β€” I’m sharing it all openly. πŸ“š Currently on a 90-day DSA challenge, I post daily blogs and code logs that unpack: Real-world problem-solving strategies Patterns and techniques I learn (and unlearn) Honest reflections on growth, failure, and consistency Along the way, I’m also exploring how to apply AI to meaningful problems β€” because I believe in learning out loud and building in public. Let’s connect if you’re into: Open learning journeys πŸš€ Problem-solving and pattern recognition 🧠 Building cool things with code βš™οΈ ⚑ Follow along and let’s decode DSA β€” together!