Day 21/100 of #100DaysOfCode 💻 Today's problem made me think in trees. 🌳 Tree Node:- Given a tree structure in a table, classify each node as Root, Inner, or Leaf. The logic: Root → has no parent (p_id IS NULL) Inner → appears as a parent of someone else Leaf → everything else I didn't get it right on the first try. 😅 My first attempt used "WHERE p_id = 1" inside the subquery, which hardcodes the root and breaks for any other tree structure. Wrong logic, wrong output. Then I stepped back and thought about it properly (Code is given in the image) 💡 The fix is instead of hardcoding, ask "does this node appear as a parent of anyone?" If yes → Inner. That's the real tree logic. Never hardcode what SQL can figure out dynamically. 🧩 Trial and error is part of the process. The wrong attempt taught me more than the right one. 😄 #SQL #100DaysOfCode #LearningInPublic #DataAnalytics #Consistency #DevJourney #LeetCode
Classifying Tree Nodes in SQL with Dynamic Logic
More Relevant Posts
-
🚀 Day 28/50 #LeetCodeChallenge Today’s problem: Biggest Single Number This problem was a brilliant exercise in combining Aggregation with Subqueries to filter out duplicates effectively. 🔥 💡 Problem Insight: The task was to find the largest number that appears only once in the table. If no unique number exists, the result should be null. 🧠 Key Learning: Identify Uniqueness: Used GROUP BY combined with HAVING COUNT(*) = 1 to isolate numbers that don't repeat. The Power of MAX(): Applied MAX() on the filtered subset to grab the highest value. Handling Nulls: Using MAX() on a subquery is a clean way to ensure a null output if the criteria aren't met, instead of getting an empty result set. ⚡ Big Realization: The real trick isn't just finding the maximum—it's knowing how to exclude data that doesn't fit your constraints (duplicates) before you look for the top value. 📈 Takeaway: SQL logic is often about "layers." Filtering the noise first makes finding the answer straightforward. Consistency > Difficulty 💯 #Day28 #LeetCode #SQL #DataAnalytics #LearningJourney #CodingChallenge #50DaysOfChallenge
To view or add a comment, sign in
-
-
Small wins don’t look small when you know the effort behind them. Just hit SQL 50 on LeetCode — not a huge milestone on paper, but it forced me to slow down, think clearly, and actually understand what I was writing instead of just “making queries work.” What changed for me wasn’t just solving problems — it was: • thinking in joins instead of steps • debugging logic instead of syntax • realizing how easy it is to get almost correct answers Still a long way to go, but this feels like a solid step in the right direction. On to the next 50.... #SQL #LeetCode #DataStructures #ProblemSolving #LearningJourney #Consistency #TechGrowth #SoftwareEngineering #CodingLife #DeveloperMindset #KeepBuilding #100DaysOfCode #DataAnalytics #BackendDevelopment #QueryOptimization #StudentsInTech #FutureEngineer #GrowthMindset #PracticeMakesProgress #TechCareers
To view or add a comment, sign in
-
-
🚀 Day 34/50 – #LeetCode Challenge Today’s problem: Product Price at a Given Date 📊 This one really tested my understanding of handling time-based data in SQL. 💡 Key Learning: When dealing with historical data, it's important to focus on the latest valid record before a given date — not just any record. 🔍 Approach I used: Consider all products Find the most recent price change on or before the target date (2019-08-16) If no change exists → use default price = 10 Used concepts like MAX(date), GROUP BY, and JOIN 🧠 What I improved today: Writing cleaner SQL queries Handling edge cases (no previous data) Thinking in terms of real-world data scenarios 🔥 Consistency is building confidence step by step. #Day34 #LeetCode #SQL #DataStructures #CodingJourney #Consistency #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 Day 26 – 30 Days SQL LeetCode Challenge Today’s problem was simple but highlights an important real-world scenario 👀 📌 Today's Problem: Article Views I (LeetCode #1148) 🧠 Problem Statement: Find all authors who viewed at least one of their own articles. 💡 Key SQL Concepts Used: • DISTINCT • Filtering with conditions • Comparing columns within the same row 📚 What I Practiced Today: ✔ Comparing values within the same table ✔ Removing duplicates using DISTINCT ✔ Writing clean filtering queries 🔥 This pattern is useful in: • Detecting self-actions (self-purchases, self-views) • Fraud detection • User behavior analysis 🔗 GitHub Repository: https://lnkd.in/e8aV37dA #SQL #LeetCode #DataAnalytics #30DaysOfSQL #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 11/30 of My LeetCode Journey (SQL Focus) Keeping the momentum going and diving deeper into SQL concepts! 📊🔥 🔹 **SQL Problem of the Day** 👉 *Rank Scores* Given a `Scores` table, write a query to rank the scores from highest to lowest. Rules: • Same scores share the same rank • No gaps in ranking (dense ranking) 💡 *Key Concept:* Using ranking functions like `DENSE_RANK()` (or alternative logic if not available). Understanding ranking functions is a game changer for analytical queries 📈 Day 11 done ✅ #LeetCode #30DaysChallenge #SQL #CodingJourney #Consistency #ProblemSolving #DataAnalytics #Learning
To view or add a comment, sign in
-
🚀 Day 28/100 – LeetCode SQL Challenge Today’s problem: Triangle Judgement 📌 What I learned today: How to apply real-world mathematical logic (Triangle Inequality Rule) in SQL Using CASE statements to create conditional outputs Writing clean and readable SQL queries for decision-making problems 🔍 Key Concept: A triangle is valid only if: x + y > z y + z > x x + z > y 💡 If all conditions are satisfied → “Yes” Otherwise → “No” 🧠 This problem helped me understand how SQL is not just about data retrieval, but also about applying logical conditions effectively. Consistency is the key 🔑 #Day28 #100DaysOfCode #LeetCode #SQL #Learning #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
39 problems solved. No shortcuts, no cramming. Just one problem a day — sometimes two if the first one clicks fast. Linked lists, backtracking, SQL queries, greedy scans. Each one a little uncomfortable at first, then suddenly obvious once it lands. That's kind of the whole point. Dashboard → https://lnkd.in/eWjTD6_P Repo → https://lnkd.in/ePM5inyX #LeetCode #CodingJourney #100DaysOfCode #BuildInPublic #SoftwareEngineering #ConsistencyOverMotivation #ProblemSolving
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 𝟯𝟮 𝗼𝗳 𝗠𝘆 𝗦𝗤𝗟 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 Today was all about diving deeper into 𝗥𝗲𝗰𝘂𝗿𝘀𝗶𝘃𝗲 𝗖𝗧𝗘𝘀 and 𝗵𝗶𝗲𝗿𝗮𝗿𝗰𝗵𝗶𝗰𝗮𝗹 𝗾𝘂𝗲𝗿𝗶𝗲𝘀 — a really powerful concept in SQL! 🔍 𝗪𝗵𝗮𝘁 𝗜 𝗟𝗲𝗮𝗿𝗻𝗲𝗱: * Recursive CTE concept (breaking problems into base + recursive parts) 𝗛𝗶𝗲𝗿𝗮𝗿𝗰𝗵𝘆 𝗵𝗮𝗻𝗱𝗹𝗶𝗻𝗴 𝘂𝘀𝗶𝗻𝗴: * START WITH * CONNECT BY PRIOR * LEVEL * SYS_CONNECT_BY_PATH * CONNECT_BY_ROOT 💡 Solved two Interview Questions : 1️⃣ Print values from 1 to N using recursion 2️⃣ Find multiple missing values in a sequence Step by step, getting more confident with SQL every day 💪 #SQL #LearningJourney #Day32 #RecursiveCTE #Database #Coding
To view or add a comment, sign in
-
-
Solving the SQL 50 challenge on LeetCode has been an exciting and confidence-boosting journey. Each problem pushed me to think deeper, optimize queries, and strengthen my understanding of SQL concepts. From basic queries to advanced topics like joins, aggregations, subqueries, and window functions — this journey was truly enriching 💡 📘 What’s in my notes/document? A structured study guide covering: All 50 problems with solutions Clear explanations for each query Key SQL concepts like SELECT, JOINs, Aggregations, Window Functions, and more Practical patterns and best practices for real-world scenarios Once you get a solid grip on fundamentals, problems labeled medium or even hard start feeling like easy. It’s all about consistency and practice. #SQL #LeetCode #DataEngineering #LearningJourney #sql50
To view or add a comment, sign in
-
Day 18/100 of #100DaysOfCode 💻 Short query. Clear logic. Clean result. 🎯 Customer Placing the Largest Number of Orders:- Find the customer who placed the most orders from the Orders table. GROUP BY to count orders per customer → ORDER BY COUNT DESC to rank them → LIMIT 1 to grab the top one. Done. ✅ 💡 The real insight here - LIMIT 1 is one of those small but powerful tools. Instead of writing a subquery or CTE to find the max, just sort and slice. Cleaner and faster. Sometimes the best query is the shortest one. 🧩 Not every day is a Hard problem grind, some days you just stay consistent, show up, and keep the streak alive. That matters too. 😄 #SQL #100DaysOfCode #LearningInPublic #DataAnalytics #Consistency #DevJourney #LeetCode
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