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

Piyush KumarPiyush Kumar
4 min read

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

0
Subscribe to my newsletter

Read articles from Piyush Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Piyush Kumar
Piyush Kumar

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!