🔥 DSA Series | Day 11 We all have seen the classic Two Sum / Pair Sum problem everywhere — even trending on LinkedIn. But today, a small twist struck my mind… 🤔 👉 What if we need to find ALL UNIQUE pairs that sum to a target? 💡 Problem Input: arr = [1,1,2,2,3,3] target = 4 👉 Expected Output: [[1,3], [2,2]] 🚀 Approach (Two Pointers + Sorting) Instead of brute force ❌ (O(n²)), we: Sort the array Use two pointers (i, j) Move intelligently based on sum Skip duplicates to ensure uniqueness 🧠 Code class Solution: def uniquePairs(self, arr: list[int], target: int) -> list[list[int]]: arr.sort() n = len(arr) i = 0 j = n - 1 res = [] while i < j: total = arr[i] + arr[j] if total == target: res.append([arr[i], arr[j]]) i += 1 j -= 1 # 🔁 Skip duplicates while i < j and arr[i] == arr[i - 1]: i += 1 while i < j and arr[j] == arr[j + 1]: j -= 1 elif total < target: i += 1 else: j -= 1 return res if res else [[-1, -1]] ⚡ Complexity ⏱️ Time → O(n log n) (sorting dominates) 📦 Space → O(1) (excluding output) 🔥 Key Insight 💡 Removing duplicates smartly during traversal is more efficient than removing them beforehand. 🧠 Takeaway Sometimes a small twist in a common problem → turns it into a great interview question What would you choose? 🤔 🔹 Hashing (O(n)) 🔹 Two Pointers (O(n log n), cleaner) Let’s discuss 👇 #DSA #Coding #Python #InterviewPrep #ProblemSolving #100DaysOfCode #Tech #Learning
Unique Pairs Summing to Target in Array
More Relevant Posts
-
🚀 Day 10 of DSA Practice: Merge Two Sorted Arrays Today’s problem is a classic and super important for interviews 👇 🧩 Problem Given two sorted arrays, merge them into a single sorted array. 🔍 Example Input: Array 1: [1, 3, 5] Array 2: [2, 4, 6] Output: [1, 2, 3, 4, 5, 6] 💡 Approach 1: Two Pointers (Optimal) Since both arrays are already sorted, we can use a two-pointer technique. 👉 Compare elements from both arrays and pick the smaller one each time. ✅ Time Complexity: O(n + m) ✅ Space Complexity: O(n + m) def merge_sorted_arrays(arr1, arr2): i, j = 0, 0 merged = [] while i < len(arr1) and j < len(arr2): if arr1[i] < arr2[j]: merged.append(arr1[i]) i += 1 else: merged.append(arr2[j]) j += 1 # Add remaining elements merged.extend(arr1[i:]) merged.extend(arr2[j:]) return merged 💡 Approach 2: Using Built-in Sort (Not Optimal) Merge both arrays and then sort. ❌ Time Complexity: O((n+m) log(n+m)) def merge_sorted_arrays(arr1, arr2): return sorted(arr1 + arr2) ⚡ Key Takeaways ✔️ Two-pointer approach is efficient and interview-friendly ✔️ Works because arrays are already sorted ✔️ Foundation for advanced topics like merge sort #Python #CodingJourney #30DaysOfCode #LearnToCode #Programming #Developers #ProblemSolving #PythonBasics
To view or add a comment, sign in
-
🚀 Day 2 – Strengthening My Problem-Solving Mindset Quick reality check 👇 It’s not about how many languages you know… It’s about how well you can think and solve. 📌 Today’s Problem: Multiplication Table Sounds basic, but I approached it with a learning mindset. 🔹 Two Approaches Explored 1️⃣ Iterative Approach (For Loop) 2️⃣ Recursive Approach (Function Calling Itself) 💡 Key Takeaway Same problem. Two approaches. Different ways of thinking. ✔️ Learned how loops execute line by line ✔️ Understood how recursion builds logic internally 📈 Progress Update: From just coding → to understanding how code works Consistency is the real game. #Python #ProblemSolving #100DaysOfCode #Recursion #LearningJourney #DeveloperGrowth
To view or add a comment, sign in
-
-
🚀 𝗗𝗦𝗔 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 – 𝗦𝗼𝗹𝘃𝗶𝗻𝗴 𝗟𝗼𝗻𝗴𝗲𝘀𝘁 𝗦𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴 𝗪𝗶𝘁𝗵𝗼𝘂𝘁 𝗥𝗲𝗽𝗲𝗮𝘁𝗶𝗻𝗴 𝗖𝗵𝗮𝗿𝗮𝗰𝘁𝗲𝗿𝘀 Most people jump straight to the answer… But the real skill is learning how to optimize step by step. 🧩 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 👉 Given a string, find the length of the longest substring without repeating characters. Example: "abcabcbb" → Output: 3 ("abc") 🔗 𝗚𝗶𝘁𝗛𝘂𝗯 𝗖𝗼𝗱𝗲: https://lnkd.in/gTmWkphw 🔴 𝟭. 𝗕𝗿𝘂𝘁𝗲 𝗙𝗼𝗿𝗰𝗲 (O(n³)) Try all possible substrings Check if each substring has unique characters Keep track of max length ❌ Works, but very slow 🟡 𝟮. 𝗕𝗲𝘁𝘁𝗲𝗿 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 (O(n²)) Start from each index Use a set to track characters Stop when duplicate appears ✅ Faster, but still not optimal 🟢 𝟯. 𝗢𝗽𝘁𝗶𝗺𝗮𝗹 – 𝗦𝗹𝗶𝗱𝗶𝗻𝗴 𝗪𝗶𝗻𝗱𝗼𝘄 (O(n)) 💡 𝗜𝗱𝗲𝗮: Don’t restart… adjust the window! Use two pointers (left & right) Expand window (right++) If duplicate → shrink (left++) Track max length 🔥 𝗗𝗿𝘆 𝗥𝘂𝗻 (Simple View) String: "abcabcbb" Step-by-step: a → ab → abc ✅ (max = 3) duplicate found → shrink window continue expanding… 💡 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 Instead of solving again and again, 👉 reuse previous work using a sliding window. 📈 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 Understand → Improve → Optimize This mindset is what clears interviews 🚀 💻 𝗪𝗵𝗲𝗿𝗲 𝗶𝘁 𝗶𝘀 𝘂𝘀𝗲𝗱 ✔ Substring problems ✔ Longest/shortest window problems ✔ Real-time data stream problems #DSA #Coding #Python #SlidingWindow #ProblemSolving #100DaysOfCode #InterviewPrep #LearningJourney
To view or add a comment, sign in
-
-
🚀 Cracked “Top K Frequent Elements” with an Optimal Approach! Today I solved one of the most important interview problems on LeetCode using an efficient Bucket Sort approach (O(n)) — and got it accepted ✅ 🔍 Problem Insight: Instead of sorting (which takes O(n log n)), I used frequency as an index to directly access elements with higher occurrence. 💡 Key Learnings: How to reduce time complexity from O(n log n) → O(n) Using hashmaps (Counter) for frequency counting Applying bucket sort for optimization Writing clean and interview-ready code ⚡ Complexity Analysis: Time Complexity: O(n) (Frequency count + bucket fill + traversal) Space Complexity: O(n) (Hashmap + bucket storage) ⚡ Performance: Runtime: 10 ms 🧠 Approach Summary: Count frequency of elements Store elements in buckets based on frequency Traverse from highest frequency to get top K elements 📌 Consistency > Perfection Every problem solved is one step closer to mastering DSA. #DataStructures #Algorithms #Python #LeetCode #CodingJourney #ProblemSolving #TechGrowth #Consistency #Learning #DSA
To view or add a comment, sign in
-
-
🚀 Day 3 – Building a Problem-Solving Mindset Still on the grind. Still showing up. Because consistency > motivation. 📌 Today’s Problem: Sum of N Natural Numbers Looks simple. But again… the goal is not just solving — it’s how efficiently you think. 🔹 Approaches Explored 1️⃣ Naive Approach → Basic step-by-step addition 2️⃣ Using Recursion → Function calling itself to solve smaller parts 3️⃣ Formula-Based Approach → Direct mathematical solution for maximum efficiency 💡 Key Takeaway Same problem. Three different approaches. Different levels of thinking. ✔️ Learned how multiple solutions exist for one problem ✔️ Understood that efficiency improves with better thinking 📈 Progress Update: From solving problems → to choosing the best approach Consistency is the real unlock 🔑 #Python #ProblemSolving #100DaysOfCode #Consistency #LearningJourney #DeveloperMindset
To view or add a comment, sign in
-
-
🚀 Day 15 of DSA Grind — Sliding Window Maximum (Hard) 🔥 Today’s problem pushed my thinking to the next level — not just solving, but optimizing. 💡 Problem: Given an array, find the maximum in every sliding window of size k. ⚡ Naive Approach: Check every window → O(n * k) ❌ (Too slow) 🔥 Optimized Approach (Deque / Monotonic Queue): Maintain elements in decreasing order Remove useless elements Front always gives maximum ✅ Time Complexity: O(n) ✅ Space Complexity: O(k) 🧠 Key Learning: This problem teaches how to avoid recomputation and use data structures smartly — a must-know pattern for interviews. 📌 Example: Input: [1,2,1,0,4,2,6], k = 3 Output: [2,2,4,4,6] 💬 Big Takeaway: Don’t just solve — optimize like an engineer. Consistency > Motivation 💯 #DSA #LeetCode #SlidingWindow #Python #CodingJourney #TechInterview #100DaysOfCode #SoftwareEngineering #ProblemSolving
To view or add a comment, sign in
-
-
94 pages. Every URL, title & description. Mapped in 3.6 seconds flat. Here's how I used Firecrawl to build a course search tool for students , without touching a single line of HTML. What I got back instantly: → Every course page → Faculty-wise pages with batch details → Descriptions ready for semantic search or RAG I fed this directly into an LLM-powered search index. Now students can ask: "Show me all batches subject-wise for May 2026" ...and get accurate results, without touching a single HTML tag. This is what I mean when I say Firecrawl is infrastructure for AI, not just a scraper. The [/map](https://lnkd.in/dsJ7c4nH) endpoint is criminally underrated. One call. Structured output. Production-ready. What website would you map first? Drop it below — I'll show you what the output looks like. 👇 #Firecrawl #WebScraping #RAG #AItools #Python #BuildInPublic #EdTech
To view or add a comment, sign in
-
-
"SHINE" In software, complexity is the friction that creates brilliance. Every bug is a facet being cut; every optimized query is a layer of dust removed. It's aren't just writing a script—it is a beacon in the dark. Minimize the opacity. Maximize the output. Let the code be the light Don't just execute code. Ignite it. Don't just build a tool. Build a beacon. Code with logic, but design with soul. #code #Project #ML #AI #MultimodalAI #NeonAesthetic #Glassmorphism #Design #WebDesign #TechInnovation #Python
To view or add a comment, sign in
-
Just solved a LeetCode problem with 100% runtime efficiency — but here’s the real strategy behind it 👇 When I approach problems like this, I don’t jump straight into code. I break it into patterns: 🔹 Identify what the problem really wants → Not just “digit sum & product” — it’s about processing numbers efficiently digit by digit 🔹 Optimize early → Instead of storing digits, I compute sum & product in a single pass (O(n) time, O(1) space) 🔹 Keep it simple → Clean logic > overcomplicated tricks 🔹 Validate edge thinking → What happens with 0? Single digits? Large numbers? This mindset is what I’m focusing on as I grow in problem-solving — not just solving, but solving smartly. #LeetCode #ProblemSolving #Python #CodingJourney #DataStructures #Algorithms #TechGrowth #Consistency #LearningInPublic #FutureEngineer
To view or add a comment, sign in
-
-
🚀 Day 1 — Building Problem Solving Skills I’m continuing my journey to improve problem-solving skills by staying consistent, disciplined, and accountable — one problem at a time. 🧩 Problem: • Two Sum (LeetCode #1) 📚 Topic: Arrays (Pair Traversal) 💡 Key Insight: Checking all possible pairs works, but it highlights the need for more efficient approaches as input size grows. ⚡ Approach: • Pick an element using index i • Traverse remaining elements using index j • Check if nums[i] + nums[j] == target • Return indices when condition is satisfied 🎯 Takeaway: Even simple problems help strengthen logic and introduce optimization thinking. ⏱ Complexity: Time → O(n²) Space → O(1) 💻 Sample Input: nums = [2, 7, 11, 15] target = 9 ✅ Output: [0, 1] Consistency > Perfection 💪 #DSA #LeetCode #ProblemSolving #Python #CodingJourney #LearningInPublic #Arrays #TechGrowth
To view or add a comment, sign in
-
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