Back to Browse

LeetCode 610 - Triangle Judgement (Python and SQL) [Easy]

280 views
Apr 2, 2024
7:02

🧠 Don’t miss out! Get FREE access to my Skool community — packed with resources, tools, and support to help you with Data, Machine Learning, and AI Automations! 📈 https://www.skool.com/data-and-ai-automations-4579 In this video, we solve LeetCode Problem 610: Triangle Judgement using both SQL and Python. This problem is a great exercise in applying basic geometric rules and logical filtering to a database problem. LeetCode 610 - Triangle Judgement: https://leetcode.com/problems/triangle-judgement/description/ 🚀 Hire me for Data Work: https://ryanandmattdatascience.com/data-freelancing/ 👨‍💻 Mentorships: https://ryanandmattdatascience.com/mentorship/ 📧 Email: [email protected] 🌐 Website & Blog: https://ryanandmattdatascience.com/ 🖥️ Discord: https://discord.com/invite/F7dxbvHUhg 📚 *Practice SQL & Python Interview Questions: https://stratascratch.com/?via=ryan 📖 *SQL and Python Courses: https://datacamp.pxf.io/XYD7Qg 🍿 WATCH NEXT LeetCode Playlist: https://www.youtube.com/playlist?list=PLcQVY5V2UY4J_wlwSXiEuf2KrEBan0Ysv LeetCode 184: https://youtu.be/s4e_OA6FZVY LeetCode 608: https://youtu.be/-hHUVAlTwZg LeetCode 607: https://youtu.be/l_SnJzz1IgM In this video, I walk through LeetCode question 610, Triangle Judgment, solving it in both SQL and Python Pandas. This is an easy-level SQL problem that requires you to determine whether three line segments can form a triangle based on the triangle inequality theorem. I start by breaking down the problem statement and explaining the mathematical logic behind triangle formation: the sum of any two sides must be greater than the third side. For the SQL solution, I demonstrate how to use a CASE statement to evaluate all three conditions and return "yes" or "no" accordingly. The solution uses SELECT * to preserve all columns while adding the triangle column. For the Pandas solution, I create a custom function called is_triangle that accepts a row as input and uses if-else logic to evaluate the same triangle conditions. I then show how to use the apply() method with axis=1 to apply this function row-by-row across the entire dataframe, creating the new triangle column. Both solutions are line-by-line explained so you can understand exactly how the logic works and why each step is necessary. By the end of this tutorial, you will know how to solve triangle judgment problems using both SQL and Pandas approaches. TIMESTAMPS 00:00 Problem Introduction & Overview 00:40 Understanding Triangle Formation Logic 01:42 Building the SQL Solution 02:52 SQL Case Statement Explained 03:42 Python Pandas Solution Setup 04:38 Creating the Triangle Validation Function 05:45 Applying the Function & Final Output OTHER SOCIALS: Ryan’s LinkedIn: https://www.linkedin.com/in/ryan-p-nolan/ Matt’s LinkedIn: https://www.linkedin.com/in/matt-payne-ceo/ Twitter/X: https://x.com/RyanMattDS Who is Ryan Ryan is a Data Scientist at a fintech company, where he focuses on fraud prevention in underwriting and risk. Before that, he worked as a Data Analyst at a tax software company. He holds a degree in Electrical Engineering from UCF. Who is Matt Matt is the founder of Width.ai, an AI and Machine Learning agency. Before starting his own company, he was a Machine Learning Engineer at Capital One. *This is an affiliate program. We receive a small portion of the final sale at no extra cost to you.

Download

1 formats

Video Formats

360pmp410.7 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

LeetCode 610 - Triangle Judgement (Python and SQL) [Easy] | NatokHD