🚀 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
Java DSA Day 30: Longest Common Prefix with Sorting
More Relevant Posts
-
🚀 Day 37 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Squares of a Sorted Array Problem: Given a sorted array of integers (including negatives), return a new array of the squares of each number, also sorted in non-decreasing order. Approach: Used a two-pointer approach from both ends of the array. Compared squares of elements and filled the result array from the end to maintain sorted order efficiently. Key Learning: ✔️ Handling negative values in sorted arrays ✔️ Using two-pointer technique for optimal solutions ✔️ Avoiding extra sorting to achieve O(n) time complexity 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 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 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 36 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search (Peak Finding) 🧩 Problem Solved: Find Peak Element Problem: Given an array, find a peak element (an element greater than its neighbors) and return its index. Approach: Used Binary Search by comparing the middle element with its neighbors. Based on the increasing or decreasing slope, moved towards the side where a peak must exist, reducing the search space efficiently. Key Learning: ✔️ Applying binary search on unsorted arrays using patterns ✔️ Understanding how slope direction guides decisions ✔️ Solving peak problems in O(log n) time 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 32 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sliding Window Technique 🧩 Problem Solved: Longest Substring Without Repeating Characters Problem: Given a string, find the length of the longest substring without repeating characters. Approach: Used a sliding window technique with two pointers and a hash array to track the last occurrence of characters. Whenever a repeating character appeared within the current window, adjusted the left pointer to maintain a substring with unique characters. Key Learning: ✔️ Applying sliding window for substring problems ✔️ Using hashing for constant-time character tracking ✔️ Optimizing from brute-force to O(n) time complexity 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 44 of #100DaysOfLeetCode 💻✅ Solved Very Simple #169. Majority Element problem in Java. Approach: • Sorted the given array using Arrays.sort() • Observed that the majority element appears more than n/2 times • After sorting, the majority element will always be present at index n/2 • Returned the element at nums[n/2] Performance: ✓ Runtime: 7 ms (Beats 42.86% submissions) ✓ Memory: 55.96 MB (Beats 16.21% submissions) Key Learning: ✓ Understood how sorting can help identify the majority element ✓ Learned the property that the majority element always occupies the middle position after sorting ✓ Practiced array manipulation and problem solving in Java Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
✨ DSA in Java – Day 83 🚀 Today I solved an interesting problem on Binary Trees: 👉 Sum of Root to Leaf Binary Numbers 🌱 What I Learned: How to traverse a binary tree using DFS (Depth First Search) Building numbers along the path using: ➤ current = current * 2 + node.val Identifying leaf nodes and calculating final values Improving recursion understanding in tree problems 💡 Approach: Start from root with value 0 At each node, update the current number If it's a leaf node → add it to the final sum Traverse left and right recursively 📌 Key Insight: Binary tree problems become easier when you think of them as path-based problems rather than node-based problems. 💻 Consistency is the key! Day by day, step by step, getting stronger in DSA 💪 #DSA #Java #BinaryTree #CodingJourney #LeetCode #100DaysOfCode #WomenInTech #Consistency
To view or add a comment, sign in
-
-
🚀 Day 38 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Two-Pointer Technique 🧩 Problem Solved: Is Subsequence Problem: Given two strings s and t, check whether s is a subsequence of t. Approach: Used two pointers to traverse both strings. Moved the pointer in s only when characters matched, and always moved the pointer in t, ensuring order is maintained. Key Learning: ✔️ Applying two-pointer technique on strings ✔️ Understanding subsequence vs substring ✔️ Writing clean and efficient O(n) solutions 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
-
-
🔍 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
-
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