🚀 Day 7 / 180 – DSA with Java 🚀 📘 Topic Covered: Modified Binary Search 🧩 Problem Solved: Search in Rotated Sorted Array Problem: Given a sorted array that has been rotated at some pivot, find the index of a target element in O(log n) time. Approach: Used a modified Binary Search by identifying which half of the array is sorted at each step. Based on the sorted portion, narrowed the search space intelligently until the target was found. Key Learning: ✔️ Applying binary search beyond simple sorted arrays ✔️ Identifying sorted halves in rotated arrays ✔️ Maintaining O(log n) efficiency with smart conditions If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
Java Binary Search in Rotated Array
More Relevant Posts
-
🚀 Day 26 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search in Rotated Sorted Array 🧩 Problem Solved: Search in Rotated Sorted Array II Problem: Given a rotated sorted array that may contain duplicates, determine if a target element exists in the array. Approach: Applied a modified Binary Search. At each step, identified which half of the array was sorted and adjusted the search space accordingly. Special care was taken to handle duplicates, which can make determining the sorted half more challenging. Key Learning: ✔️ Handling duplicates in binary search problems ✔️ Identifying sorted portions in rotated arrays ✔️ Adapting classic algorithms to complex scenarios If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 25 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search (First & Last Occurrence) 🧩 Problem Solved: Find First and Last Position of Element in Sorted Array Problem: Given a sorted array and a target value, find the starting and ending position of the target in O(log n) time. If not found, return [-1, -1]. Approach: Used Binary Search twice — • First to find the leftmost (first) occurrence • Then to find the rightmost (last) occurrence By carefully adjusting the search boundaries, ensured both positions were located efficiently. Key Learning: ✔️ Extending binary search for range queries ✔️ Handling boundary conditions carefully ✔️ Maintaining O(log n) time complexity If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 24 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search & Lower Bound Concept 🧩 Problem Solved: Search Insert Position Problem: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it should be inserted to maintain sorted order. Approach: Applied Binary Search while maintaining a potential answer index. Whenever the middle element was greater than or equal to the target, updated the answer and moved left to find the smallest valid position. Key Learning: ✔️ Understanding lower bound logic ✔️ Using binary search beyond simple searching ✔️ Achieving O(log n) efficiency with precise conditions If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 14 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Sorted-Rotation Logic 🧩 Problem Solved: Check if Array is Sorted and Rotated Problem: Determine whether a given array is sorted in non-decreasing order and then possibly rotated. Approach: Traversed the array and counted how many times the order decreases (where the current element is smaller than the previous one). If the count of such “break points” is at most one (including the circular check between last and first elements), the array satisfies the condition. Key Learning: ✔️ Understanding sorted array properties ✔️ Handling circular array comparisons ✔️ Solving rotation-based problems efficiently in O(n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 31 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Substring Search 🧩 Problem Solved: Find the Index of the First Occurrence in a String Problem: Given two strings haystack and needle, return the index of the first occurrence of needle in haystack. If it is not present, return -1. Approach: Traversed the main string and checked potential starting positions where the first character matched. Then compared the substring of the same length as the target string to verify a complete match. Key Learning: ✔️ Understanding substring search logic ✔️ Optimizing comparisons by checking the first character first ✔️ Practicing careful boundary handling in string traversal If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 21 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Pattern Detection 🧩 Problem Solved: Largest 3-Digit Repeating Number in a String Problem: Given a numeric string, find the largest substring of length 3 where all three digits are the same. If no such substring exists, return an empty string. Approach: Traversed the string and checked every group of three consecutive characters. Whenever three identical digits were found, compared them lexicographically to track the largest valid substring. Key Learning: ✔️ Detecting fixed-length patterns in strings ✔️ Using lexicographical comparison effectively ✔️ Careful boundary handling during traversal If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Today I learned about Recursion in Java, a powerful concept that helps solve complex problems by breaking them into smaller ones. A recursive method calls itself until a base condition stops it. Understanding recursion improved my logical thinking and problem-solving skills, especially for DSA topics like trees, backtracking, and divide-and-conquer algorithms. Implementing examples like factorial and Fibonacci made the concept clear and practical. Recursion is a technique where a method calls itself to solve a problem. It helps in breaking complex problems into smaller, manageable subproblems. 📌 What is Recursion? A recursive method has: 1️⃣ Base Case – Condition to stop recursion 2️⃣ Recursive Case – Method calling itself Without a base case, it leads to infinite recursion and StackOverflowError. #Java #Recursion #DSA #CodingJourney #Learning #ComputerScience
To view or add a comment, sign in
-
🚀 DSA Learning Journey | Day 2 | Java Solved “Search in Rotated Sorted Array.” 💡 Key Idea: Applied Binary Search by determining which half of the array is sorted and narrowing the search space. ⚙ Implementation • Language: Java • Time Complexity: O(log n) • Space Complexity: O(1) 📚 Learning how binary search can be adapted to work with rotated sorted arrays. #Java #DSA #LeetCode #ProblemSolving #BinarySearch #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 30 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sorting Technique 🧩 Problem Solved: Longest Common Prefix Problem: Given an array of strings, find the longest common prefix shared among all the strings. Approach: Sorted the array of strings and compared only the first and last strings. Since sorting groups similar prefixes together, the common prefix between these two strings represents the common prefix for the entire array. Key Learning: ✔️ Using sorting to simplify string comparison problems ✔️ Observing patterns to reduce unnecessary checks ✔️ Efficient prefix detection in string arrays If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
One thing I’m realizing while learning Java + DSA: Most problems are not about coding they’re about recognizing patterns. Linear Search, Binary Search, Recursion, Trees… The logic changes slightly, but the thinking process repeats. Currently following @Kunal Kushwaha’s Java + DSA playlist step by step and focusing more on understanding than memorizing. Fundamentals first. Speed later. #Java #DSA #ProblemSolving #LearningJourney
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