Posts

Showing posts from August, 2025

Two Sum

  My Java Journey with LeetCode's Two Sum: Yo, what’s good? Today, I dove into the Two Sum problem on LeetCode, and it was a wild ride. I’m jotting this down as part of my coding journal to track my thought process, the mistakes I made, and how I cracked it with some help from my virtual coding buddy, Grok. This isn’t just about getting the answer—it’s about learning how to think through problems like a pro. Let’s break it down, Java style! The Problem Two Sum is pretty chill at first glance. You’re given an array of integers nums and a target sum, and you need to return the indices of two numbers that add up to the target. For example, if nums = [2, 7, 11, 15] and target = 9 , you return [0, 1] because nums[0] + nums[1] = 2 + 7 = 9 . The rules? You can’t use the same element twice, and there’s exactly one solution. My First Stab: Brute-Force with Nested Loops When I read the problem, my brain was like, “Easy, just check every pair of numbers!” So, my first instinct was ...