DEV Community

hassam bin shahid
hassam bin shahid

Posted on

πŸš€ DSA Journey | Solved 3 LeetCode Problems in Python

Today's practice focused on three different algorithmic patterns, each reinforcing an important concept in problem solving and writing efficient code.

βœ… 1. To Lower Case (LeetCode 709)

Concept: String Manipulation

class Solution:
    def toLowerCase(self, s: str) -> str:
        return s.lower()
Enter fullscreen mode Exit fullscreen mode

Key Takeaway: Reviewed string operations and learned how character conversion can also be implemented using ASCII values.


βœ… 2. Product of Array Except Self (LeetCode 238)

Concept: Prefix & Suffix Products

class Solution:
    def productExceptSelf(self, nums):
        n = len(nums)
        ans = [1] * n

        prefix = 1
        for i in range(n):
            ans[i] = prefix
            prefix *= nums[i]

        suffix = 1
        for i in range(n - 1, -1, -1):
            ans[i] *= suffix
            suffix *= nums[i]

        return ans
Enter fullscreen mode Exit fullscreen mode

Key Takeaway: Practiced solving array problems in O(n) time without using division by leveraging prefix and suffix products.


βœ… 3. Maximum Average Subarray I (LeetCode 643)

Concept: Sliding Window

class Solution:
    def findMaxAverage(self, nums, k):
        window_sum = sum(nums[:k])
        max_sum = window_sum

        for i in range(k, len(nums)):
            window_sum += nums[i] - nums[i - k]
            max_sum = max(max_sum, window_sum)

        return max_sum / k
Enter fullscreen mode Exit fullscreen mode

Key Takeaway: Applied the Sliding Window technique to optimize repeated calculations and reduce the time complexity to O(n).


Every LeetCode problem teaches more than just syntaxβ€”it strengthens analytical thinking, algorithm selection, and code optimization. Consistency in practice is helping me build a stronger foundation in Data Structures and Algorithms, one problem at a time.

I'm looking forward to tackling more challenging problems and continuing to grow as a software engineer.

πŸ’» Language: Python
πŸ“š Topics Covered: String Manipulation, Prefix & Suffix Products, Sliding Window

LeetCode #Python #DSA #Algorithms #ProblemSolving #SoftwareEngineering #CodingJourney #100DaysOfCode #Developer #Programming

Top comments (0)