DEV Community

hassam bin shahid
hassam bin shahid

Posted on

🚀 Solving 3 LeetCode Problems: Arrays, Strings, and Greedy Algorithms

As part of my daily Data Structures and Algorithms (DSA) practice, today I focused on solving three LeetCode problems that strengthened my understanding of arrays, string manipulation, and greedy algorithms.
Consistent practice is helping me improve my problem-solving skills and prepare for coding interviews.


📌 Problems Solved

1. Monotonic Array (LeetCode 896)

Concept: Arrays

The goal was to determine whether an array is entirely non-decreasing or non-increasing.

What I Learned

  • How to identify increasing and decreasing trends in a single traversal.
  • Why checking both possibilities simultaneously leads to an efficient solution.
  • Time Complexity: O(n)
  • Space Complexity: O(1)

2. String Compression (LeetCode 443)

Concept: Two Pointers, Strings

This problem required compressing a character array in-place without using extra memory.

What I Learned

  • Applying the Two Pointers technique for reading and writing.
  • Performing in-place modifications efficiently.
  • Handling multi-digit counts correctly during compression.
  • Time Complexity: O(n)
  • Space Complexity: O(1)

3. Jump Game II (LeetCode 45)

Concept: Greedy Algorithm

The challenge was to find the minimum number of jumps needed to reach the last index.

What I Learned

  • How greedy algorithms can produce optimal solutions.
  • Tracking the farthest reachable position while minimizing jumps.
  • Understanding why greedy outperforms brute-force approaches for this problem.
  • Time Complexity: O(n)
  • Space Complexity: O(1)

💡 Key Takeaways

Today's practice reinforced several important concepts:

  • Efficient array traversal techniques.
  • In-place string manipulation using Two Pointers.
  • Solving optimization problems with Greedy Algorithms.
  • Writing clean, optimized Python code with linear time complexity whenever possible.

The more problems I solve, the better I become at recognizing patterns and selecting the right algorithmic approach.


🎯 Next Goal

I'm committed to solving LeetCode problems every day to strengthen my fundamentals in Data Structures & Algorithms and become a better software engineer.

If you're also practicing DSA, I'd love to hear about your favorite problem-solving strategies or discuss different approaches in the comments.

Happy Coding! 🚀


🏷️ Tags

#leetcode #python #algorithms #datastructures

Top comments (0)