🚀 Day 6 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search 🧩 Problem Solved: Search in Sorted Array Problem: Given a sorted array and a target value, return its index if found. Otherwise, return -1. Approach: Applied the Binary Search technique by repeatedly dividing the search space in half, comparing the middle element with the target, and adjusting the search boundaries accordingly. Key Learning: ✔️ Understanding divide-and-conquer strategy ✔️ Reducing time complexity to O(log n) ✔️ Importance of sorted arrays in efficient searching If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
Java Binary Search in Sorted Array
More Relevant Posts
-
🚀 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 12 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Sorting 🧩 Problem Solved: Number Game Problem: Given an array, sort it and swap every pair of adjacent elements to form the required output pattern. Approach: First sorted the array to organize elements in ascending order. Then iterated in steps of two and swapped adjacent elements to achieve the desired arrangement. Key Learning: ✔️ Combining sorting with index-based manipulation ✔️ Understanding pattern formation in arrays ✔️ Importance of careful iteration while swapping elements 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 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 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 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
-
-
🚀 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
-
-
🚀 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 19 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Greedy Traversal 🧩 Problem Solved: Largest Odd Number in a String Problem: Given a numeric string, return the largest-valued odd-numbered substring. If no odd digit exists, return an empty string. Approach: Traversed the string from right to left to find the first odd digit. Once found, returned the substring from the start up to that index to ensure the largest possible odd number. Key Learning: ✔️ Observing patterns to reduce unnecessary computation ✔️ Efficient right-to-left traversal ✔️ Applying greedy thinking in string problems 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 17 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Reversal Algorithm 🧩 Problem Solved: Rotate Array Problem: Rotate an array to the right by k steps, modifying it in-place without using extra space. Approach: Used the reversal algorithm: 1️⃣ Reversed the entire array 2️⃣ Reversed the first k elements 3️⃣ Reversed the remaining elements This efficiently achieved rotation in O(n) time with O(1) extra space. Key Learning: ✔️ Using reversal technique for array manipulation ✔️ Breaking complex operations into smaller steps ✔️ Writing optimized in-place solutions 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 10 / 180 – DSA with Java 🚀 📘 Topic Covered: Loops & Conditional Logic 🧩 Problem Solved: Sum of Multiples Problem: Given an integer n, calculate the sum of all numbers from 1 to n that are divisible by 3, 5, or 7. Approach: Iterated from 1 to n and checked divisibility conditions. If a number was divisible by 3, 5, or 7, added it to the running sum. Key Learning: ✔️ Strengthening fundamentals with loops and conditions ✔️ Writing clean and readable logic ✔️ Importance of handling multiple conditions efficiently If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #ProblemSolving #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