🚀 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
Java DSA: Checking Sorted and Rotated Arrays
More Relevant Posts
-
🚀 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 16 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Carry Handling 🧩 Problem Solved: Plus One Problem: Given a number represented as an array of digits, increment the number by one and return the updated array. Approach: Started from the last digit and handled the carry carefully. If the digit was less than 9, incremented it directly. If it was 9, set it to 0 and continued moving left to handle the carry. If all digits were 9, created a new array with an extra leading 1. Key Learning: ✔️ Handling carry propagation in arrays ✔️ Managing edge cases like all 9s ✔️ Thinking about number representation logically 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 34 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Basic Construction 🧩 Problem Solved: Concatenation of Array Problem: Given an integer array nums, create a new array that contains the elements of nums twice in sequence. Approach: Created a new array with double the size of the original array and filled the first half with the original elements, then copied the same elements again into the second half. Key Learning: ✔️ Practicing array construction and indexing ✔️ Understanding how to manipulate array sizes ✔️ Writing clean logic for simple transformation problems 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 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 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 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 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 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