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()
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
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
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
Top comments (0)