🚀 Day 572 of #750DaysOfCode 🚀 🔍 Problem Solved: Furthest Point From Origin Today’s problem was a great example of how a simple-looking question can be solved with the right observation 👀 💡 Key Insight: We don’t need to simulate every possible movement. Instead, we just count: 'L' → moves left 'R' → moves right '_' → flexible (can be either) 👉 To maximize distance from origin, use all '_' in the direction that increases the difference the most. 🧠 Approach: Count number of 'L', 'R', and '_' Net position = R - L Add all '_' to maximize distance 👉 Final Answer = |R - L| + '_' 📈 Complexity: Time: O(n) Space: O(1) ✨ Takeaway: Sometimes, instead of exploring all possibilities, you just need to convert the problem into counts and math. Simple logic → powerful result 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Algorithms #LearningEveryday
Furthest Point From Origin Problem Solved with Simple Logic
More Relevant Posts
-
💡 Day 59 of LeetCode Problem Solved! 🔧 🌟 674. Longest Continuous Increasing Subsequence 🌟 🔗 Solution Code: https://lnkd.in/gzDVyZwa 🧠 Approach: • Linear Scan: Implemented a single-pass strategy to traverse the array and track the length of the current increasing streak. • Streak Tracking: Checked if each element is strictly greater than its predecessor. If true, extended the streak; otherwise, reset it to 1. Continuously updated the maximum length found. ⚡ Key Learning: • Reinforced the importance of recognizing that not every problem needs nested loops — a single traversal with smart state management is often sufficient. Resetting to 1 (not 0) when the streak breaks is a subtle but crucial detail that reflects real-world subarray thinking. ⏱️ Complexity: • Time: O(N) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #CodingJourney #Algorithms #Arrays
To view or add a comment, sign in
-
-
🚀 Day 571 of #750DaysOfCode 🚀 🔍 Problem Solved: Sum of Distances Today’s problem looked like a classic brute-force trap 👀 At first glance, comparing every pair gives an O(n²) solution — but with constraints up to 10⁵, that’s not going to work. 💡 Key Insight: Instead of comparing all pairs, we can: 👉 Group indices of the same value 👉 Use prefix sums to efficiently calculate distances 🧠 Approach: Group indices by value (using HashMap) For each group: Build prefix sum of indices For each index: Left contribution → i * count - sum Right contribution → sum - i * count Combine both to get final result 📈 Complexity: Time: O(n) Space: O(n) ✨ Takeaway: When you see distance-based problems: 👉 Think in terms of contributions instead of pair comparisons 👉 Prefix sums can turn expensive computations into linear time Another strong pattern added to the toolkit 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #PrefixSum #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 20/100 — #100DaysOfLeetCode 20 days of consistency completed ✅ Small daily efforts are slowly building strong problem-solving intuition. ✅ Problem Solved: 🔹 LeetCode 1248 — Count Number of Nice Subarrays 💡 Concepts Used: Sliding Window Prefix Sum / At Most K Technique 🧠 Key Learning: A subarray is considered nice if it contains exactly k odd numbers. Instead of checking all subarrays, I learned an important trick: 👉 Count subarrays with at most k odds 👉 Subtract subarrays with at most (k-1) odds This transforms a complex counting problem into an efficient O(n) sliding window solution. ⚡ Takeaway: Many hard problems become easier once you convert “exactly k” → “at most k”. Consistency is paying off — patterns are becoming clearer every day 🚀 #100DaysOfLeetCode #LeetCode #DSA #SlidingWindow #Algorithms #Java #ProblemSolving #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 88 — LeetCode Practice 🚀 Today’s focus was on factorization and optimization techniques. ✅ Problem solved today: 🔹 Construct the Rectangle 💡 Key learnings from today: • Understood how to find factors of a number efficiently • Learned why starting from √area gives the closest dimensions • Strengthened concepts of minimizing difference between two values • Explored how mathematical logic can optimize brute-force solutions • Improved understanding of time complexity reduction 🧠 Approach used: Started checking from √area and moved downwards to find the first factor pair. This ensures length ≥ width and minimum difference. ⚡ Time Complexity: O(√n) 📦 Space Complexity: O(1) 📈 Progress: Getting better at optimizing solutions and thinking mathematically! #Day88 #LeetCode #DSA #Java #CodingPractice #ProblemSolving #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 10/50 🔍 Problem: Merge Sorted Array Today’s problem focused on efficiently merging two sorted arrays without using extra space. 💡 Approach: I used the Two Pointer technique (from the end): Started comparing elements from the back of both arrays Placed the larger element at the end of nums1 Continued this process until all elements were merged ⚡ This approach avoids unnecessary shifting and works in-place. 📊 Complexity Analysis: Time Complexity: O(m + n) Space Complexity: O(1) 📚 Key Learning: Thinking from the end can simplify problems and avoid extra operations. Two-pointer technique is extremely useful for array manipulation problems. Consistency is building confidence 💪 #LeetCode #Algorithms #DataStructures #ProblemSolving #CodingJourney #Java #100DaysOfCode #StudentDeveloper #Learning
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 7/50 🔍 Problem: Valid Anagram Today’s problem was about checking whether two strings are anagrams of each other efficiently. 💡 Approach: I used the Character Frequency Count method: First checked if both strings have equal length Used an array of size 26 to track character frequencies Incremented counts for one string and decremented for the other If all values are zero, both strings are anagrams ⚡ This approach avoids sorting and ensures optimal performance. 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) 📚 Key Learning: Using frequency arrays is a powerful technique for string problems. It helps achieve constant space complexity and improves efficiency compared to sorting-based approaches. Step by step, getting better at problem solving 💪 #LeetCode #Algorithms #DataStructures #ProblemSolving #CodingJourney #Java #100DaysOfCode #StudentDeveloper #Learning
To view or add a comment, sign in
-
-
🚀 Day 546 of #750DaysOfCode🚀 🔥 Solved: Check if Strings Can be Made Equal With Operations I (LeetCode Easy) 💡 Problem Insight We are allowed to swap characters at indices where: 👉 j - i = 2 This means: Index 0 ↔ 2 (even positions) Index 1 ↔ 3 (odd positions) 🚫 But we cannot mix even and odd indices 🧠 Key Observation The string is divided into 2 independent groups: Even indices → (0, 2) Odd indices → (1, 3) 👉 We can rearrange within each group freely 👉 So both groups must match between s1 and s2 ⚡ Approach Extract characters: Even indices from both strings Odd indices from both strings Sort both groups Compare: Even parts must match Odd parts must match 📈 Complexity Time: O(1) Space: O(1) 💬 Key Takeaway Sometimes problems look like string manipulation, but the real trick is: 👉 Understanding constraints → grouping → independent transformations 🔁 Consistency check ✔️ Another day, another step forward 🚀 #LeetCode #DataStructures #Algorithms #Java #CodingChallenge #ProblemSolving #100DaysOfCode #Consistency
To view or add a comment, sign in
-
-
🚀 Day 63 of #100DaysOfLeetCode ✅ Problem Solved: Unique Binary Search Trees (LeetCode 96) Today’s problem was a great example of how Dynamic Programming and mathematical patterns (Catalan Numbers) come together. 🔍 Key Insight: For every node chosen as root, the number of unique BSTs is: 👉 Left Subtrees × Right Subtrees This leads to the recurrence: dp[n] = Σ (dp[left] × dp[right]) 💡 What I learned: Breaking problems into smaller subproblems makes complex structures easier Recognizing patterns like Catalan Numbers is a game changer DP is not just about arrays, it's about thinking smart ⚡ Result: ✔️ Runtime: 0 ms (Beats 100%) ✔️ Clean and optimized solution Consistency is slowly turning into confidence 💪 #LeetCode #DataStructures #DynamicProgramming #CodingJourney #ProblemSolving #Java #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 87 — LeetCode Practice 🚀 Today’s focus was on ranking logic and nested iteration concepts. ✅ Problem solved today: 🔹 Relative Ranks 💡 Key learnings from today: • Understood how to determine ranks by comparing each element with others • Learned how counting higher scores helps assign positions • Strengthened concepts of nested loops and conditional logic • Explored how to map rankings into strings like Gold Medal, Silver Medal, Bronze Medal • Improved thinking on converting numeric logic into meaningful output 🧠 Approach used: Used a brute-force method where for each score, I counted how many scores are greater than it to determine its rank. ⚡ Time Complexity: O(n²) 📦 Space Complexity: O(n) 📈 Progress: Staying consistent and improving problem-solving step by step! #Day87 #LeetCode #DSA #Java #CodingJourney #Consistency #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 70 — LeetCode Practice ✅ Problem Solved: Minimum Operations to Make Array Sum Divisible by K 💡 What I learned today: • Understood how modulus (%) helps in solving optimization problems • Learned that instead of performing operations repeatedly, we can directly use math logic • Realized that the answer depends on sum % k • Improved thinking towards efficient (O(n)) solutions 📊 Approach: • Calculated total sum of the array • Found remainder using sum % k • That remainder itself gives the minimum operations required 🎯 Key Insight: Sometimes, problems look complex but can be solved using simple mathematical observations instead of brute force 🔥 Consistency is the key — showing up every day! #Day70 #LeetCode #DSA #CodingJourney #ProblemSolving #Consistency #Java
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