Gopal Goswami’s Post

🚀 Solved Two Sum Problem with Optimal Approach | LeetCode Today I solved the classic Two Sum problem and focused on writing an efficient solution rather than just making it work. 💡 Problem: Given an array of integers, return indices of two numbers such that they add up to a target. ⚡ Approach: Instead of using the brute force method, I used a HashMap (dictionary) to store elements and their indices. 👉 Logic: Traverse the array once For each element, calculate: difference = target - current value Check if difference already exists in the HashMap If yes → return indices instantly 🔥 Time & Space Complexity: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) 🚀 Optimization: Improved from brute force O(n²) → O(n) using HashMap lookup 🏆 Result: ✔️ Accepted (All test cases passed) ✔️ Runtime: 0 ms (Beats 100%) 📌 Key Learnings: HashMap enables constant time lookup Thinking in terms of complement simplifies problems Optimization is key in coding interviews 💻 Tech Stack: Python | Data Structures & Algorithms 📈 Consistency + Practice = Growth 🚀 #leetcode #dsa #python #algorithms #coding #programming #softwareengineering #100DaysOfCode #tech

  • graphical user interface

To view or add a comment, sign in

Explore content categories