📅 Day 30 of #100DaysOfLeetCode Problem: 1523. Count Odd Numbers in an Interval Range Difficulty: Easy 🔍 Concept: Given two integers low and high, count how many odd numbers exist in the inclusive range. The trick is to use math instead of looping through all values. ✨ Key Insight: If the range length is even → exactly half are odd. If the range length is odd → result depends on whether both ends are odd. 🧠 Time Complexity: O(1) ⚡ Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Counting Odd Numbers in a Range: LeetCode Challenge
More Relevant Posts
-
🚀 Day 13 of #100DaysOfCode – Binary Search in Action-Today I solved LeetCode 1283: Find the Smallest Divisor Given a Threshold and it was a great example of how Binary Search can be applied beyond sorted arrays. 👉 This monotonic behavior makes the problem perfect for Binary Search. ⏱️ Complexity Time: O(n log max(nums)) Space: O(1) 📌 Key Takeaway Binary Search isn’t just for sorted arrays — 👉 If the answer space is monotonic, Binary Search can optimize it efficiently. #100DaysOfCode #Day12 #BinarySearch #LeetCode #Java #DSA #ProblemSolving #CodingJourney 💻✨
To view or add a comment, sign in
-
-
Day 18 of my LeetCode Journey: Problem: Search in a 2D Matrix Approach: Started from the top-right corner of the matrix. At each step: If the value is greater than target → move left If smaller → move down If equal → found the target This works because rows and columns are both sorted, allowing us to eliminate one row or column at every step. Time Complexity: O(m + n) Space Complexity: O(1) Key insight: Using matrix properties smartly can avoid unnecessary binary searches. Using matrix properties smartly can avoid unnecessary binary searches. On to Day 19 💪 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #1001DaysOfCode
To view or add a comment, sign in
-
-
Day 45/100 – #100DaysOfCode 🚀 Solved Remove All Adjacent Duplicates in String (LeetCode) using a Stack. Approach : -> Traverse the string character by character. -> If the stack is not empty and the top character is the same as the current one → pop it (remove the duplicate). -> Otherwise, push the current character onto the stack. -> After processing the full string, the stack contains the final characters (in reverse order). -> Build the result by popping from the stack and reversing it. This approach works in O(n) time and avoids unnecessary comparisons. #DSA #Stacks #LeetCode #ProblemSolving #Java #LearningEveryday #100DaysOfCode
To view or add a comment, sign in
-
-
📅 Day 41 of #100DaysOfLeetCode 🧩 Problem: 300. Longest Increasing Subsequence Difficulty: Medium 🚀 What I learned today: Used the Patience Sorting technique to solve LIS in O(n log n) time Maintained an auxiliary array where each index represents the minimum possible tail of an increasing subsequence of that length Applied binary search (lower bound / ceil) to efficiently replace elements Important insight: Using >= ensures the subsequence remains strictly increasing 🧠 Key Takeaway: Even though the auxiliary array doesn’t store the actual subsequence, its length always equals the LIS length — a powerful optimization over the classic DP O(n²) approach. 💡 Complexity: Time: O(n log n) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
Day 42 — LeetCode 215 | Kth Largest Element in an Array (Java) Solved the problem using a Min Heap (PriorityQueue) instead of sorting. Why? Because sorting works, but it’s not optimal. 🔹 Took user input for array size, elements, and k 🔹 Maintained a heap of size k 🔹 Returned the kth largest element efficiently Complexity matters: • Time — O(n log k) • Space — O(k) This approach scales better and is closer to what interviewers expect when they say “optimize your solution.” Building problem-solving depth one question at a time. 🚀 #DSA #Java #LeetCode #PriorityQueue #Heap #DataStructureAndAlgorithm #ProblemSolving #CodingJourney #DailyPractice
To view or add a comment, sign in
-
-
Day 16 of my LeetCode Journey Problem: Group Anagrams Approach 1 (Primary): Used a HashMap where the key is the word’s sorted characters. All anagrams produce the same sorted string, so they naturally group together. Convert word → char array Sort lexicographically Use sorted string as key Store original words as values Why it works? Anagrams share identical sorted forms. Time Complexity: O(n * k log k) Alternative Optimization: Instead of sorting, use a character frequency array (26 letters) as the key. This avoids sorting and improves time complexity. Time Complexity: O(n * k) Key insight: Choosing the right hash key representation can significantly impact performance. On to Day 17 💪 #LeetCode #DSA #Java #ProblemSolving #Consistency #CodingJourney #1001DaysOfCode Space Complexity: O(n * k)
To view or add a comment, sign in
-
-
Day 32 of #100DaysOfCode 🚀 Combination Sum III (Leetcode) Approach (Backtracking): This problem is about choosing k numbers (1–9) that add up to a given sum n. -> used backtracking to explore combinations step-by-step: *Start from a number 1 to 9 *Pick a number if it doesn’t exceed the remaining target *Move to the next number (i+1) to maintain uniqueness *If we have picked k numbers and the target becomes 0, store the combination. *Backtrack and try other possibilities *It’s a clean recursive pattern: pick → explore → unpick → continue. #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #Backtracking #ProblemSolving #LearningEveryda
To view or add a comment, sign in
-
-
🚀 Day 91/100 - Problem of the day :- Four Divisors. 🎯 Goal Solve the problem efficiently by identifying numbers with exactly four divisors and calculating their sum. 💡 Core Idea Iterate through each number, find divisors up to √n, count them smartly, and stop early once divisors exceed four. 📌 Key Takeaway Optimizing divisor checks with early termination significantly improves performance. 🧠 Space Complexity: O(1) ⏱️ Time Complexity: O(n · √k), where k is the maximum value in the array. #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Algorithms #Efficiency #100DaysChallenge
To view or add a comment, sign in
-
-
📅 Day 46 of #100DaysOfLeetCode 🧩 Problem: 2054. Two Best Non-Overlapping Events ⚙️ Difficulty: Medium 🚀 What I learned today: How to maximize value by selecting at most two non-overlapping intervals Importance of sorting events by end time to enable efficient lookups Used prefix maximum array to store the best value so far Applied binary search to find the last event that ends before the current one starts Achieved an optimal O(n log n) solution for large constraints 🧠 Key Insight: Instead of checking all pairs, precompute the best past event and combine it smartly using binary search. 💡 Techniques Used: Sorting • Binary Search • Prefix Max • Greedy ⏱ Complexity: Time: O(n log n) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 LeetCode Day 58/100 ✅ Count Odd Numbers in an Interval Range (Java) Today’s problem focused on finding how many odd numbers exist within a given range [low, high]. Instead of iterating through every number, I optimized the solution using a mathematical approach with O(1) time complexity. ✨ Key Idea: Calculate the total length of the range Half of them are odds If the range length is odd and the start value is odd, add one more 💡 This approach avoids loops and runs in constant time — giving 100% runtime efficiency on LeetCode! 🧠 Skills Used: Optimization, Mathematical Logic, Edge Case Handling Looking forward to solving more interesting problems and strengthening problem-solving consistency! 🔥 #Day58 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #100DaysOfCode #Consistency
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