Day 6 of Daily DSA 🚀 Solved LeetCode 977: Squares of a Sorted Array Approach: Used the two-pointer technique to compare squares from both ends of the array and build the result from back to front. This avoids extra sorting and keeps the solution optimal. Complexity: • Time: O(n) • Space: O(n) LeetCode Stats: • Runtime: 1 ms (Beats 99.80%) • Memory: 47.21 MB (Beats 74.22%) This problem reinforced how understanding data patterns can help eliminate unnecessary operations like sorting. #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #100DaysOfCode
Solving LeetCode 977: Squares of a Sorted Array with Two Pointers
More Relevant Posts
-
Day 19 of Daily DSA 🚀 Solved LeetCode 2089: Find Target Indices After Sorting Array ✅ Approach: Instead of actually sorting the array, I counted: elements less than the target elements equal to the target The starting index is determined by how many elements are smaller than the target, and then indices are built for all equal elements. Simple counting → no extra sorting needed 💡 ⏱ Complexity: • Time: O(n) — single pass • Space: O(1) — excluding output list 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.83 MB (Beats 83.41%) A neat example of how thinking beyond “just sort it” can lead to cleaner and faster solutions. #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency #Arrays
To view or add a comment, sign in
-
-
Day 25 of Practicing DSA on LeetCode Solved: • (540) Single Element in a Sorted Array – Medium Focused on: -Applying binary search on index patterns -Using even–odd index logic to narrow the search space -Achieving O(log n) time with O(1) extra space -Avoiding brute force by trusting array structure This problem showed how sorted data + index patterns = powerful optimizations. Think in patterns, not positions. Consistency over everything. #DSA #Java #LeetCode #BinarySearch #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 20 of Daily DSA 🚀 Solved LeetCode 179: Largest Number ✅ Approach: Converted all integers to strings and used a custom comparator while sorting. For two numbers a and b, we compare: a + b vs b + a This ensures the order that forms the largest possible number. Edge Case Handled 💡 If the highest element after sorting is "0", then the entire array contains zeros → return "0" instead of "000". ⏱ Complexity: • Time: O(n log n) — sorting with custom comparator • Space: O(n) — string array 📊 LeetCode Stats: • Runtime: 6 ms (Beats 96.21%) ⚡ • Memory: 44.96 MB (Beats 76.86%) Comparator-based problems really sharpen logical thinking 🔥 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Sorting #Consistency
To view or add a comment, sign in
-
-
Day 11 of Daily DSA 🚀 Solved LeetCode 1800: Maximum Ascending Subarray Sum ✅ 🔍 Approach: Iterated through the array while maintaining the sum of the current strictly increasing subarray. Whenever the sequence breaks, a new subarray sum is started and stored. Finally, the maximum subarray sum is obtained from the stored values. This method clearly separates each ascending subarray and helps in understanding the problem flow. ⏱ Complexity: • Time: O(n) — single traversal + max lookup • Space: O(n) — list used to store subarray sums 📊 LeetCode Stats: • Runtime: 1 ms ⚡ • Memory: 43.30 MB A good learning step before optimizing further to constant space. #DSA #LeetCode #Java #Arrays #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 71/100 – LeetCode Challenge ✅ Problem: #1356 Sort Integers by The Number of 1 Bits Difficulty: Easy Language: Java Approach: Custom Comparator with Bit Counting Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Sort integers based on number of set bits (1s in binary representation). If bit counts are equal, sort by natural integer order. Use Integer.bitCount() for efficient population count. Solution Brief: Converted primitive array to Integer[] for custom sorting. Applied Arrays.sort() with comparator: Compare bitCount(a) vs bitCount(b) If equal, compare integers directly using a.compareTo(b) Converted back to primitive array. #LeetCode #Day71 #100DaysOfCode #Sorting #Java #Algorithm #CodingChallenge #ProblemSolving #SortByBits #EasyProblem #BitManipulation #Comparator #DSA
To view or add a comment, sign in
-
-
Day 14 of Daily DSA 🚀 Solved LeetCode 153: Find Minimum in Rotated Sorted Array ✅ Approach: Used Binary Search to locate the minimum element in a rotated sorted array. At each step, compared nums[mid] with nums[end] to determine which half is unsorted and contains the minimum. By shrinking the search space intelligently, the minimum element is found efficiently. A great example of how Binary Search adapts to rotated arrays. ⏱ Complexity: • Time: O(log n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.66 MB (Beats 87.66%) Binary Search mastery keeps leveling up 💪 #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 10 of Daily DSA 🚀 Solved LeetCode 190: Reverse Bits ✅ 🔍 Approach: Worked with the 32-bit representation of the given integer: • Converted the number into a fixed 32-bit binary string • Used a two-pointer technique to reverse the bits • Converted the reversed binary back to an unsigned integer This approach keeps the logic simple while ensuring correctness for signed integers. ⏱ Complexity: • Time: O(32) = O(1) (constant time) • Space: O(32) = O(1) 📊 LeetCode Stats: • Runtime: 9 ms • Memory: 43.46 MB A good reminder that clarity matters more than micro-optimizations when learning bit manipulation. #DSA #LeetCode #Java #BitManipulation #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 15 of Daily DSA 🚀 Solved LeetCode 540: Single Element in a Sorted Array ✅ Approach: Used Binary Search on indices instead of values. Since elements appear in pairs, the unique element breaks the pairing pattern. By forcing mid to be even and comparing nums[mid] with nums[mid + 1], we can safely discard half of the array each time. ⏱ Complexity: • Time: O(log n) — binary search • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 52.96 MB (Beats 57.60%) A neat example of how index properties make binary search even more powerful. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 20 of #100DaysOfCode 🌱 Topic: Binary Trees / Recursion ✅ Problem Solved: LeetCode 105 – Construct Binary Tree from Preorder and Inorder Traversal 🛠 Approach: Used preorder to identify the root node. Used inorder to split left and right subtrees. Stored inorder indices in HashMap for fast lookup. Recursively built left and right subtrees using calculated ranges. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) (HashMap) #100DaysOfCode #Day20 #DSA #BinaryTree #Recursion #Java #LeetCode #ProblemSolving #CodingJourney #Consistency #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 12 of Daily DSA 🚀 Solved LeetCode 704: Binary Search ✅ Approach: Used the classic binary search technique on a sorted array. Initialized start and end pointers and repeatedly narrowed the search space by comparing the target with the middle element. Calculated mid using start + (end - start) / 2 to avoid overflow and ensure correctness. This approach efficiently reduces the search range and guarantees optimal performance. ⏱ Complexity: • Time: O(log n) — search space halves every iteration • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 48.54 MB (Beats 29.13%) A solid example of how understanding fundamentals leads to maximum efficiency. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #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
I also did the same problem today 😁