📅 Day 15 / 100 – #100DaysOfCode Solved Two Sum II – Input Array Is Sorted on LeetCode 💻 Today’s focus was on improving problem-solving by leveraging sorted array properties. 🔍 What I learned: Practiced the HashMap approach (O(n) time, O(n) space) Understood how 1-based indexing works in this problem Realized that since the array is sorted, this can be optimized further using the Two Pointer technique (O(1) space) 🔥 🧠 Key Insight: Don’t just solve the problem — look for constraints (like sorted arrays) to optimize further. ⚡ Next Step: Will implement the Two Pointer approach to achieve constant space complexity. Consistency > Motivation. Let’s keep building 💪 #Day15 #100DaysOfCode #DSA #LeetCode #ProblemSolving #CodingJourney
100DaysOfCode Day 15: Solved Two Sum II on LeetCode
More Relevant Posts
-
Day 83 of #100DaysOfCode Today I solved "Binary Tree Maximum Path Sum" on LeetCode using DFS + Recursion. Key Idea: At every node, we calculate the maximum path sum passing through it. But here’s the twist We ignore negative paths because they reduce the total sum. Approach: • Recursively get the max path sum from left and right subtrees • Ignore negative values using max(0, …) • Update the global answer as: root->val + left + right • Return to parent: root->val + max(left, right) This ensures we consider both: Path passing through the node Path extending upwards Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Greedy choice (ignore negative paths) Time Complexity: O(n) Space Complexity: O(h) This problem really sharpened my understanding of handling multiple path possibilities in trees From simple traversals to advanced patterns — growth is visible #Day83 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
-
Day 38 Today I solved: Majority Element (LeetCode 169) 💡 Problem: Given an array, find the element that appears more than [n/2] times. You can assume that the majority element always exists. 💡 My Approach: I used a HashMap (frequency counting) approach: 1️⃣ Traverse the array and store frequency of each element 2️⃣ Calculate n/2 3️⃣ Iterate through the map 👉 Return the element whose frequency is greater than n/2 💡 Key Insight: The majority element will always dominate the count (> n/2), so once counted, it’s easy to identify ✅ ⚡ Complexity: Time: O(n) Space: O(n) #LeetCode #DSA #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 23/100 — LeetCode Challenge Today's problem: Find Peak Element 🧠 Concept: Binary Search on Unsorted Data 💡 Key Idea: Even without a sorted array, binary search can be applied by analyzing the slope between elements and reducing the search space. ⚡ Time Complexity: O(log n) 📂 Solutions Repository https://lnkd.in/gkFh2mPZ A great example of how binary search is more about reducing the search space than just working on sorted arrays. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
-
Day 46 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Geometric Sum using Recursion We were given an integer n. Task was to find the sum: 1 + 1/3 + 1/3² + ... + 1/3ⁿ Using recursion. 💻 Approach 🔹️Define a recursive function sum(n). 🔹️Base case: ▪️If n == 0 → return 1 🔹️Recursive case: ▪️Return sum(n-1) + 1/(3ⁿ) Each call adds one term. And moves toward smaller n. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion can be used for summation of series. ▫️Each recursive call adds one term to the result. ▫️Understanding base case is important to stop recursion. ▫️Power calculations are common in series problems. Day 46 completed. Getting more comfortable with recursive formulas 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 68 of #100DaysOfCode 🔥 Solved Median of Two Sorted Arrays (LeetCode Q4) today! 💡 Problem Insight: Find the median of two sorted arrays in an efficient way without merging them. 🧠 Approach: - Use Binary Search on the smaller array - Partition both arrays such that left side has smaller elements and right side has larger ones - Ensure correct balance of elements on both sides ⚙️ Algorithm: - Apply binary search to find correct partition - Check conditions for valid split - If valid → calculate median based on total length - Else → adjust search space ⏱️ Complexity: - Time: O(log(min(n, m))) - Space: O(1) 📌 Key Learning: Brute force is not always the answer — smart partitioning can optimize everything. 💬 Think smart, not hard. #DSA #LeetCode #BinarySearch #100DaysOfCode #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 LeetCode 438 — Find All Anagrams in a String | Solved ✅ Solved a Medium-level problem using Sliding Window + Hashing. 🔍 Approach: Maintained a dynamic window and tracked character frequencies to efficiently detect anagrams without re-sorting. ⚡ Complexity: Time: O(n) Space: O(1) (optimized using fixed-size array) 💡 Key Learning: Optimizing from hashmap → array significantly improves performance in character-based problems. Step by step, getting better at pattern recognition 🧠 #LeetCode #DSA #SlidingWindow #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 36 – #100DaysOfLeetCode Challenge Today I worked on the problem “Subarray Sum Equals K.” Problem Overview: Given an array of integers and an integer k, the task is to find the total number of continuous subarrays whose sum equals k. Example: Input: nums = [1, 1, 1], k = 2 Output: 2 Explanation: The subarrays [1,1] (from index 0→1 and 1→2) both sum to 2. Approach – Prefix Sum + HashMap To solve this efficiently: 🔹 Use a running sum (prefix sum) while iterating through the array 🔹 Store the frequency of prefix sums in a HashMap 🔹 At each step, check if (current_sum - k) exists in the map 🔹 If it exists, add its frequency to the count Time Complexity: O(n) Space Complexity: O(n) Key Learning: This problem highlights how prefix sums combined with hashing can drastically optimize problems involving subarrays and cumulative sums. Day 36 of my #100DaysOfLeetCode journey — staying consistent and improving problem-solving skills one day at a time!
To view or add a comment, sign in
-
-
3761. Minimum Absolute Distance Between Mirror Pairs | Medium ✅ Today's daily challenge was a fun one, pairs of numbers that are digit-reversals of each other hiding inside an array. Loved how this problem forces you to think about relationships between elements in a non-obvious way. Watch my full solution walkthrough in the video! Drop a comment if you've solved this one, I'd love to hear your approach 💡 #LeetCode #DailyLeetCode #CodingChallenge #HashTable #Arrays #SoftwareEngineering #DSA #CodingInterview #TechCareers #ProblemSolving
To view or add a comment, sign in
-
Day 37 Today I solved: Subarray Sum Equals K (LeetCode 560) 💡 Problem: Given an array and an integer k, find the total number of subarrays whose sum equals k. 💡 My Approach: I used Prefix Sum + HashMap for an optimal solution: 1️⃣ Compute running prefix sum while traversing the array 2️⃣ Use a HashMap to store frequency of prefix sums 3️⃣ At each index, check: 👉 If (currentSum - k) exists in map → we found subarrays 4️⃣ Add its frequency to the count 5️⃣ Update the map with current prefix sum 💡 Key Insight: If prefixSum[j] - prefixSum[i] = k 👉 Then prefixSum[i] = prefixSum[j] - k So instead of checking all subarrays ❌ We use previously seen sums to get result in O(n) ✅ ⚡ Complexity: Time: O(n) Space: O(n) 🔥 Takeaway: Prefix Sum + HashMap is a powerful combo for subarray problems 🚀 #LeetCode #DSA #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 239 of #500DaysOfCode Solved LeetCode 3488 – Closest Equal Element Queries 🔁 💡 Approach: Store indices of each value using a hashmap Since array is circular, handle wrap-around distance For each query: Use binary search (lower_bound) to find closest index Check neighbors (left & right) Compute min circular distance ⚡ Key Insight: Only adjacent indices in sorted list matter Circular distance = min(|i-j|, n - |i-j|) ⏱️ Complexity: Time: O(n + q log n) Space: O(n) ✨ Takeaway: Combining hashing + binary search + circular logic makes this efficient. Consistency stacking up 🔥 #LeetCode #DSA #BinarySearch #HashMap #Arrays
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development