Skip to main content

Command Palette

Search for a command to run...

Day 4: From Brute Force to Optimization - My Data Structures & Algorithms Learning Journey πŸš€

Published
β€’4 min read
P

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!

TL;DR: Today I tackled Container With Most Water and Roman to Integer problems, focusing on building solid foundations before optimization. Here's what I learned and how you can apply these concepts in technical interviews.


🎯 What HR Recruiters Need to Know About This Post

For Hiring Managers & Technical Recruiters: This post demonstrates:

  • βœ… Problem-solving methodology - I build brute force solutions first, then optimize

  • βœ… Learning agility - Actively researching advanced techniques (Two Pointer method)

  • βœ… Code documentation - All solutions available on GitHub with clear explanations

  • βœ… Consistency - Day 4 of a committed 90-day learning journey

  • βœ… Growth mindset - Acknowledging inefficiencies while planning improvements


πŸ“š Today's Technical Deep Dive

Problem 1: Container With Most Water - The Foundation-First Approach

The Challenge: Find two lines that form a container holding the maximum amount of water.

My Strategy:

  1. Start with Brute Force (O(nΒ²) time complexity)

    • Check every possible pair of lines

    • Calculate area for each pair

    • Track maximum area found

Why Brute Force First?

  • 🧠 Builds logical thinking - Essential for technical interviews

  • πŸ” Reveals edge cases - Helps understand the problem deeply

  • πŸ’‘ Interview strategy - Many companies appreciate seeing your thought process

from typing import List

class Solution:
    def maxArea(self, height: List[int]) -> int:
        maxvol = 0  # Stores the maximum area found

        # Try all possible pairs of lines (brute-force approach)
        for i in range(len(height) - 1):
            for j in range(i + 1, len(height)):
                # Water is limited by the shorter line
                minheight = min(height[i], height[j])

                # Width is the horizontal distance between lines
                width = j - i

                # Area = minheight * width
                temp = minheight * width

                # Update max area if current is greater
                maxvol = max(maxvol, temp)

        return maxvol

Next Step: Two Pointer Optimization (O(n) solution)

  • I'm studying this technique for tomorrow's implementation

  • This shows progression from basic to advanced solutions

Problem 2: Roman to Integer - Clean String Processing

Key Learning: Dictionary mapping + reverse traversal for handling subtraction cases.

class Solution:
    def romanToInt(self, s: str) -> int:
        # Dictionary to map Roman numerals to their integer values
        roman = {
            'I': 1,
            'V': 5,
            'X': 10,
            'L': 50,
            'C': 100,
            'D': 500,
            'M': 1000
        }

        total = 0         # This will store the final integer result
        prev_value = 0    # Tracks the value of the previous Roman numeral

        # Iterate over the string in reverse (right to left)
        for char in reversed(s):
            value = roman[char]  # Get the integer value of the current Roman numeral

            # If the current value is less than the previous one, we subtract it
            # Example: IV -> 5 (V) comes before 1 (I), so we subtract 1 -> total = 4
            if value < prev_value:
                total -= value
            else:
                # Otherwise, we add it to the total
                total += value

            # Update prev_value to the current one for the next iteration
            prev_value = value

        return total  # Return the final converted integer

🎯 Key Takeaways for Beginners Following This Journey

1. Master the Basics Before Optimization

  • Brute force solutions show you understand the problem

  • Optimization comes naturally once logic is solid

  • Interview tip: Always explain your brute force approach first

2. Time Complexity Matters (But Understanding Matters More)

  • O(nΒ²) vs O(n) - know the difference

  • Be ready to discuss trade-offs in interviews

  • Practice explaining complexity in simple terms

3. Document Your Learning Process

  • GitHub repository with clean, commented code

  • Shows continuous learning to potential employers

  • Helps other developers learn from your journey


πŸ“ˆ Progress Tracking & Metrics

Day 4 Stats:

  • βœ… 2 Problems solved

  • βœ… 1 New technique researched (Two Pointer)

  • βœ… Code documented and pushed to GitHub

  • βœ… Learning methodology refined

Consistency Score: 4/90 days completed (4.4% progress) πŸ”₯


  • GitHub Repository: Day 4 Solutions

  • Problem Sources: LeetCode, HackerRank

  • Next Study Topic: Two Pointer Technique Implementation


πŸ’Ό Why This Matters for Your Career

For Job Seekers:

  • Demonstrates consistent learning habits

  • Shows ability to break down complex problems

  • Proves commitment to technical growth

  • Documents problem-solving methodology

For Students:

  • Learn alongside my journey

  • See real problem-solving in action

  • Understand interview preparation strategies

  • Build your own coding discipline


πŸ“’ Join My Learning Journey!

Following my #90DaysOfDSA challenge?

  • ⭐ Star my GitHub repository

  • πŸ’¬ Share your own solutions in the comments

  • πŸ”” Follow for daily updates and insights

  • πŸ“§ Connect with me for collaboration opportunities

For Recruiters: Feel free to reach out - I'm actively seeking ai development opportunities and would love to discuss how my problem-solving approach can benefit your team.


Day 4 complete! Tomorrow we optimize. The journey continues... πŸ’ͺ

Tags: #DSA #DataStructures #Algorithms #TechnicalInterview #SoftwareDeveloper #ProblemSolving #CodingChallenge #JobSearch #Programming #LeetCode #GitHub #CareerGrowth #TechSkills

More from this blog

M

Mastering DSA: Daily Coding Challenges

9 posts

Follow My daily journey mastering Data Structures & Algorithms through coding challenges, practical solutions, and step-by-step learningβ€”from basics to optimized approaches.