📅 Day 24 of #100DaysOfCode 🔥 Problem: Split Linked List in Parts (LeetCode 725) Approach: ->First, count the total length of the linked list. ->Determine partSize = n / k (minimum size of each part). ->Distribute the remainder nodes (n % k) among the first few parts. ->Cut and store each part by adjusting the next pointer. #100DaysOfCode #LeetCode #DSA #LinkedList #ProblemSolving #CodingChallenge #Cplusplus #DataStructures #CodeWithClarity #Algorithms #ProgrammingJourney #CodingCommunity #DailyDSA #SoftwareEngineer #DeveloperLife #TechCommunity #GrowthMindset #ContinuousLearning #Discipline #Consistency
Splitting a Linked List into Parts with LeetCode 725
More Relevant Posts
-
🚀 Day 63 of #100DaysOfCode Today I solved a C++ problem: 👉 Find K Pairs with Smallest Sums 🧩 Problem Summary: Given two sorted arrays arr1 and arr2, and an integer k, the task is to find k pairs (a, b) where a belongs to arr1 and b belongs to arr2, such that their sum is among the smallest possible. 🧠 Approach: I used a min-heap (priority_queue with greater comparator) to always extract the smallest pair sum efficiently. Start by pushing the smallest possible pairs from arr1 and the first element of arr2. Each time we pop the smallest pair, we add the next possible pair from the same row. Continue until we find k pairs. ⚙️ Key Concepts: Priority Queue (Min-Heap) Pair Sum Optimization Efficient use of STL 💡 Complexity: Time: O(k log k) Space: O(k) 👨💻 Language: C++ (STL-based) #100DaysOfCode #Day63 #CPlusPlus #STL #CodingChallenge #DSA #ProblemSolving #LeetCode #CodeNewbie #Programmer #LearnCoding #CompetitiveProgramming #cpp #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 46 of 150 Days LeetCode Challenge #150DaysOfCode #LeetCode #CodingChallenge #DSA #HashMap #CPlusPlus #Programming #SoftwareEngineering #TechLearning #ProblemSolving #CodeDaily #LeetCode150DaysChallenge #Algorithm #DataStructures 🔹 Problem Statement:Contains Duplicate II Given an integer array nums and an integer k, check if there exist two distinct indices i and j in the array such that: nums[i] == nums[j] |i - j| <= k In simple words: “Does the array contain a duplicate within a distance of k?” 🔹 Example: Input: nums = [1,2,3,1], k = 3 Output: true Explanation: nums[0] and nums[3] are both 1, and the distance between them is 3 ≤ k. 🔹 Approach: Use a hash map to store each number with its most recent index. Iterate through the array: If the number already exists in the map, calculate the distance between the current index and the previous index. If this distance ≤ k, return true. Update the map with the current index. Return false if no such pair is found. Time Complexity: O(n) | Space Complexity: O(n) 🔹 Key Insights: ✅ Hash maps allow O(1) lookups for duplicates. ✅ Always update the index to track the most recent occurrence. ✅ Brute-force approaches take O(n²), but hash maps reduce it to O(n).
To view or add a comment, sign in
-
-
📅 Day 40 of #100DaysOfCode 💻 Problem: 1002. Find Common Characters Approach: 1️⃣ Start by counting the frequency of each character from the first word using a HashMap. 2️⃣ Then, for each next word, update that HashMap to store the minimum frequency of each character (since we only care about characters that appear in all words). 3️⃣ Finally, collect all characters that have a frequency greater than 0 — those are the common ones across every word. This works like a "character intersection" — reducing counts each time until only the common ones remain. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #DeveloperLife #CodingJourney #KeepLearning #TechCommunity #SoftwareEngineering #Motivation
To view or add a comment, sign in
-
-
🟩 Day 56 of Leetcode 150 days challenge – Add Two Numbers (LeetCode #2) #LeetCode150 #Day56 #AddTwoNumbers #LinkedList #DataStructures #Algorithms #ProblemSolving #LeetCode #CodingChallenge #CPP #Programming #150DaysOfCode #LearnDSA #SDEPrep #CodingJourney 🔹 Problem: Given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each node contains a single digit. Add the two numbers and return the sum as a linked list. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807 🧠 Approach: We perform the addition just like we do on paper: Initialize a carry as 0. Traverse both lists simultaneously. Add the digits from both lists + carry. Store the last digit in a new node. Update carry = sum / 10. Continue until both lists are done and carry is 0. 🕒 Time Complexity: O(max(M, N)) 💾 Space Complexity: O(max(M, N)) 🏁 Key Takeaway: Linked list addition is a classic problem that strengthens your understanding of pointer manipulation, carry handling, and edge cases like unequal list lengths. 💡
To view or add a comment, sign in
-
-
🚀 Solved LeetCode Problem: Single Number (C++) 🔢 Every element appears twice except one This problem is a great reminder that bit manipulation can often beat complex data structures with pure logic and simplicity. 💡 Approach: Used the XOR operator (^) — since x ^ x = 0 and x ^ 0 = x, all duplicate numbers cancel out, leaving the single unique number. 🧠 Key Takeaways: Time Complexity: O(n) Space Complexity: O(1) Concept: Bit Manipulation + XOR Property 💬 Elegant, fast, and minimal — that’s the beauty of C++. 🔖 #LeetCode #Cplusplus #DSA #Coding #ProblemSolving #BitManipulation #CodingInterview #SoftwareEngineering #CodeNewbie #TechLearning #C++Developer #Algorithm #DataStructures #CodingChallenge #XOR #CodeDaily #LearnToCode
To view or add a comment, sign in
-
-
Day 6 – LeetCode Challenge Today, I solved Problem #128: “Longest Consecutive Sequence” using C++. 🔍 Problem Overview: The task is to find the length of the longest consecutive elements sequence in an unsorted integer array. The key challenge is to ensure the solution works in O(n) time complexity. 💡 Approach: To achieve linear time, I used an unordered_set to quickly check if a number exists. For each number, I only begin counting a sequence when it is the start of a new streak (i.e., (num - 1) does not exist in the set). This ensures each number is processed only once. 🧠 Algorithm Design: Insert all elements into an unordered_set for O(1) average lookups. For every number, check if it's the start of a sequence. If yes, count forward (num + 1, num + 2, ... ) while elements exist in the set. Track and update the maximum streak length. ⏱ Time Complexity: O(n) 📌 Space Complexity: O(n) #LeetCode #CPlusPlus #DSA #100DaysOfCode #ProblemSolving #Algorithms #CodingChallenge #TechCommunity #GeetaUniversity
To view or add a comment, sign in
-
-
🚀 Day 66 of #100DaysOfCode Today’s problem was LeetCode 155 — Min Stack 🧠💪 📌 Problem Summary: We need to design a stack that supports: push() pop() top() getMin() (returns minimum element in O(1) time) All operations must be O(1) — that’s the tricky part. ⚡ 📌 Approach: 👉 Use a single stack to store modified values 👉 Track the minimum separately using a variable 👉 When pushing a smaller value, encode it cleverly so you can retrieve the previous min during pop() 💡 Key Insight: When inserting a value smaller than the current minimum: st.push(2*x - min) min = x This way, the stack encodes both data and min info efficiently. 📌 Complexity: ⏱ Time: O(1) for all operations 💾 Space: O(n) ✨ Learning: This is a great example of space optimization and bit manipulation logic — classic low-level trick that feels like magic the first time you see it! ⚙️ Raj Vikramaditya Raghav Garg Nancy Solanki Shweta Arora Harsh Raj Harshita Verma Love Babbar Prince Singh Shivam Mahajan Rohit Negi Neeraj Walia Nishant Chahar Kushal Vijay #LeetCode #100DaysOfCode #CodingChallenge #Cplusplus #DataStructures #LinkedList #ProblemSolving #SoftwareEngineering #Developers #Programming #TechJourney #KeepLearning #DailyCoding #CodeNewbie#LeetCode #100DaysOfCode #Programming #Cplusplus #LinkedList #ProblemSolving #SoftwareEngineering #TechJourney #CodeNewbie #DSA
To view or add a comment, sign in
-
-
🧠 LeetCode #1526 — Minimum Number of Increments on Subarrays to Form a Target Array Difficulty: Hard 🔴 Language: C++ 💻 💡 Approach: Instead of simulating subarray increments, observe that each time the array value surpasses the previous one, a corresponding operation is required. To calculate the total operations needed, sum all positive variances between adjacent elements along with the initial element. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) 📈 Result: Accepted (0 ms runtime) 💬 Simple logic, efficient solution! 🔥 Keep solving, keep growing 💪 #LeetCode #CPlusPlus #DSA #Coding #ProblemSolving #HardProblems #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 93 of #100DaysOfLeetCode — Minimum Operations to Convert All Elements to Zero (Leetcode 3542) Today’s problem was a fun one that really tests your understanding of array manipulation and pattern observation! 🧩 Problem: Given an array of non-negative integers, the goal is to find the minimum number of operations needed to make all elements 0. In each operation, you can select a subarray and set all occurrences of the minimum non-zero element in that subarray to 0. 💭 Example: nums = [3, 1, 2, 1] ✅ Output → 3 ⚙️ Brute Force Approach: Iterate through the array and repeatedly find the smallest non-zero number. Set all its occurrences to zero. Count operations until all elements become zero. 🔹 Time Complexity: O(n²) 🔹 Space Complexity: O(1) ⚡ Optimal Approach (Used in my Solution): Use a stack-like logic or greedy approach to count how many unique increasing non-zero elements exist in the array. Each unique segment of increasing non-zero values corresponds to one operation. 🧠 Key Idea: If the next element is larger than the previous one, it represents a new operation zone. 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(n) 🔍 Dry Run Example: Input: [0, 2] Skip zeros. 2 is non-zero → stack is empty → push it and increment operation count. ✅ Result = 1 💡 Key Learnings: Observing array patterns helps to reduce redundant operations. Always analyze monotonic properties for greedy optimization. Stack logic can simplify subarray-based operation problems. 🔥 Tech Used: C++ | Arrays | Stack | Greedy 🧠 Concepts: Array traversal, Greedy Reduction, Monotonic Stack #LeetCode #Day93 #100DaysOfCode #DSA #CodingChallenge #CPlusPlus #Algorithms #ProblemSolving #GreedyAlgorithm #LearningEveryday #TechWithAnurag #CodeNewbie #SoftwareEngineering #FAANGPrep
To view or add a comment, sign in
-
Explore related topics
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
Consistency in Diwali 🎓