DAY-1:CODING CHALLENGE 1.Longest common Prefix substring from given string as input 2.3SUM problem Started with BRUTE-FORCE → checked every triplet. 😀 Worked 😇 but SLOW for big arrays (O(n³)) → TIME LIMIT EXCEEDED. Faced errors along the way: 'int object not iterable' → I wrote sorted(a,b,c) instead of sorted([a,b,c]). 'unhashable type: list' → Tried adding list to set. Fixed by converting to tuple. LOGICAL BUG → Return inside the loop returned early. Fixed by moving return outside. Finally moved to OPTIMAL TWO-POINTER APPROACH: Sort array first. Use two pointers to find pairs for target -nums[i]. Skip duplicates carefully. Complexity reduced to O(n²). 💡 Lessons learned: small syntax mistakes can cause big errors, immutable types are key for sets, and proper pointer logic makes code efficient. #Python #Algorithms #LeetCode #ProblemSolving #CodingJourney
Solved 3SUM problem with Two-Pointer Approach in Python
More Relevant Posts
-
Day 16 of #100DaysOfLeetCode Today’s problem focused on substring counting within binary strings and required an efficient approach to handle potentially large input sizes without generating every substring explicitly. 1. Number of Substrings With Only 1s The task was to count the total number of substrings that consist entirely of the character '1', with the final result taken modulo (10^9 + 7). Instead of constructing the substrings, the key insight is that each continuous block of 1s contributes a predictable number of valid substrings. 🔹 My Approach: Iterated through the string while tracking the current streak length of consecutive 1s. Each time a block ended, computed the number of substrings from that block using the formula: k*(k+1)/2 where k is the length of the streak. Added the total from each block to the final answer, applying the modulo constraint throughout. Completed the process with a final update for any trailing block of 1s. What I Learned: This problem reinforces how recognizing mathematical patterns within sequences can transform a brute-force solution into a simple linear scan. Efficient substring counting often comes down to understanding structure rather than enumerating possibilities. 📊 Complexity Analysis: Time Complexity: O(n) — single pass over the string. Space Complexity: O(1) — constant space approach. #day16 #100daysofleetcode #leetcode #DSA #python #leetcodes #striver
To view or add a comment, sign in
-
-
🚀 Day 3 of #100DaysofDSA Today’s focus was on the “Set Matrix Zeroes” problem — a classic array-matrix question that tests both logic and optimization thinking It began with the brute-force idea: storing all zero positions and then marking corresponding rows and columns later. It works but takes O(m × n) time and O(m + n) extra space. Next, then explored a better approach using two auxiliary arrays to track which rows and columns should be zeroed. This improved the clarity but still consumed additional memory and space. Finally, then to reduce the complexity I tackled the optimal solution, which achieves O(1) extra space by using the first row and first column of the matrix itself as markers. A small Boolean flag handles the edge case when the first row contains a zero. This subtle observation transforms the logic completely — turning a memory-heavy method into a clean in-place algorithm. It was a good reminder that optimization isn’t just about speed — it’s about finding elegance in constraints. #100DaysOfDSA #MatrixProblems #Optimization #SpaceComplexity #Python #ProblemSolving
To view or add a comment, sign in
-
-
Day 31 / 100 – Add Strings (LeetCode #415) Today’s challenge was all about simulating manual addition without using any built-in integer conversions. Given two numbers as strings, the task was to return their sum — also as a string. This problem really emphasized the importance of breaking problems into small, logical steps rather than relying on shortcuts. 🔍 Key Learnings Recreated the digit-by-digit addition process using ASCII values. Practiced handling carry-over efficiently while iterating backward. Strengthened my understanding of string manipulation and arithmetic logic. 💭 Thought of the Day True problem-solving isn’t about using built-ins — it’s about understanding how things work underneath. Today reminded me that mastery grows when we rebuild the basics from scratch, not when we avoid them. 🔗 Problem Link: https://lnkd.in/gHMt9vj9 #100DaysOfCode #Day31 #LeetCode #Python #ProblemSolving #StringManipulation #Algorithms #DataStructures #CodingChallenge #CodeEveryday #TechGrowth #LearningJourney
To view or add a comment, sign in
-
-
Day 36 / 100 – Longest Palindromic Substring (LeetCode #5) Today’s challenge focused on String Manipulation — finding the longest palindromic substring within a given string. At first, it felt tricky to handle all the possible substrings, but then I learned to expand around the center, checking for symmetry on both sides. This approach makes the solution both logical and efficient. This problem reinforced how clarity in logic often comes from recognizing patterns, and that even complex problems can be broken into smaller, mirror-like checks. 🔍 Key Learnings Expanding around the center efficiently checks for palindromes in O(n²) time. Always consider both even and odd length palindromes. String problems often rely on clear thinking more than heavy algorithms. 💭 Thought of the Day Problem-solving isn’t about rushing for the answer — it’s about exploring the structure of the challenge. Palindromes taught me patience, symmetry, and the art of looking for balance in both logic and code. 🔗 Problem Link: https://lnkd.in/gSe-ygD8 #100DaysOfCode #Day36 #LeetCode #Python #StringManipulation #ProblemSolving #Algorithms #CodingChallenge #CleanCode #CodeEveryday #LearningJourney #DataStructures #Optimization
To view or add a comment, sign in
-
-
Problem: Given a string containing ()[]{}, determine if the parentheses are valid. A string is valid if brackets close in the correct order and type. ⬇️ ⬇️ ⬇️ My initial intuition: 😎 Thought of using a stack immediately — push openings, pop on closings. ☠️ But the first few implementations broke on tricky cases like ([)]. 🤡 I was popping and comparing in the wrong order and couldn’t figure out how to validate the pairings cleanly. ⬇️ ⬇️ ⬇️ After careful debugging: 😎 Discovered that flipping my mapping made the logic much simpler: { ')': '(', ']': '[', '}': '{' } 💡 This way, every closing bracket directly tells me which opening it expects. 😎 The stack now works perfectly — last in, first out — catching even the toughest edge cases. 🌟🌟🌟 learned about little micro optimizations: -> to create a local reference of the map helps with access times. -> not unravelling map with .values() calls, instead created a set of opening parenthesis. ✅ Intuition was right this time. 😅 Execution... not so much. #LeetCode #ProblemSolving #Python #LearningJourney #Coding
To view or add a comment, sign in
-
-
Day 72: Partition List 🔗 I'm back to linked lists on Day 72 of #100DaysOfCode by solving "Partition List." The challenge is to rearrange a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x, while preserving the original relative order within each partition. My solution uses a two-list approach with dummy nodes: Creation of Two Lists: I initialize two separate dummy nodes: less_dummy and greater_dummy. Partitioning: I iterate through the original list once. If a node's value is less than x, I append it to the less list; otherwise, I append it to the greater list. This inherently preserves the relative order within each group. Merging: After the single pass, I set the next pointer of the tail of the less list to the head of the greater list (less_tail.next = greater_dummy.next). Crucially, I set the tail of the greater list to None to prevent cycles (greater_tail.next = None). This single-pass method achieves an optimal O(n) time complexity and O(1) extra space complexity (excluding the new nodes being rearranged). My solution was accepted with 100% runtime efficiency! #Python #DSA #Algorithms #LinkedList #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Today I worked on a classic string problem: Finding the length of the longest substring that contains no repeated characters. 🧠 What the problem asks: Given a string, identify the longest continuous sequence where all characters are unique, and return its length. 📌 Key Observations: A substring must be continuous (not scattered like a subsequence) As soon as a character repeats, the current window becomes invalid The goal is to maintain a window of unique characters only 🔍 How I approached it: I used the Sliding Window technique with two pointers. This helped me: Expand the window when characters are unique Shrink it when duplicates appear Track the maximum length efficiently This approach avoids rechecking characters repeatedly and keeps the solution optimal. ✔ Example Insights: "abcabcbb" → longest substring: "abc" → length 3 "bbbbb" → "b" → length 1 "pwwkew" → "wke" → length 3 💡 Takeaway: This problem reinforces how powerful sliding window techniques are for real-world string and array challenges. Great practice for improving logic, efficiency, and pattern recognition. #LeetCode #CodingPractice #Python #Algorithms #100DaysOfCode #SlidingWindow #ProblemSolving #TechJourney
To view or add a comment, sign in
-
-
✅ Learned to solve “Remove Duplicates from Sorted Array” (in-place, O(n) time, O(1) space)! Sorted input means every duplicate sits next to its twin—perfect setup for the two-pointer pattern: scan once, write uniques forward, and return the count k while keeping the first k positions clean and ordered. What clicked: - Two pointers: one scans, one writes uniques forward - Skip repeats deterministically thanks to sorting - Edge cases covered: empty array, all duplicates, negatives, mixed ranges Level-ups next: “Remove Duplicates II” (allow at most twice) and “Remove Element” to deepen the pattern muscle. What’s your favorite twist on this technique? 🚀 #LeetCode #TwoPointers #Arrays #InPlace #DSA #Algorithms #InterviewPrep #ProblemSolving #TimeComplexity #CodingChallenge #Python #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 68: Search in 2D Sorted Matrix (Search Space Reduction) 🔎 I'm continuing the streak on Day 68 of #100DaysOfCode with a challenging matrix search problem! The task is to find a target value in an $m \times n$ matrix where both rows and columns are sorted in ascending order. The key to solving this efficiently is Search Space Reduction. Instead of performing a standard search, my solution uses a smart traversal technique: Starting Point: I begin the search at the top-right corner of the matrix. Decision Logic: If the current value equals the target, we stop. If the current value is greater than the target, the entire current column can be eliminated, so we move left. If the current value is less than the target, the entire current row can be eliminated, so we move down. This strategy eliminates one row or one column in every step, guaranteeing an optimal O(m + n) time complexity and O(1) extra space. #Python #DSA #Algorithms #Matrix #Search #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 5 of #100DaysOfLeetCode Problem: 54. Spiral Matrix Category: Arrays / Matrix Traversal Today’s challenge focused on traversing a 2D matrix in spiral order and returning all elements in that pattern. This problem was really fun to solve because it required handling multiple edge cases while maintaining clean traversal logic. 🧠 Key Learnings: Used the concept of repeatedly peeling off the outer layer of the matrix. Traversed top row → right column → bottom row → left column in sequence. Understood the importance of checking matrix boundaries after each step to avoid index errors. Improved logical thinking for problems involving nested data structures. 🎯 Takeaway: Matrix traversal problems are all about maintaining control over direction and boundaries — once that’s handled, the logic flows smoothly. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Matrix #Arrays #Python #AIEngineer #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