🚀 #100DaysOfCode – Day 27 Update Today I solved two DSA problems and explored different approaches. 🔹 Problem 1: Find Majority Element (n/2) ✅ Solved using Moore’s Voting Algorithm — an optimal approach. ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 📌 Learned how voting/cancellation logic helps find the majority element efficiently without extra space. --- 🔹 Problem 2: Sort a Linked List ✅ Approach 1 — Brute Force - Traversed the linked list and stored all node data in a temporary ArrayList. - Sorted the ArrayList. - Traversed the linked list again and updated node values. ⏱ Time Complexity: O(n) + O(n log n) + O(n) ≈ O(n log n) 💾 Space Complexity: O(n) 📌 Understood how extra space can simplify logic but is not optimal. 🔥 Tomorrow I will explore the optimal approach for sorting a linked list. #Day27 #100DaysOfCode #DSA #LinkedList #Java #ProblemSolving #CodingJourney
100DaysOfCode Day 27: Majority Element & LinkedList Sorting
More Relevant Posts
-
🌱 Day 11 of my #100DaysOfCode Journey Today I solved LeetCode Problem – Contains Duplicate. The problem asks us to determine if an integer array contains any duplicate values. If any value appears more than once, we return true; otherwise, false. The approach I used today was to sort the array first and then check adjacent elements for equality. This helps detect duplicates efficiently in a single pass. 🔹 What I practiced today: ✅ Array manipulation and sorting ✅ Comparing adjacent elements to find duplicates ✅ Thinking about time vs. space trade-offs 📊 Complexity Analysis: • Time Complexity: O(n log n) — due to sorting • Space Complexity: O(1) — in-place array check A simple yet practical problem that strengthens array handling and logical thinking in algorithm problems. #LeetCode #Java #DSA #100DaysOfCode #CodingJourney #ContainsDuplicate
To view or add a comment, sign in
-
-
Merge Sorted Array (LeetCode : 88) 💻✨ In this problem, we are given two sorted arrays. The task is to create a final sorted array inside nums1 without using extra space. I used Two Pointer Technique here 👇 🔹 i → last valid index of nums1 🔹 j → last index of nums2 🔹 k → last index of nums1 (m + n - 1) We compare from the back because if we compare from the front, the data would be overwritten. 👉 If nums1[i] > nums2[j], then we put the larger value at the back. 👉 Otherwise, we put nums2[j]. 👉 Once any one of the arrays is finished, we copy the remaining elements. Time Complexity of this approach: O(m + n) Space Complexity: O(1) (In-place solution) 🚀 This problem reminded me again — If you think in the right direction, the solution becomes much easier. #LeetCode #androidDeveloper#problemslover#dsapattern#twopointer#dailyChallenge #DSA #Java #TwoPointerTechnique #ProblemSolving #CodingJourney #SoftwareDevelopment #InPlaceAlgorithm #DataStructures #AlgorithmThinking
To view or add a comment, sign in
-
-
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 60 of DSA consistency Today I practiced a Binary Search Tree (BST) problem: Search in a Binary Search Tree. In this problem, we need to find a node with a given value in a BST and return the subtree rooted at that node. 🔹 Key Idea: A BST has the property: Left subtree values < root Right subtree values > root Using this property, we can efficiently search by moving left or right instead of traversing the entire tree. 📊 Complexity Analysis Time Complexity: O(h) → where h is the height of the BST Space Complexity: O(h) due to recursion stack If the tree is balanced, the complexity becomes O(log n). #DSA #Java #BinarySearchTree #CodingJourney #Consistency #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Problem Statement: Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays after combining them. ⚙️ Approach: ✔️ Combine both arrays into a single array ✔️ Sort the merged array ✔️ If the length is odd → return the middle element ✔️ If the length is even → return the average of the two middle elements ⏱ Time Complexity: O((m+n) log(m+n)) 📦 Space Complexity: O(m+n) 📌 Learning: This problem helped me understand array merging and median calculation concepts. 🔥 Consistency in solving problems daily helps improve problem-solving skills and algorithmic thinking. #Day9 #DSA #LeetCode #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 29 of #75daysofLeetCode 2095 – Delete the Middle Node of a Linked List Just solved an interesting linked list problem that perfectly demonstrates the power of the two-pointer technique (slow & fast pointers). 🔍 Problem Insight: Given a linked list, delete its middle node where the middle is defined as ⌊n/2⌋ (0-based indexing). 💡 Key Idea: Instead of calculating the length, we can efficiently find the middle using: 🐢 Slow pointer (1 step) ⚡ Fast pointer (2 steps) When the fast pointer reaches the end, the slow pointer will be at the middle node! 🛠 Approach: ✔ Handle edge case (single node → return null) ✔ Traverse using slow & fast pointers ✔ Keep track of previous node ✔ Remove the middle node in one pass ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🔥 Why this matters? This pattern is widely used in: Finding middle of linked list Detecting cycles Splitting lists Mastering this unlocks many problems! #LeetCode #DSA #LinkedList #Java #CodingInterview #ProblemSolving #TechLearning
To view or add a comment, sign in
-
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 16/100 – LeetCode Challenge Problem: Merge Sorted Array Today’s problem involved merging two sorted arrays into one sorted array. Approach: Created a temporary array of size m + n Used two pointers to compare elements from both arrays Inserted the smaller element into the new array Copied remaining elements if any array still had values Finally copied the merged result back into nums1 Complexity: Time: O(m + n) Space: O(m + n) Concepts Practiced: Two-pointer technique Array traversal Merging sorted arrays #100DaysOfCode #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 41/100 🚀 | #100DaysOfDSA Solved Valid Perfect Square (LeetCode 367) today. The task was to determine whether a number is a perfect square without using built-in functions like sqrt(). Approach: Used Binary Search to efficiently find a number whose square equals the given number. Steps: • Initialize left = 1 and right = num • Calculate mid • If mid * mid == num, it's a perfect square • If mid * mid < num, move to the right half • Otherwise, search the left half Also used long to prevent overflow while calculating mid * mid. Time Complexity: O(log n) Space Complexity: O(1) Key takeaway: Binary Search isn’t just for arrays — it can also be applied to mathematical search spaces. #LeetCode #DSA #BinarySearch #Java #ProblemSolving #100DaysOfDSA
To view or add a comment, sign in
-
-
Day 91/100 – LeetCode Challenge ✅ Problem: #98 Validate Binary Search Tree Difficulty: Medium Language: Java Approach: Inorder Traversal with Stack Time Complexity: O(n) Space Complexity: O(h) where h = tree height Key Insight: Inorder traversal of BST produces sorted ascending sequence. Compare each visited node with previous node to detect violations. Solution Brief: Used stack for iterative inorder traversal. Maintained pre pointer to track previous visited node. While traversing: Push all left nodes to stack Pop node, check if root.val <= pre.val (violation) Update pre to current node Move to right subtree #LeetCode #Day91 #100DaysOfCode #Tree #BST #Java #Algorithm #CodingChallenge #ProblemSolving #ValidateBST #MediumProblem #InorderTraversal #Stack #DSA
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