🚀 Day 4 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Index Manipulation 🧩 Problem Solved: Rearrange Array Elements by Sign Problem: Rearrange the array so that positive and negative numbers appear alternately, while maintaining their original relative order. Approach: Used separate indices for positive and negative positions and placed elements at alternating indices in a new array to achieve the required arrangement efficiently. Key Learning: ✔️ Handling index-based placement in arrays ✔️ Maintaining order while rearranging elements ✔️ Breaking problems into position-mapping logic If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
Rearranging Array Elements by Sign in Java
More Relevant Posts
-
🚀 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 18 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Carry-Based Addition 🧩 Problem Solved: Add Binary Problem: Given two binary strings, return their sum as a binary string. Approach: Traversed both strings from right to left, added corresponding digits along with carry, and built the result step by step. Used a string builder and reversed the final result to get the correct order. Key Learning: ✔️ Handling carry logic in string-based arithmetic ✔️ Simulating manual binary addition programmatically ✔️ Managing different string lengths efficiently 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 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 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 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 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 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
-
-
🚀 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 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