Day 24/100 – #100DaysOfCode 🚀 | #Java #LeetCode #DSA #LinkedList ✅ Problem Solved: Linked List Cycle II 🔎 Task: Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. 💡 Approach Used: Used Floyd’s Tortoise and Hare Algorithm to detect the cycle. Once a meeting point is found, moved one pointer to head and kept the other at the meeting point — both move one step at a time until they meet again (start of cycle). 🧠 Key Concepts: Two Pointers, Linked List Traversal, Cycle Detection ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Today’s takeaway: Understanding the mathematical intuition behind pointer movement makes linked list cycle problems easy to visualize and solve 🔄 #Java #LeetCode #DSA #ProblemSolving #CodingChallenge #100DaysOfCode
Solved Linked List Cycle II with Floyd's Algorithm
More Relevant Posts
-
🗓 Day 6 / 100 – #100DaysOfLeetCode 📘 Problem: 3228. Maximum Number of Operations to Move Ones to the End Difficulty: Medium 💡 Problem Summary: Given a binary string s, you can repeatedly choose an index i where s[i] == '1' and s[i+1] == '0', and move that '1' to the right until it reaches the end of the string or hits another '1'. The goal is to find the maximum number of such operations possible. 🧠 My Approach: Instead of simulating the moves (which would be inefficient), I used a counting strategy: Keep a running count of the number of '1's seen so far (cnt). Whenever a '0' appears after one or more '1's, we can perform cnt operations involving those ones. Sum these up for the final result. 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
Day 43 of #100DaysOfLeetCode Today’s problem: Find Pivot Index Concepts practiced: Prefix Sum Technique Array Traversal Efficient Space Optimization Approach: The goal is to find an index such that the sum of all elements to its left equals the sum of all elements to its right. 1️⃣ First, calculate the total sum of the array. 2️⃣ Iterate through the array, and at each index: 🔹 Subtract the current element from the right sum. 🔹 Check if left sum equals right sum → if yes, that’s the pivot index! 3️⃣ Update the left sum and continue. #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #LearningInPublic #SoftwareEngineering #DSA
To view or add a comment, sign in
-
-
Day 6 of My #21DaysOfJavaWithDSA challenge Today’s topic: The If Statement Concept Recap: The if statement in Java is one of the most basic yet powerful control structures. It allows us to make decisions in code executing certain lines only if a given condition is true. Problem Practiced: Given a number, print “Big” if it’s greater than 100. Regardless of the condition, always print “Number”. Example Output: Input: 10 → Output: Number Input: 101 → Output: Big Number Key Takeaway: Small conditions can control big logic! Understanding if statements builds the foundation for more complex decision-making like if-else, nested if, and loops. #Java #DSA #CodingChallenge #Day6 #LearningInPublic #GeeksforGeeks #CodeNewbie #100DaysOfCode
To view or add a comment, sign in
-
-
Day 25/100 – #100DaysOfCode 🚀 | #Java #LeetCode #DSA #BinarySearch ✅ Problem Solved: Find Minimum in Rotated Sorted Array II 🔎 Task: Given a rotated sorted array (which may contain duplicates), find the minimum element. 💡 Approach Used: Used Modified Binary Search to handle duplicates. Carefully adjusted search boundaries when nums[mid] == nums[right] to avoid missing the minimum. Ensured O(log n) in most cases, degrading gracefully to O(n) for worst-case duplicates. 🧠 Key Concepts: Binary Search, Array Rotation, Edge Case Handling ⚙️ Time Complexity: O(log n) average 📦 Space Complexity: O(1) ✨ Today’s takeaway: Binary search isn’t just about finding — it’s about knowing when to shrink the search space smartly ⚔️ #Java #LeetCode #DSA #ProblemSolving #CodingChallenge #100DaysOfCode #BinarySearch
To view or add a comment, sign in
-
-
🚀 #PostLog37 The problem was about determining the minimum ship capacity required to deliver all packages within a given number of days — LeetCode #1011: Capacity To Ship Packages Within D Days. 🔍 Core Ideas Involved Binary Search on the answer range Greedy approach to simulate daily loading Time complexity optimized to O(n log sum(weights)) ✅ Result: Accepted with 98% faster runtime 📈 Memory usage also within an efficient range Key takeaway: Reducing the search space can be more powerful than iterating through it. #leetcode #dsa #binarysearch #java #problemsolving #DSA
To view or add a comment, sign in
-
-
Today’s problem: Merge Two Sorted Lists 🔗 Problem: Given two sorted linked lists, merge them into one sorted list and return it. Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Approach I used: ✅ Create a dummy node to simplify pointer operations. ✅ Use a pointer (tail) to build the merged list by comparing the heads of both lists. ✅ Append the smaller node each time and move forward. ✅ When one list ends, attach the remaining nodes of the other. A clean iterative solution that keeps the space usage minimal (O(1) extra space). ⚡
To view or add a comment, sign in
-
-
🚀Day 29/100 - Problem of the day :- Minimum Number of Increments on Subarrays to Form a Target Array. 🎯 Goal: Solve the “Minimum Number of Increments on Subarrays to Form a Target Array” problem efficiently on LeetCode. 💡 Core Idea: The key observation is that we only need to add operations when the current element is greater than the previous one. So, the total operations = target[0] + sum(max(target[i] - target[i-1], 0)). This approach ensures we only count necessary increments, avoiding redundant steps. 🎯 Key Takeaway: By focusing on the difference between consecutive elements, we transform a complex problem into a simple linear pass — achieving both clarity and top performance. ✅ Passed all 129 test cases 🚀 Runtime beats 100% of Java submissions 💾 Space Complexity: O(1) — constant extra space used. ⏱ Time Complexity: O(n) — single pass through the array. #Java #DSA #ProblemSolving #Day29 #Leetcode #CodingJourney #100DaysChallenge
To view or add a comment, sign in
-
-
✨ Day 61 of 100: Same Tree ✨ Today’s challenge was LeetCode 100 – Same Tree 🌳 The task: Given two binary trees, determine if they are the same — meaning both structure and node values are identical. 💡 Key Takeaways: 🔹 Strengthened understanding of recursive tree traversal (checking left and right subtrees). 🔹 Practiced comparing tree nodes carefully — both value and structure. 🔹 Reinforced concepts of DFS (Depth-First Search) and base case handling in recursion. 🧠 Approach: 1️⃣ If both nodes are null, return true. 2️⃣ If only one is null, return false. 3️⃣ Check if values are equal, and then recursively verify left and right subtrees. 🌱 This problem was a great refresher on recursion fundamentals and tree comparison logic! #LeetCode #100DaysOfCode #Day61 #Java #DSA #CodingChallenge #BinaryTree #Recursion #DepthFirstSearch
To view or add a comment, sign in
-
-
🚀 Day 30/100 - Problem of the day:- Delete Nodes From Linked List Present in Array. 🎯 Goal: To remove specific nodes from a singly linked list based on a given array of values efficiently. 💡 Core Idea: Used a HashSet to store deletion values for O(1) lookup and a dummy node to simplify edge-case handling (like deleting the head). Iterated through the linked list once, adjusting pointers to skip nodes that should be removed. 📘 Key Takeaway: Efficient pointer manipulation is crucial in linked list problems. Using a dummy node simplifies deletion logic and edge cases. HashSet greatly optimizes lookup for deletion values. 🧠 Space Complexity: O(n) — for storing values in the HashSet. ⚙️ Time Complexity: O(m + n) — m for inserting into HashSet, n for traversing the linked list. #100DaysChallenge #Java #DSA #Day30 #ProblemSolving #CodingJourney #LeetCode
To view or add a comment, sign in
-
-
✨ Day 46 of 100: Simplify Path ✨ Today’s challenge was LeetCode 71 – Simplify Path 🧭 🧩 Problem Summary: Given an absolute path in a Unix-style file system, simplify it so that it represents the canonical path. We need to correctly handle ".", "..", and multiple slashes "/" while maintaining the correct directory structure. 💡 Key Takeaways: 🔹 Strengthened understanding of stack-based path traversal. 🔹 Learned how ".." can be used to move up directories and "." can be ignored. 🔹 Practiced string manipulation using split() and String.join() in Java. 🔹 Reinforced handling of edge cases like multiple consecutive slashes. 🧠 Core Idea: Use a Stack to keep track of valid directory names and rebuild the simplified path at the end. 💻 Language: Java ☕ #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #DSA #SimplifyPath #WomenWhoCode #CodingChallenge
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