Simplifying SQL for LeetCode's Triangle Judgement

🚀 From Overthinking to Clean Logic — SQL Growth Moment! Solved “Triangle Judgement” on LeetCode and this one taught me something important 💡 At first, I tried solving it using nested CASE statements and multiple conditions — it worked, but it was unnecessarily complex. Then I realized the problem boils down to a simple mathematical rule 👇 👉 A triangle is valid if: x + y > z x + z > y y + z > x 🧠 Final Clean Approach: SELECT x, y, z, CASE WHEN x + y > z AND x + z > y AND y + z > x THEN 'Yes' ELSE 'No' END AS triangle FROM Triangle; 📊 Result: ✔️ Accepted ✅ (11/11 test cases passed) ✔️ Runtime: 305 ms 🔥 Key Takeaway: Sometimes the best solution isn’t the most complex one — it’s the simplest correct logic. Learning to simplify is just as important as learning to solve 💪 #SQL #LeetCode #CodingJourney #ProblemSolving #Learning #Tech #PlacementPreparation

  • graphical user interface

To view or add a comment, sign in

Explore content categories