Good evening, folks 👋 Day 2–3 / 100 — #100DaysOfCode Maintained a 2-day consistency streak by focusing on core array problems on LeetCode and reinforcing fundamental problem-solving patterns. ✅ Problems Solved 121. Best Time to Buy and Sell Stock → Optimized using a single-pass greedy approach by tracking minimum price and maximum profit. 283. Move Zeroes → In-place solution using the two-pointer technique with O(1) extra space. 26. Remove Duplicates from Sorted Array → Efficient slow–fast pointer strategy leveraging the sorted property. 1. Two Sum → Solved using a hash map to achieve O(n) time complexity. 🔍 Key Takeaways Most array problems reduce to pattern recognition (two pointers, hashing, greedy). Writing optimal solutions is easier once constraints and invariants are clear. Revisiting “easy” problems with an optimization mindset is still valuable. #100DaysOfCode #LeetCode #DSA #ProblemSolving #SoftwareEngineering #Consistency
100DaysOfCode: Array Problems on LeetCode
More Relevant Posts
-
Day 37/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 48 – Rotate Image (Medium) 🧠 Approach: First transpose the matrix (swap rows with columns). Then reverse each row to achieve a 90-degree clockwise rotation in place. 💻 Solution: class Solution: def rotate(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. """ n = len(matrix) for i in range(n): for j in range(i + 1, n): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] for i in range(n): matrix[i].reverse() ⏱ Time | Space: O(n^2) | O(1) 📌 Key Takeaway: Breaking a complex transformation into simple matrix operations (transpose + reverse) makes in-place problems much easier to solve. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🔥 Day 147 of My LeetCode Journey — Problem 387: First Unique Character in a String 💡 Problem Insight: Today’s problem was to find the first non-repeating character in a string. Simple requirement — but only if you resist the urge to rescan the string repeatedly. 🧠 Concept Highlight: The clean approach is frequency counting + single scan: First pass → count character occurrences Second pass → return the first character with frequency 1 This guarantees O(n) time and avoids unnecessary nested checks. The real lesson: separate counting from decision-making. 💪 Key Takeaway: When a problem asks for “first” + “unique,” you almost always need two passes or a data structure that remembers order. Trying to do it in one naive loop leads to fragile logic. ✨ Daily Reflection: This problem reinforces that clarity beats cleverness. Clean state tracking makes string problems predictable and easy to reason about. #Day147 #LeetCode #Strings #HashMap #ProblemSolving #DSA #CodingJourney #ThinkClearly
To view or add a comment, sign in
-
-
Day 32/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 46 – Permutations (Medium) 🧠 Approach: Fix one position at a time by swapping the current index with every possible remaining element, generate permutations recursively, and backtrack by undoing the swap. 💻 Solution: class Solution: def permute(self, nums: List[int]) -> List[List[int]]: res = [] def backtrack(idx): if idx == len(nums): res.append(nums[:]) return for i in range(idx, len(nums)): nums[idx], nums[i] = nums[i], nums[idx] backtrack(idx+1) nums[idx], nums[i] = nums[i], nums[idx] backtrack(0) return res ⏱ Time | Space: O(n × n!) | O(n) 📌 Key Takeaway: Permutation problems often use in-place backtracking, where swapping elements avoids extra space while exploring all possible arrangements. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
Day 33/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 350 – Intersection of Two Arrays II (Easy) 🧠 Approach: Sort both arrays and use a two-pointer technique to traverse them together. When elements match, add to the result and move both pointers; otherwise, move the pointer pointing to the smaller element. 💻 Solution: class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: nums1.sort() nums2.sort() i = j = 0 result = [] while i < len(nums1) and j < len(nums2): if nums1[i] == nums2[j]: result.append(nums1[i]) i += 1 j += 1 elif nums1[i] < nums2[j]: i += 1 else: j += 1 return result ⏱ Time | Space: O(n log n + m log m) | O(1) 📌 Key Takeaway: Sorting combined with the two-pointer technique is an effective way to handle problems involving frequency-based intersections. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
📌 LeetCode Practice Update Worked on two array problems today on LeetCode, both focused on in-place modifications and pointer-based traversal. 🟢 Remove Duplicates from Sorted Array (26) Since the array is already sorted, duplicates naturally appear next to each other. I used a two-pointer approach where one pointer keeps track of the last unique element while the other scans the array. Whenever a new value is encountered, it’s placed at the next valid position. This keeps all unique elements at the front of the array without using any extra space. 🟢 Remove Element (27) This problem required removing all occurrences of a given value in-place. The approach was again pointer-based — iterating through the array and overwriting elements that should be kept. The key idea was that the order beyond the returned length doesn’t matter, which simplifies the logic and allows a clean O(n) solution with constant space. 📘 What today’s practice reinforced ✔ How problem constraints guide the optimal approach ✔ Writing clean in-place solutions without extra memory ✔ Using pointers to control valid array positions efficiently Staying consistent and focusing on fundamentals rather than rushing through problems. #DSA #LeetCode #Arrays #ProblemSolving #ComputerScience #Consistency
To view or add a comment, sign in
-
🔹 Day 116 – LeetCode Practice 📌 Problem: Sort Colors (LeetCode #75) 📊 Difficulty: Medium 🧠 Problem Overview: Given an array containing only 0, 1, and 2, sort the array in-place so that all 0s come first, followed by 1s, then 2s. 🎯 Key Idea: Since the values are limited to three types, we can count occurrences and rebuild the array in sorted order. ✅ Approach Used: Traverse the array and count how many 0s, 1s, and 2s Overwrite the array with the counted number of 0s, then 1s, then 2s 📈 Submission Results: Status: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory Usage: 43.47 MB (Beats 72.76%) 💡 What this problem reinforces: Counting-based sorting technique In-place array manipulation Using problem constraints to design optimal solutions
To view or add a comment, sign in
-
-
🔥 Day 130 of My LeetCode Journey — Problem 80: Remove Duplicates from Sorted Array II 💡 Problem Insight: This problem is about modifying a sorted array in-place so that each element appears at most twice. The trick isn’t removing duplicates — it’s removing just enough duplicates without breaking order. 🧠 Concept Highlight: The clean solution uses a two-pointer approach: One pointer iterates through the array Another pointer tracks where the next valid element should go Allow insertion only if the current element hasn’t appeared more than twice No extra space, no unnecessary checks — just controlled overwriting. 💪 Key Takeaway: Constraints define behavior. When the rules change (from “once” to “twice”), your logic must adapt — not your time complexity. ✨ Daily Reflection: This problem sharpens in-place thinking. If you can’t reason about overwrite logic cleanly, array problems will keep tripping you up. #Day130 #LeetCode #TwoPointer #InPlaceAlgorithms #ProblemSolving #DSA #CodingJourney #ThinkClean
To view or add a comment, sign in
-
-
LeetCode 1200. Minimum Absolute Difference 🧩 Problem statement - You are given an array of distinct integers. 🔹 Your task is to: - Look at every possible pair of numbers in the array - Compute the absolute difference for each pair - Find the smallest difference that can occur - Return all pairs whose difference equals this minimum value 🔹 Rules for the output: - Each pair must be [a, b] where a < b - Pairs should be returned in ascending order - So the problem is not to find just one pair - It’s to find all pairs that achieve the minimum absolute difference. 🤔 Core intuition If we think naively: - Checking all pairs would work => But that’s O(n²) — too slow for large input Now here’s the key realization: 💡 The closest numbers (minimum difference) will always be neighbors when the array is sorted. Why? => If two numbers are far apart in sorted order, something lies between them That middle value guarantees a smaller difference than skipping over it So we never need to compare non-adjacent elements. 🔑 Why sorting helps Once the array is sorted: - Absolute difference becomes simple subtraction - We only compare: arr[i] - arr[i-1] This immediately reduces the problem from: “Compare everything with everything” to: “Just compare adjacent elements” ⚙️ Final approach (Two-pass strategy) 1. Sort the array 2. First pass : Scan once to find the minimum adjacent difference 3. Second pass : Scan again to collect all pairs matching that difference 4. Return the result Why two passes? Because we must know the minimum difference before deciding which pairs qualify. ⏱️ Complexity Time Complexity: O(n log n) Space Complexity: O(1) Mazhar Imam Khan #LeetCodeDaily #CodingInPublic #TechPrep #SoftwareDeveloper #DSAJourney #CodeEveryday
To view or add a comment, sign in
-
-
#100DaysOfLeetCodeChallenge Day 17/100-LeetCode Challenge 876-MIDDLE-OF-THE-LINKED LIST. 🧩 Problem Statement Given the head of a singly linked list, return the middle node. If there are two middle nodes, return the second middle node. 💡 My Approach I used a basic and clear approach: 1️⃣ First traversal → Count total nodes. 2️⃣ Calculate count / 2. 3️⃣ Second traversal → Move to that position. 4️⃣ Return the middle node. 🛠 Why I Used This Approach? ✅ Easy to understand ✅ Beginner-friendly ✅ No complex pointer logic ✅ Clean O(1) space solution Master basics first, then optimize 🔥 #LeetCode #DSA #LinkedList #ProblemSolving #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 15 / 100 Today I focused on understanding Quick Sort — how partitioning works, pivot selection, and why its average time complexity is O(n log n). Also solved a few LeetCode problems to strengthen sorting concepts and pattern recognition. Slow progress. Consistent effort. Building fundamentals one concept at a time. #QuickSort #DSA #LeetCode #100DaysOfCode #ProblemSolving #Consistency
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