💡 Day 63 of LeetCode Problem Solved! 🔧 🌟 796. Rotate String 🌟 🔗 Solution Code: https://lnkd.in/dbS6k9gb 🧠 Approach: • Checked if both strings have equal length — if not, instantly return false. • Concatenated s with itself → all possible rotations of s are embedded inside s + s. • Used Java's built-in contains() to check if goal is a substring of the doubled string. ⚡ Key Learning: • A clever observation can replace brute-force rotation simulation entirely. Doubling the string is a go-to trick for rotation problems — simple, elegant, and highly effective. ⏱️ Complexity: • Time: O(N) • Space: O(N) #LeetCode #Java #DSA #ProblemSolving #Consistency #CodingJourney #Algorithms #Strings
Rotate String Solution in Java with LeetCode Explanation
More Relevant Posts
-
💡 Day 61 of LeetCode Problem Solved! 🔧 🌟 482. Find Maximum Consecutive Ones 🌟 🔗 Solution Code: https://lnkd.in/gf5DPq4E 🧠 Approach: • Traverse the binary array once using one pointer. • Keep counting consecutive 1s and update the maximum value at each step. • When a 0 appears, reset the count to 0. ⚡ Key Learning: • This is a simple sliding window idea. No need for nested loops or extra memory. Tracking current count and maximum value is a useful pattern for many array problems. ⏱️ Complexity: • Time: O(N) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #CodingJourney #Algorithms #Arrays
To view or add a comment, sign in
-
-
#Day79 of second #100DaysOfCode Binary search on answers is starting to click more now. DSA • Solved Minimum Number of Days to Make m Bouquets (LeetCode 1482) • Given bloom days, find the minimum day to make required bouquets – Brute: check each possible day and count valid bouquets → O(n × max(days)) – Optimal: binary search on days → O(n log max(days)) • Key idea: days form a monotonic search space — if a day works, all later days will also work • Focused on counting consecutive flowers correctly while checking feasibility These problems are really helping me understand how to model conditions for binary search. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Day 92 of #100DaysOfLeetCode 💻✅ Solved #739. Daily Temperatures problem in Java. Approach: • Used Monotonic Stack to track indices • Compared current temperature with stack top • Updated result when a warmer day was found • Stored indices for future comparisons Performance: ✓ Runtime: 60 ms (Beats 79.01% submissions) 🚀 ✓ Memory: 107.89 MB (Beats 17.53% submissions) Key Learning: ✓ Learned Monotonic Stack technique ✓ Improved handling of next greater element problems ✓ Strengthened stack-based problem solving Learning one problem every single day 🚀 #Java #LeetCode #DSA #Stack #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 41/100 – LeetCode DSA Practice 📌 Problem: 561. Array Partition Today’s challenge was about grouping elements into pairs such that the sum of the minimum values of each pair is maximized. 💡 My Approach: Initially thought about checking all possible pair combinations ❌ (too complex) Then realized this is a problem Sorted the array in ascending order Paired adjacent elements Added elements at even indices (0, 2, 4...) to get the maximum sum 🧠 Key Insight: After sorting, pairing neighbors ensures that the minimum in each pair is as large as possible, which maximizes the total sum. 💻 Code (Java): import java.util.Arrays; class Solution { public int arrayPairSum(int[] nums) { Arrays.sort(nums); int sum = 0; for(int i = 0; i < nums.length; i += 2) { sum += nums[i]; } return sum; } } 📚 What I Learned Today: Importance of recognizing patterns Sorting can simplify complex pairing problems Always look for pattern instead of brute force 🔥 Small insight, big impact! #Day41 #100DaysOfCode #LeetCode #DSA #GreedyAlgorithm #CodingJourney
To view or add a comment, sign in
-
-
Day 74 of #100DaysOfLeetCode 💻✅ Solved #162. Find Peak Element problem in Java. Approach: • Used Binary Search technique to efficiently find the peak element • Set two pointers, left at start and right at end of the array • Calculated mid index using safe mid formula • Compared nums[mid] with nums[mid + 1] to determine direction • If mid element is smaller, moved search space to right half • Otherwise, moved search space to left half including mid • Continued until left and right pointers converged • Final position (left == right) represents the peak index Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) 🚀 ✓ Memory: 44.32 MB (Beats 25.49% submissions) Key Learning: ✓ Strengthened understanding of Binary Search on unsorted arrays ✓ Learned how to apply divide-and-conquer beyond traditional searching ✓ Improved intuition for peak finding using neighbor comparison ✓ Practiced optimizing search space instead of linear scanning Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 33 Today’s focus: Binary Search for next greater element. Problem solved: • Find Smallest Letter Greater Than Target (LeetCode 744) Concepts used: • Binary Search • Upper bound concept • Circular handling Key takeaway: The goal is to find the smallest character strictly greater than a given target in a sorted array. This is a classic upper bound problem: We use binary search to find the first element greater than the target. During search: • If letters[mid] > target, store it as a possible answer and move left • Else move right An important edge case: If no character is greater than the target, we return the first element (circular behavior). Continuing to strengthen binary search patterns and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🔥 𝗗𝗮𝘆 𝟵𝟰/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟭𝟱𝟯𝟵. 𝗞𝘁𝗵 𝗠𝗶𝘀𝘀𝗶𝗻𝗴 𝗣𝗼𝘀𝗶𝘁𝗶𝘃𝗲 𝗡𝘂𝗺𝗯𝗲𝗿 | 🟢 Easy | Java Marked as Easy — but the optimal solution is pure binary search brilliance. 🎯 🔍 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 Given a sorted array, find the kth missing positive integer. Linear scan works — but can we do O(log n)? 💡 𝗧𝗵𝗲 𝗞𝗲𝘆 𝗜𝗻𝘀𝗶𝗴𝗵𝘁 At index i, the value arr[i] should be i+1 in a complete sequence. So missing numbers before arr[i] = arr[i] - 1 - i This lets us binary search on the count of missing numbers! ⚡ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — 𝗕𝗶𝗻𝗮𝗿𝘆 𝗦𝗲𝗮𝗿𝗰𝗵 ✅ If arr[mid] - 1 - mid < k → not enough missing numbers yet, go right ✅ Else → too many missing, go left ✅ After the loop, left + k gives the exact answer 𝗪𝗵𝘆 𝗹𝗲𝗳𝘁 + 𝗸? After binary search, left is the index where the kth missing number falls beyond. left numbers exist in the array before that point, so the answer is left + k. No extra passes needed. ✨ 📊 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 ⏱ Time: O(log n) — vs O(n) linear scan 📦 Space: O(1) This is a perfect example of binary searching on a derived condition, not just a value. A real upgrade from the naive approach. 🧠 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gVYcjNS6 𝟲 𝗺𝗼𝗿𝗲 𝗱𝗮𝘆𝘀. 𝗧𝗵𝗲 𝗳𝗶𝗻𝗶𝘀𝗵 𝗹𝗶𝗻𝗲 𝗶𝘀 𝗿𝗶𝗴𝗵𝘁 𝘁𝗵𝗲𝗿𝗲! 🏁 #LeetCode #Day94of100 #100DaysOfCode #Java #DSA #BinarySearch #Arrays #CodingChallenge #Programming
To view or add a comment, sign in
-
🧠 Day 26/75: Logic over Luck When you see a problem that asks for $O(\log n)$ time, your mind should immediately jump to Binary Search. But what if the data isn't perfectly sorted? Today’s LeetCode problem—Search in Rotated Sorted Array—is all about conditions. My approach in Java: Calculate mid safely. Determine if the left half is sorted (nums[left] <= nums[mid]). If yes, check if the target is in that range; otherwise, search the right. If no, it means the right half must be sorted. Result? 0ms Runtime and another problem checked off the list. ✅ Day 26 complete. Every problem is a lesson in thinking more clearly. See you for Day 27! 💻🔥 #Consistency #CodingJourney #LeetCodeChallenge #JavaDeveloper #TechGrowth #100DaysOfCode
To view or add a comment, sign in
-
-
🔢 Day 47/75: Optimizing with Brian Kernighan’s Algorithm! Today’s challenge was counting the number of "1" bits in an integer. While the naive approach is to check all 32 bits one by one, I implemented a much more elegant solution known as Brian Kernighan’s Algorithm. The Logic: The expression n = n & (n - 1) has a fascinating property: it always flips the least significant set bit (the rightmost 1) to 0. By running this in a loop until $n$ becomes 0, the number of iterations equals exactly the number of set bits. If a number has only three "1" bits, the loop runs 3 times, not 32. The Result: ✅ Runtime: 0 ms (Beats 100.00% of Java users) ✅ Efficiency: $O(k)$ time complexity, where $k$ is the number of set bits. Mastering these bitwise shortcuts is what separates a good solution from a great one! 🚀 #75DaysOfCode #LeetCode #Java #BitManipulation #Algorithms #ComputerScience #Optimization #SoftwareEngineering
To view or add a comment, sign in
-
-
✅ Solved LeetCode 217 — Contains Duplicate! Given an integer array nums, return true if any value appears at least twice. 🧠 My Approach: Sort + Linear Scan → Sort the array → adjacent duplicates are guaranteed to be neighbors → One pass to check if nums[i] == nums[i-1] → Time: O(n log n) | Space: O(1) 💡 Key Insight: Sorting brings duplicates side by side — no need for extra space like a HashSet. Trade time for space! ```java Arrays.sort(nums); for (int i = 1; i < nums.length; i++) { if (nums[i] == nums[i - 1]) return true; } return false; ``` 🔄 Alternative approaches: • HashSet → O(n) time, O(n) space • Brute force → O(n²) time (avoid!) Every problem teaches you a new trade-off. Keep grinding! 💪 #LeetCode #DSA #CodingInterview #Java #ProblemSolving #SoftwareEngineering #100DaysOfCode #Programming
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