💻 Interesting Java problem: Find the closest target in a circular array Given a words[] array, a target, and a startIndex, the task is to find the shortest circular distance to the target. Leetcode Problem :https://lnkd.in/g3RbdChE Core idea: For every matching target: find direct distance → Math.abs(i - startIndex) find circular distance → n - dist take the minimum. This is a neat example of how circular arrays require us to think beyond normal linear traversal. Small twist, smart logic. 🚀 #Java #Algorithms #DSA #CodingInterview #ProblemSolving #LeetCode
Java Circular Array Target Distance
More Relevant Posts
-
Day 73 of #100DaysOfLeetCode 💻✅ Solved #389. Find the Difference problem in Java. Approach: • Initialized a variable to store the sum • Added ASCII values of all characters in string t • Subtracted ASCII values of all characters in string s • The remaining value represents the extra character • Converted the result back to character and returned it Performance: ✓ Runtime: 1 ms (Beats 99.89% submissions) 🚀 ✓ Memory: 42.77 MB (Beats 97.03% submissions) Key Learning: ✓ Practiced optimized string traversal using enhanced for-loop ✓ Reinforced understanding of ASCII-based solutions ✓ Learned how mathematical approaches can simplify problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Math #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 31 of #100DaysOfCode Solved Find Target Indices After Sorting Array 🔍 Today’s problem looked like a sorting question, but the real trick was avoiding sorting altogether 😏 💡 Key Insight: Count elements less than target → starting index Count elements equal to target → number of indices ⚡ No sorting needed → O(n) time, O(1) space 🔍 Learned: Optimize before you implement brute force Counting can replace sorting in many cases Cleaner logic = faster code 💻 Implemented in Java #DSAwithEdSlash #LeetCode #Java #ProblemSolving #100DaysOfCode @edslash
To view or add a comment, sign in
-
-
Day 4 of my DSA Journey 🚀 Today’s challenge: The classic Palindrome Number problem. For today's solution, I focused on an intuitive approach using String manipulation in Java. Sometimes the best way to solve a problem is to break it down into steps that make logical sense right out of the gate! 🧠 My Approach: Handle the edge case: Negative numbers can never be palindromes, so return false immediately. Convert the integer to a String. Use a for loop to iterate backwards through the string, building a new reversed string character by character. Compare the original string with the reversed string to determine if it's a palindrome. ⚡ Key Learnings & Java Gotchas: String Iteration: In Java, strings aren't exactly like arrays, so I had to use .charAt(i) instead of standard bracket notation [i] to grab individual characters. The Comparison Trap: I learned the crucial difference between == and .equals(). In Java, == compares memory locations, but .equals() checks if the actual text values are the same. A huge "aha!" moment for handling Strings! Edge Case Handling: Always check for negative numbers first to save processing time. 📌 Complexity: Time: O(n) — where n is the number of digits, since we loop through the string once. Space: O(n) — for storing the string representations of the number. Every bug is a lesson, and every solved problem is a step forward. On to the next one! 💪 #DSA #DataStructures #Algorithms #ProblemSolving #CodingJourney #Java #TechJourney#DSAJourney #LeetCode #Coding #LearnInPublic #GrowthMindset
To view or add a comment, sign in
-
-
🚀 Day 3/30 — LeetCode Challenge Solved Median of Two Sorted Arrays on using Java. This wasn’t about merging arrays — the real challenge was applying binary search on partitions to achieve optimal time complexity. ✅ Key takeaway: Efficiency comes from thinking differently, not doing more work. Using partition-based binary search reduces complexity to O(log(min(n, m))). This problem pushed me to understand the logic deeply rather than just implementing it. #LeetCode #Java #Algorithms #BinarySearch #ProblemSolving #Consistency Archana J E Divya Suresh Harini B harilakshmi s Bavani k Bhavya B Devipriya R
To view or add a comment, sign in
-
-
#Day76 of my second #100DaysOfCode Binary search continues to surprise me with how many variations it has. DSA • Solved Find Peak Element (LeetCode 162) – Brute: check every element → O(n) – Optimal: binary search based on slope comparison → O(log n) • Key idea: if the next element is greater, move right; else move left — a peak is guaranteed • Didn’t need to check all elements, just follow the increasing/decreasing trend Interesting how this doesn’t require a fully sorted array, yet binary search still works. #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 21 of #100DaysOfCode Today, I worked on the classic string problem: implementing the strStr() function in Java. The goal: Find the first occurrence of a substring (needle) inside another string (haystack). Approach I used: - Applied a sliding window technique - Compared substrings using "substring(i, j)" - Returned the starting index when a match is found Key learning: Understanding how index-based string operations work and how "substring()" helps in breaking down problems step-by-step. Also realized the importance of optimizing solutions to avoid unnecessary string creation. Consistency is slowly turning concepts into confidence! Looking forward to improving this further with more optimized approaches #Java #Coding #DSA #LeetCode #ProblemSolving #LearningJourney #Consistency
To view or add a comment, sign in
-
-
Day 76 of #100DaysOfLeetCode 💻✅ Solved #33. Search in Rotated Sorted Array problem in Java. Approach: • Applied Binary Search on rotated array • Checked which half is sorted at each step • Reduced search space based on target position Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) 🚀 ✓ Memory: 43.80 MB (Beats 70.96% submissions) Key Learning: ✓ Mastered searching in rotated sorted arrays ✓ Improved Binary Search decision-making ✓ Learned efficient handling of edge cases Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 82 of DSA Journey Solved Isomorphic Strings today! This problem looks simple, but it teaches an important concept — one-to-one mapping between characters. 🔍 What I learned: Each character in one string must map to exactly one character in the other No two characters should map to the same character Consistency across the entire string is key 💡 Approach: Used two HashMaps to track mappings in both directions: s → t t → s This avoids conflicts and ensures correctness. 🧠 Example: "paper" → "title" ✅ "foo" → "bar" ❌ ✨ Key takeaway: Always think about bidirectional mapping when dealing with transformation problems. Small problem, but powerful concept! #DSA #Java #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 15 of #DSAwithEdSlash Solved: Bulb Switcher 💡 Today’s problem looked simple at first but had a really interesting mathematical insight behind it. Instead of simulating all the toggles, the key realization is that only perfect squares remain ON after all rounds. 💡 Key Takeaways: Importance of pattern recognition 🔍 Optimization using mathematical logic instead of brute force Counting perfect squares ≤ n gives the answer 📊 Result: ⚡ Optimized Time Complexity: O(√n) 💻 Efficient Java implementation Consistency is building confidence day by day 💪 #Day15 #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency #PlacementPrep
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