🚀Day 5 of #120DaysOfCode 📌 Problem: Height Checker 📌 Language: Java 🔍Approach(Two Pointer Technique) 1. make a copy of heights 2. Sort the copy --> this becomes expected 3. Traverse both arrays 4. Count indices where values differ 🔥 Key Insight 1. Create the expected order by sorting a copy of heights 2. Compare both arrays index by index 3. Count mismatches ⏱️ Time and Space Complexity Time Complexity: O(n log n) Space complexity: O(n) 🔥One problem closer to mastery #120DaysOfCode #Day5 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
Java Height Checker Solution using Two Pointer Technique
More Relevant Posts
-
🚀Day 6 of #120DaysOfCode 📌 Problem: Third Maximum number(414) 📌 Language: Java 🔍Approach . Duplicates must be ignored . Sorting is easy but not optimal . We only need top 3 distinct values 🔥 Approaches Maintain three variable . max1 --> largest . max2 --> second largest . max3 --> third largest ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day6 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
🚀Day 14 of #120DaysOfCode 📌 Problem: Matrix Reshape(566) 📌 Language: Java 🔍Approach 1. Check if Reshape is possible 2. Traverse the original matrix in row order 3. Mapping logic ⏱️ Time and Space Complexity Time Complexity: O(m x n) Space complexity: O(r x c) 🔥One problem closer to mastery #120DaysOfCode #Day14 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
🚀Day 7 of #120DaysOfCode 📌 Problem: Find all numbers disappeared in an Array(448) 📌 Language: Java 🔍Approach: Using HashSet . Store all elements of nums in a set . Loop from 1 to n . If a number is not in the set --> it's missing ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(n) 🔥One problem closer to mastery #120DaysOfCode #Day6 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
DSA journey 🚀 📌 LeetCode #167 – Two Sum II (Input Array Is Sorted) 💻 Language: Java 🔹 Approach (Two Pointer Technique): Initialize two pointers at the start and end of the sorted array Calculate the sum of both pointers If the sum equals the target → return 1-based indices If the sum is smaller than the target → move the start pointer forward If the sum is greater than the target → move the end pointer backward Efficient use of the sorted property 💡 ⏱ Time Complexity: O(n) 🧩 Space Complexity: O(1) Step-by-step clarity before optimization ✨ Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
🚀Day 20 of #120DaysOfCode 📌 Problem: Reverse Integer(7) 📌 Language: Java Algorithm: 1. Initialize rev = 0 2. While x != 0 . Extract digit . Check overflow . Update rev 3. Return rev ⏱️ Time and Space Complexity Time Complexity: O(logn) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day20 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
DSA journey 🚀 📌 LeetCode #1 – Two Sum 💻 Language: Java 🔹 Approach: Use two nested loops to check all possible pairs Compare the sum of each pair with the target Return indices once the matching pair is found ⏱ Time Complexity: O(n²) 🧩 Space Complexity: O(1) Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic #DSAWithedSlash
To view or add a comment, sign in
-
-
🚀 Day 2 | Problem 1 of my 15-Day 50+ String DSA Challenge Problem: Find Length of a String (without using length()) Today I practised a basic but important string problem in Java and focused on understanding different looping approaches. Key learnings: • Calculated string length without using built-in methods • Understood the difference between `for` loop and `for-each` loop • Learned when index-based iteration is needed and when simple traversal is enough Strengthening fundamentals step by step 💪 #DSA #Java #StringProblems #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 9 of #120DaysOfCode 📌 Problem: Largest Number At Least Twice of Others(747) 📌 Language: Java 🔍Approach 1. Traverse the array once to find the largest (max1) and second largest (max2) elements. 2. While updating the largest element, also store it's index. 3. After traversal, check if max >= 2 * max2 4. If true, return the stored index; otherwise, return -1. ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day9 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
🚀Day 13 of #120DaysOfCode 📌 Problem: Reverse String(344) 📌 Language: Java 🔍Approach(Two Pointer Technique) 1. Use two pointer . left --> start of the array index . right --> end of the array 2. While left < right: . Swaps[left] and s[right] . Move left forward (left++) . Move right backward (right--) 3. Stop when pointers meet or cross ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day13 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #Akshay #DSA
To view or add a comment, sign in
-
-
🚀 Day 29 | #100Days100ProgrammingChallenge #Language: Java * Concept: Sorting Algorithm – Selection Sort #Today, I implemented Selection Sort using Java 🧑💻✨ #What the program does: * Takes number of elements from the user * Accepts array elements using Scanner * Sorts the array using Selection Sort algorithm * Displays the sorted array in ascending order #Key learnings today: * Better understanding of nested for loops * How Selection Sort works step-by-step * Swapping elements using a temporary variable * Improved logic-building skills #Sample Output: Input : 12 13 22 123 3 Output : 3 12 13 22 123 * Consistency is the key. Moving forward to Day 30 🚀 #Day29 #Java #SelectionSort #DSA #LearningJava #100DaysOfCode #ProgrammingChallenge
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