🚀 DSA Progress Update | Solved 3 LeetCode Problems
Today's LeetCode session was focused on strengthening my understanding of three fundamental problem-solving patterns that frequently appear in technical interviews.
✅ Problems Solved
🔹 682. Baseball Game
- Pattern: Stack
- Built a score history using a stack to efficiently process operations such as
+,D, andC. - Time Complexity: O(n)
stack = []
for op in operations:
if op == "+":
stack.append(stack[-1] + stack[-2])
elif op == "D":
stack.append(2 * stack[-1])
elif op == "C":
stack.pop()
else:
stack.append(int(op))
return sum(stack)
🔹 1456. Maximum Number of Vowels in a Substring of Given Length
- Pattern: Sliding Window
- Optimized the brute-force approach by maintaining a fixed-size window and updating the vowel count in constant time.
- Time Complexity: O(n)
vowels = {'a', 'e', 'i', 'o', 'u'}
count = sum(1 for ch in s[:k] if ch in vowels)
maximum = count
for i in range(k, len(s)):
if s[i-k] in vowels:
count -= 1
if s[i] in vowels:
count += 1
maximum = max(maximum, count)
return maximum
🔹 134. Gas Station
- Pattern: Greedy Algorithm
- Learned how tracking the fuel balance helps identify the only valid starting station while solving the problem in linear time.
- Time Complexity: O(n)
if sum(gas) < sum(cost):
return -1
start = 0
tank = 0
for i in range(len(gas)):
tank += gas[i] - cost[i]
if tank < 0:
start = i + 1
tank = 0
return start
💡 Key Takeaways
✔️ Choosing the right algorithmic pattern is often more important than writing more code.
✔️ Today's practice reinforced three essential interview concepts:
- Stack
- Sliding Window
- Greedy Algorithm
Every problem I solve improves not only my coding skills but also my ability to analyze problems, optimize solutions, and think like a software engineer.
I'm committed to solving LeetCode problems consistently and documenting my progress as I continue growing in Data Structures & Algorithms.
Top comments (0)