🚀 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
Java Binary Search & Lower Bound Concept
More Relevant Posts
-
🚀 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 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 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 33 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Index Manipulation 🧩 Problem Solved: Shuffle the Array Problem: Given an array in the form [x1, x2, ..., xn, y1, y2, ..., yn], rearrange it to [x1, y1, x2, y2, ..., xn, yn]. Approach: Used two pointers to track elements from the first and second halves of the array, then alternately placed them into a new array to achieve the required shuffle pattern. Key Learning: ✔️ Managing multiple pointers in array problems ✔️ Practicing index-based rearrangement ✔️ Maintaining correct ordering while constructing a new array 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 29 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Container With Most Water Problem: Given an array where each element represents the height of a vertical line, find two lines that together with the x-axis form a container that holds the maximum amount of water. Approach: Used a two-pointer strategy starting from both ends of the array. Calculated the water area using the shorter height and the distance between pointers, then moved the pointer with the smaller height to try finding a better container. Key Learning: ✔️ Efficient use of two-pointer technique ✔️ Understanding how pointer movement impacts optimization ✔️ Reducing brute-force O(n²) solutions to O(n) 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 21 of My DSA Journey Solved “Perfect Number” using Java. Problem Summary A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). Example: 28 → divisors are 1, 2, 4, 7, 14 → sum = 28 Approach Initially, I checked all divisors up to n/2. This works but is inefficient for larger numbers. Then I optimized the solution by iterating only up to √n. For every divisor i, there exists a corresponding pair (n / i). So instead of checking all numbers, we only check till √n and add both divisors. Important points: • Start sum = 1 (since 1 is always a divisor) • Avoid counting the square root twice when i == n / i • Exclude the number itself from the sum Optimization Insight Divisors always occur in pairs. Using this property significantly reduces the number of iterations. Complexity Time Complexity: O(√n) Space Complexity: O(1) Key Learning A brute-force solution may work, but understanding mathematical properties helps in optimizing it. Thinking in terms of patterns and divisor behavior leads to better solutions. #DSA #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🔍 Linear Search in Java | DSA Practice Implemented Linear Search algorithm in Java as part of my DSA learning journey. 📌 What it does: Searches for a target element in an array by checking each element one by one. Returns the index if found, otherwise prints “Element not found”. 🧠 Concepts used: ∙ Array traversal using for loop ∙ Index tracking with a flag variable (index = -1) ∙ Early exit using break for efficiency #java #dsa #problem #solution #datastructure #algorithm #linearsearch
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
-
-
DSA with Java.... Today I learnt about insertion sort algorithm. This algorithm starts at index 1, compares elements to the left and shifts elements to the right to insert a value. It has a complexity of 0(n^2) which is quite decent for small datasets but terrible for large datasets. It has less steps than bubble sort and it's best case scenario is 0(n) compared to selection sort, 0(n^2). I implemented insertion sort with Java to understand how the computer operates with such algorithm. Out of all these algorithms, which do you consider best to use in business applications? Cheers 🥂 #dsa #java #insertionsort #softwareengineering
To view or add a comment, sign in
-
-
🚀 Day 28 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sliding Window 🧩 Problem Solved: Divisor Substrings Problem: Given an integer num and an integer k, find the number of substrings of length k from the digits of num such that the substring value divides num. Approach: Converted the number to a string and used a sliding window of size k to extract substrings. Each substring was converted back to an integer and checked whether it divides the original number. Key Learning: ✔️ Applying sliding window technique on strings ✔️ Converting between numeric and string representations ✔️ Handling edge cases like division by zero 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
-
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