#100DaysOfCode – Day 77 Delete in a Doubly Linked List Problem: Given a doubly linked list and an integer x, remove the node at position x (1-indexed) and return the head of the updated list. Example: Input: 1 <-> 2 <-> 3 <-> 4, x = 3 Output: 1 <-> 2 <-> 4 My Approach: 1️⃣ Handled edge cases deleting the head or an empty list. 2️⃣ Traversed to the node at position x. 3️⃣ Updated both prev and next pointers to unlink the node cleanly. Time Complexity: O(N) Space Complexity: O(1) Understanding pointer manipulation in linked lists builds the foundation for mastering advanced data structures. Every prev and next link matters! #100DaysOfCode #Java #ProblemSolving #DSA #GeeksforGeeks #LinkedList #Pointers #TakeUForward #CodeNewbie #CodingJourney
How to delete a node in a doubly linked list
More Relevant Posts
-
#100DaysOfCode – Day 76 Insert a Node in a Doubly Linked List Problem: Given a position p and a value x, insert a new node with data x after the p-th node (0-based indexing) in a doubly linked list. Example: Input: p = 2, x = 6 Output: 2 <-> 4 <-> 5 <-> 6 My Approach: Traversed to the p-th node using a simple loop. Updated pointers of the prev and next nodes carefully to maintain bidirectional linkage. Handled edge cases for insertion at the end of the list. Time Complexity: O(N) Space Complexity: O(1) Understanding pointer manipulation in linked lists builds a strong base for advanced data structure problems like deletion, reversal, and flattening of linked lists. #takeUforward #100DaysOfCode #DSA #Java #ProblemSolving #GeeksForGeeks #LinkedList #Pointers #CodingChallenge #CodeNewbie #LearningEveryday
To view or add a comment, sign in
-
-
🗓 Day 7 / 100 – #100DaysOfLeetCode 🔢 Problem 2536: Increment Submatrices by One Today’s challenge involved processing multiple submatrix increment queries on an n x n matrix, initially filled with zeros. 🧠 My Approach Instead of updating every cell inside each submatrix (which would be too slow for up to 10⁴ queries), I used a row-wise difference array technique. For each query [r1, c1, r2, c2]: Increment prefix[row][c1] Decrement prefix[row][c2+1] (if within bounds) This allows efficient marking of increments. Later, prefix-summing each row reconstructs the final matrix. ⏱ Time Complexity O(q × n) where q = number of queries (We touch r2 - r1 + 1 rows per query) 💾 Space Complexity O(n²) for the prefix matrix #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 6 of 30 Days of Data Structures Challenge Topics Covered Today: 🔹 Java Collection Framework (JCF) – LinkedList 🔹 Explored in-built LinkedList methods like add(), remove(), get(), addFirst(), addLast() and more. 🔹 Implemented Merge Sort on a LinkedList from Scratch. 📂 Code: https://lnkd.in/gk5-kdKv https://lnkd.in/gfdmpVWf #Java #DataStructures #LinkedList #MergeSort #JCF
To view or add a comment, sign in
-
-
🔹 Day 47: Find Pivot Index (LeetCode #724) 📌 Problem Statement: Given an array of integers nums, the pivot index is the index where the sum of all numbers to the left is equal to the sum of all numbers to the right. If no such index exists, return -1. If multiple exist, return the leftmost one. ✅ My Approach: I first calculated the total sum of the array, then iterated through each element keeping track of the left sum. At each index, I checked whether left sum == total sum - left sum - current element. If true, that index is the pivot index. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 0 ms (Beats 100%) Memory: 45.41 MB (Beats 66.27%) 💡 Reflection: This problem strengthened my understanding of prefix sums and efficient single-pass array traversal. A clean and optimized logic! 💪 #LeetCode #Java #Arrays #PrefixSum #100DaysOfCode #Day47
To view or add a comment, sign in
-
-
📌 LeetCode Day 57 — #107. Binary Tree Level Order Traversal II Problem Description: Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. That means you need to traverse the tree level by level from left to right, but from the bottom level up to the root. Approach: Use a Queue (BFS): Perform a standard level order traversal using a queue. Store Each Level: For each level, store the node values in a temporary list. Insert at Beginning: Instead of appending levels at the end, insert each level at index 0 to reverse the order. Return Result: The final list represents the bottom-up traversal. Complexity Analysis: Time Complexity: O(n) — every node is visited once. Space Complexity: O(n) — queue and result storage for all nodes. Hashtags: #BinaryTree #BFS #LogicBuilding #LeetCode100Days #Day57 #Java #ProblemSolving
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 73 String Manipulation Problem: Valid Anagram (LeetCode #242) Task: Given two strings s and t, return true if t is an anagram of s, otherwise false. Example: Input: s = "anagram", t = "nagaram" → Output: true Input: s = "rat", t = "car" → Output: false My Approach:- Method 1 – Sorting Converted both strings into character arrays. Sorted them and compared if equal, they’re anagrams! Time Complexity: O(n log n) Method 2 – Frequency Count (Optimized) Counted occurrences of each character in s and t. If every count matches, it’s a valid anagram. Time Complexity: O(n) | Space: O(1) String problems may look simple, but optimizing from sorting to counting makes a huge difference. Small logic shifts often lead to big performance gains! #100DaysOfCode #Java #ProblemSolving #LeetCode #CodingJourney #takeUforward #DataStructures #Algorithms #StringManipulation #GeeksForGeeks #CodeNewbie
To view or add a comment, sign in
-
-
Day 46/100 Problem Statement : You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros. In one operation you can choose any subarray from initial and increment each value by one. Return the minimum number of operations to form a target array from initial. The test cases are generated so that the answer fits in a 32-bit integer. Input: target = [1,2,3,2,1] Output: 3 Solution : https://lnkd.in/gsXFvUr3 public int minNumberOperations(int[] target) { final int n=target.length; int ans=target[0]; for(int i=1; i<n; i++) ans+=Math.max(target[i]-target[i-1], 0); return ans; } #100DaysDSA #100DaysOfCode #Java #Leetcode #Neetcode #Neetcode250 #TUF
To view or add a comment, sign in
-
🚀 Just Solved LeetCode #102 — Binary Tree Level Order Traversal 📘 Problem: Given the root of a binary tree, return the level order traversal of its nodes' values — meaning, traverse the tree level by level from left to right. Example: Input → [3,9,20,null,null,15,7] Output → [[3], [9,20], [15,7]] 🧠 My Approach: I solved this using a recursive approach instead of the usual queue-based BFS. 1️⃣ First, I calculated the total number of levels in the tree using recursion. 2️⃣ Then, for each level, I called a helper function `nThLevel()` to collect all nodes at that level. 3️⃣ I stored each level’s nodes in a separate list and finally returned a list of lists as the result. This approach helped me deeply understand the relationship between recursion depth and tree levels. 💡 What I Learned: ✅ Different ways to perform level order traversal — BFS vs recursion. ✅ How to effectively use recursion to explore each tree level. ✅ Improved understanding of function calls, base conditions, and data storage in recursive algorithms. #LeetCode #Java #DSA #BinaryTree #CodingJourney
To view or add a comment, sign in
-
-
🚀 Just implemented a custom Vector<T> class in Java — a dynamic array structure that grows automatically as elements are added. It supports key operations like push_back, pop_back, front, back, clear, and more — all while practicing the concepts of generics, dynamic memory allocation, and data encapsulation. Rebuilding core data structures from scratch is a great way to understand how tools like ArrayList work internally. 💻 #Java #DSA #LearningByDoing #CodingJourney #DataStructures Nohit Singh,Shreyash Khedekar,Anshuman Singh,Arpit Jain
To view or add a comment, sign in
-
💻 Day 03/10 of Linked List Series: Inserting a Node at the Beginning of a Linked List Let’s understand how we can add a new node at the start of a linked list 👇 ⚙️ Algorithm: Insert at Beginning Create a new node with the given data (for example, 'A'). Set the next pointer of this new node to point to the current head of the list. Now, make this new node the new head of the linked list. 💡 In simple terms: you’re placing a new link before the first link in the chain. 🧩 Example Explanation: Initial list: B → C → D We want to insert 'A' at the beginning. Steps: Create a new node 'A'. Point 'A' → 'B'. Return node 'A'. ✅ Final list becomes: A → B → C → D ✨ This operation is one of the most common and easiest insert operations in linked lists — it just needs a few pointer adjustments! 📚 Stay tuned for the next part in this #LinkedListSeries! Follow my Brand 👉 #CodeWithLakkojuEswaraSai #CodeWithLakkojuEswaraSai_LinkedList #DSA #Java #10000coders
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
Keep going 💪