Day 9 of #100DaysOfLeetCode Problem: 21. Merge Two Sorted Lists Category: Linked List / Two Pointers Today’s challenge focused on merging two sorted linked lists into a single sorted list. This problem was a great refresher on pointer management, conditional linking, and efficient traversal through nodes. 🧠 Key Learnings: Used two pointers to compare nodes from both lists and attach the smaller node to the merged list. Managed the traversal smoothly without losing reference to the new head node. Reinforced the concept of dummy nodes for cleaner list initialization. Strengthened confidence in working with linked data structures and node connections. 🎯 Takeaway: Linked lists teach the importance of precise pointer handling — one wrong reference can change the entire structure! #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #LinkedList #Pointers #Python #AIEngineer #Consistency
Dileep Kumar’s Post
More Relevant Posts
-
#Week2 | Mastering Trees: From Traversal to Validation This week, I dove deep into the world of tree data structures, specifically Binary Search Trees (BSTs). It was a fantastic exercise in understanding recursion and level-order logic. Here’s what I covered: * Implemented a BST from scratch, including node creation and value insertion. * Wrote functions for various traversal methods: inorder and level-order (BFS). * Built utility functions to search for values, find the minimum value, and calculate the tree's height. * Capped it off by creating a function to validate if a tree is a proper BST. Tech Stack: Python, Jupyter Notebook A key takeaway for me was seeing how an inorder traversal of a BST naturally produces a sorted list of its nodes. It’s a simple but powerful property! Next up: I’ll be moving on to another important data structure: Heaps! You can follow my progress and check out the code here: https://lnkd.in/gnJw38QM #AIJourney #DataStructures #Python #Trees #BST #LearningInPublic #12WeeksAIReset #CodingChallenge
To view or add a comment, sign in
-
-
🔍 Day 44 DSA Challenge – Problem #33: Search in Rotated Sorted Array 📌 Problem Statement: Given a sorted array nums that may have been rotated at an unknown pivot, find the index of a target value. Return -1 if the target doesn’t exist. The solution must run in O(log n) time. ⚙️ How I Solved It: Applied a modified binary search: Identify which half (left or right) is sorted. Narrow the search to the half where the target could exist. Repeat until the target is found or search space is exhausted. 📊 Performance Stats: ⏱ Runtime: 0 ms (⚡ beats 100%) 💾 Memory: 12.65 MB (beats 42.49%) ✅ Testcases Passed: 196 / 196 🧠 Key Takeaway: Understanding array properties like rotation and leveraging binary search ensures optimal search performance in logarithmic time. #LeetCode #BinarySearch #RotatedArray #Problem33 #Python #DSA #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Today, I want to talk a bit about Seaborn, a very handy visualization library in Python. Interestingly, its alia; sns was inspired by Samuel Norman Seaborn, a fictional character from the TV series The West Wing. While taking my DataCamp course, I got to learn a few cool things about Seaborn. First is the countplot module, which helps to visualize the number of unique values in a column of a dataset. It’s an easy way to get a quick overview of categorical data. Also, Seaborn can be your go-to tool when one needs to visualize specific aspects of your dataset quickly. Another interesting feature is "relplot", which can serve as a flexible alternative to scatterplot. By specifying the parameter kind="scatter", you can create scatter plots easily within the "relplot" function. That's it for now. Happy new week, LinkedIn. #datacamp #scatterplot #new_week
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 104 Problem: Flatten Binary Tree to Linked List 🌳➡️📄 This problem is a beautiful blend of tree traversal and pointer manipulation. The goal is to transform a binary tree into a linked list following preorder traversal, while modifying the tree in-place. 🧠 Problem Summary: You're given the root of a binary tree. Your task → Flatten the tree into a linked list such that: Each node’s right pointer acts as the “next” pointer. Each node’s left pointer is always None. The resulting order must follow preorder traversal: Root → Left → Right ⚙️ My Approach: I used a recursive DFS approach that processes nodes in a way that supports pointer restructuring: 1️⃣ Flatten left subtree 2️⃣ Flatten right subtree 3️⃣ If the current node has a left subtree: Temporarily store root.right Move root.left to root.right Nullify the left pointer Traverse to the end of this new right chain Attach the original right subtree there This ensures the node order becomes preorder while maintaining pointer correctness. 📌 Key Observations: Although preorder is Root → Left → Right, the flattening requires processing children first. Doing operations in-place ensures optimal space usage. Traversing to the end of the newly attached right subtree ensures that both left and right parts remain connected in correct order. 📈 Complexity: Time: O(n) — Each node is visited once Space: O(h) — Recursion stack (height of the tree) ✨ Key Takeaway: Flattening a binary tree becomes simple once you understand pointer realignment. First flatten both subtrees → then stitch them together → and the final structure becomes a clean preorder linked list. 🌳➡️🪜 🔖 #DSA #100DaysOfCode #Day104 #BinaryTrees #PreorderTraversal #TreeFlattening #Recursion #LeetCode #ProblemSolving #Python #CodingJourney #TechCommunity #LearningEveryday
To view or add a comment, sign in
-
-
I used to write def functions for everything...even for the tiniest one-line tasks. I’d proudly define a whole function just to square a number. 😅 Then one day, I came across lambda functions, and it honestly felt like discovering sticky notes for my code. If a regular def function is like writing down a full recipe in your notebook 🍳, then a lambda function is that quick sticky note 📝 you scribble on, use once, and move on. Here’s what I mean: # Using def def square(x): return x * x # Using lambda square = lambda x: x * x Sometimes, clean code isn’t about writing more. It’s about knowing when less is enough. 😉 #Python #LambdaFunction #CodingTips #DataScience #LearnPython #CleanCode
To view or add a comment, sign in
-
Day 55 – Using finally to Clean Up Some actions should happen no matter what — like closing files or releasing resources. Use finally for that 👇 try: file = open("data.txt", "r") print(file.read()) except FileNotFoundError: print("File not found!") finally: print("Closing file...") file.close() ✅ finally always executes ✅ Essential for clean resource handling 🚨 Forgetting to close files or connections = potential memory leaks! 👉 Ever used finally in your code? #Python #ErrorHandling #BestPractices #100DaysOfCode
To view or add a comment, sign in
-
Hey Everyone ! I have Just Finished a simple #python Script To understand huffman's algorithm In case Anyone Interested In learning Read this Below * Huffman’s algorithm is a way to compress data (make it smaller) by using shorter codes for frequent characters and longer codes for rare ones. And The steps Are : > Count frequency of each character in the data. > Build a tree > Assign binary codes > Encode the data Wanna Check the Code? Here is my github repo : https://lnkd.in/dAi7cqZf Have a Great Day Guys ! Any questions Feel free to ask me. hashtag #Algorithms hashtag #DataStructures hashtag #ComputerScience
To view or add a comment, sign in
-
Day 31 / 100 – Add Strings (LeetCode #415) Today’s challenge was all about simulating manual addition without using any built-in integer conversions. Given two numbers as strings, the task was to return their sum — also as a string. This problem really emphasized the importance of breaking problems into small, logical steps rather than relying on shortcuts. 🔍 Key Learnings Recreated the digit-by-digit addition process using ASCII values. Practiced handling carry-over efficiently while iterating backward. Strengthened my understanding of string manipulation and arithmetic logic. 💭 Thought of the Day True problem-solving isn’t about using built-ins — it’s about understanding how things work underneath. Today reminded me that mastery grows when we rebuild the basics from scratch, not when we avoid them. 🔗 Problem Link: https://lnkd.in/gHMt9vj9 #100DaysOfCode #Day31 #LeetCode #Python #ProblemSolving #StringManipulation #Algorithms #DataStructures #CodingChallenge #CodeEveryday #TechGrowth #LearningJourney
To view or add a comment, sign in
-
-
#96day of #100DaysOfCode 🌱 LeetCode 109: Convert Sorted List to Binary Search Tree Today’s challenge was about building balance — literally! Given a sorted linked list, we need to convert it into a height-balanced BST 🌳 🧠 Key Idea: The middle element of the list becomes the root. Left half forms the left subtree, right half forms the right subtree. Use slow–fast pointers to find the middle efficiently. 📈 Complexity: Time: O(n log n) Space: O(log n) (recursion stack) 💬 Learning: Balance matters — in trees, in code, and in life 🌿 Sometimes, the middle point creates the strongest foundation. #LeetCode #DSA #BinarySearchTree #LinkedList #CodingChallenge #Python #Algorithm #LeetCodeDaily #100DaysOfCode
To view or add a comment, sign in
-
-
Ever spent a lot of time debugging a data issue, only to realize it came from a join where the keys weren’t 𝘢𝘤𝘵𝘶𝘢𝘭𝘭𝘺 unique? Turns out both pandas and polars have a simple fix for that! The 𝐯𝐚𝐥𝐢𝐝𝐚𝐭𝐞 argument in the .𝐣𝐨𝐢𝐧() method. This argument catches duplicate keys early and throws an error if the uniqueness condition is not met, saving us from data explosions passing through silently an causing more trouble downstream. Best part? It’s less than one extra line of code! ——— This post is part of my 𝘋𝘢𝘵𝘢 𝘚𝘤𝘪𝘦𝘯𝘤𝘦 𝘍𝘭𝘢𝘴𝘩𝘤𝘢𝘳𝘥𝘴 series, consisting of concepts pulled from my personal flashcard practice that I find particularly useful or relevant to share #dataanalysis #datascience #polars #python
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