Day 41 of #180DaysOfCode Today, I leveled up the 𝗿𝗼𝘁𝗮𝘁𝗲𝗱 𝘀𝗼𝗿𝘁𝗲𝗱 𝗮𝗿𝗿𝗮𝘆 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: 𝗦𝗲𝗮𝗿𝗰𝗵 𝘄𝗶𝘁𝗵 𝗗𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝘀! 🔍 When the array contains duplicates, the previous approach needed a tweak. If nums[low] == nums[mid] == nums[high], we can't decide which side is sorted. The solution? Trim duplicates by moving low and high inward, then proceed with the standard rotated search logic. This ensures we still achieve O(log n) performance in most cases, though it can degrade to O(n) with many duplicates. A subtle but important edge case that makes binary search even more interesting! #Python #Algorithms #BinarySearch #RotatedArray #Duplicates #Coding
Manjeet Kumar’s Post
More Relevant Posts
-
Day 49: Mastering State Control. This penultimate day of the 50-day campaign was focused on achieving technical mastery over mutable objects in Python, differentiating the operational impact of .pop() versus .remove(), and leveraging .append() versus .extend() for structured list growth. This deep command ensures predictable code flow, and having refined this essential toolkit, I am fully prepared to apply this precision to the final complexities of the challenge ahead. #NxtWave #Python #50DayChallenge #CodeControl #ProfessionalCoding
To view or add a comment, sign in
-
🚀Day 80 of #100DaysOfDSA 🚀 Solved LeetCode 451 — Sort Characters By Frequency 🔹 Problem: Sort a string based on the frequency of its characters in descending order. 🔹 Approach: Used Hash Map + Sorting 1️⃣ Count frequency of each character using a dictionary 2️⃣ Sort characters by their frequency (descending) 3️⃣ Rebuild the string by repeating characters based on count ✨ Key Insight: Hash maps are great for frequency counting, and sorting by values helps in many pattern-based problems. #LeetCode #DSA #Python #ProblemSolving #HashMap #Sorting #CodingJourney #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
💡 Check if a Number is an Armstrong Number 🐢 Optimal Approach 🔹 Count the number of digits in the given number 🔹 For each digit, raise it to the power of total digits and sum them 🔹 If the sum equals the original number → it’s an Armstrong number 🕒 Time Complexity: O(log10N + 1) — proportional to the number of digits in N 💾 Space Complexity: O(1) — uses only constant extra space #Python #CodingPractice #ProblemSolving #LearningEveryday #Algorithms #MathLogic #NeelsLearns
To view or add a comment, sign in
-
-
Day 9 of #30DaysOfCode | LeetCode Problem 3. Longest Substring Without Repeating Characters Implemented an optimized Sliding Window approach to find the length of the longest substring without repeating characters. By maintaining a dynamic window using two pointers and a hash set, the algorithm achieves O(n) time complexity while efficiently managing unique character sequences. #Python #LeetCode #CodingChallenge #ProblemSolving #DataStructures #Algorithms #DSA
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯𝟵 𝗼𝗳 #𝟭𝟴𝟬𝗗𝗮𝘆𝘀𝗢𝗳𝗖𝗼𝗱𝗲 Today, I built on the first/last occurrence solution to 𝗰𝗼𝘂𝗻𝘁 𝗼𝗰𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝗲𝘀 𝗼𝗳 𝗮 𝘁𝗮𝗿𝗴𝗲𝘁 𝗶𝗻 𝗮 𝘀𝗼𝗿𝘁𝗲𝗱 𝗮𝗿𝗿𝗮𝘆 𝘄𝗶𝘁𝗵 𝗱𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝘀. Using the same lower_bound and upper_bound helpers: Lower bound → first index where element ≥ target Upper bound → first index where element > target The count is simply: count = upper_bound - lower_bound This gives an O(log n) solution — much faster than scanning the entire array, especially with many duplicates. It’s a great example of how breaking a problem into reusable pieces leads to clean and efficient code. Perfect for analytics, frequency analysis, and search optimizations! 📊 #Python #Algorithms #BinarySearch #FrequencyCount #Coding #ProblemSolving
To view or add a comment, sign in
-
-
Day 12 of #100DaysOfLeetCode Problem: 26. Remove Duplicates from Sorted Array Category: Arrays / Two Pointers Today’s problem was about removing duplicates from a sorted array in-place, ensuring each element appears only once and returning the new length. This problem was a great way to strengthen my understanding of two-pointer traversal and array updates without extra space. 🧠 Key Learnings: Used one pointer to track the position of the last unique element while iterating through the array. When a new unique value was found, it was placed at the next available position. Improved confidence in working with in-place modification techniques. Learned to think efficiently — no need for extra arrays or memory allocation. 🎯 Takeaway: Understanding how to manipulate arrays in-place is key to writing space-optimized and interview-ready code. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Arrays #TwoPointers #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
Day 69: Scramble String (Memoization) 🧠 I'm tackling a challenging Hard DP problem on Day 69 of #100DaysOfCode: "Scramble String." The goal is to see if one string can be made from another by recursively splitting and swapping substrings. My solution uses Memoization (Top-Down DP) to avoid re-solving the same subproblems. The core logic recursively checks two possibilities for every split: Swap or No Swap. This optimization allows the complex search to complete efficiently. #Python #DSA #Algorithms #DynamicProgramming #Memoization #100DaysOfCode #HardChallenge
To view or add a comment, sign in
-
-
🚀 Problem: Given an unsorted array of integers, find the length of the longest consecutive sequence — and do it in O(n) time. 💡 Challenge: Most solutions use sorting (O(n log n)), but the goal is linear time complexity. 🧠 Solution: I optimized the approach using a HashSet (Set in Python) — which allows O(1) lookups — and only starts counting when a number is the beginning of a sequence. This ensures every number is visited once. ✅ Result: Efficient O(n) solution with 0ms runtime on LeetCode. #Python #LeetCode #ProblemSolving #CodingJourney #DSA #Algorithms #DeveloperMindset
To view or add a comment, sign in
-
-
Day 6 of #100DaysOfLeetCode Problem: 3. Longest Substring Without Repeating Characters Category: Strings / Sliding Window Today’s problem was about finding the length of the longest substring without any repeating characters — a classic question that tests understanding of window management and string traversal. 🧠 Key Learnings: Used a sliding window technique to dynamically adjust the current substring when a duplicate character was found. Tracked characters in the current substring and shifted the start position upon repetition. Focused on maintaining both time efficiency and substring accuracy by managing indices smartly. 🎯 Takeaway: Sliding window techniques are powerful for handling substring and subarray problems efficiently — balance between expanding and shrinking the window is the key. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Strings #SlidingWindow #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
🎯 Day 44 of 50 Days Code Challenge 📘 Topic: Is Subsequence A subsequence is derived from another sequence by removing or ignoring some elements without changing the order of the remaining elements. 💡 Example: For the string "abcde", "ace" is a subsequence — the order is maintained even though some characters are removed. 🧠 Key Concept: To check if one string is a subsequence of another, we can use two-pointer technique to traverse both strings efficiently. ✅ Learning: This problem enhances understanding of string traversal, pointer manipulation, and greedy algorithms — key foundations for solving sequence-based problems. #100DaysOfCode #50DaysCodeChallenge #Day44 #CodingChallenge #Python #ProblemSolving #DataStructures #NxtWave #LearnToCode
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