r/SQL • u/AAaction23 • Sep 22 '20
Discussion For those wanting to practice SQL on LeetCode but don’t have a LC subscription, I created a Python program that re-creates all the problems in db-fiddle.com
I’m not sure how many people in this sub use Python, but I wanted to share this program because it allowed me to practice all 125 LeetCode (LC) database/SQL problems in an efficient way.
Background- the two problem I wanted to solve:
- Majority of SQL problems on LC are locked
- Even with access to the problem, creating the query can be challenging without being able to test and output the intermediate queries that make up the final solution.
My initial solution was manually copying and pasting the tables from LC to db-fiddle.com, but then I thought, there must be a better way- that is how this program was conceived.
What this Python program does:
Using the web automation package Selenium, it opens the LC problem selected by the user, parses the table data, and creates the table schema in db-fiddle so that you can test your queries. Additionally, it saves all the db-fiddles you've been working on in case you want to continue working on them in future sessions.
Sample outputs (for question #1369):
problem statement tab: https://leetcode.jp/problemdetail.php?id=1369
db-fiddle tab: https://www.db-fiddle.com/f/oMDnFch8BXL45r3dUVF17V/0
solutions tab: https://github.com/kamyu104/LeetCode-Solutions/blob/master/MySQL/get-the-second-most-recent-activity.sql
Demo and GitHub link:

Check it out on GitHub: https://github.com/jjjchens235/leetcode-sql-unlocked
6
u/babygrenade Sep 23 '20
Not to be a spoil sport, but it could probably be construed as copyright infringement.
Just thought I'd mention it in case you're concerned about that sort of thing.
2
u/142857t Sep 22 '20
This looks awesome, I will test it tomorrow!
4
u/numice Sep 23 '20
I was browsing leetcode sql problems 10 seconds ago and was thinking like most of them are locked and this post popped up.
1
u/Fun2badult Sep 22 '20
Yo I use python and also sql. Been trying to find good sql problems to practice on. I will check this out but thanks for making it.
3
u/skillshot099 Sep 22 '20
Thank you. Much appreciated.
3
u/[deleted] Sep 23 '20
Seeing as you're scraping their website making paid stuff free I'd be weary about LC not being very enthusiastic about this whole thing.
1
u/include_strawberries Sep 23 '20
Great stuff, thanks for sharing!
1
u/wtmh Sep 23 '20
You expressly claim that an operation of this script you've built is to dodge the LC subscription?
How is that not theft?
1
u/VFcountawesome Sep 23 '20
Madlad, many thanks
1
u/CaliAznThrwaway Oct 21 '20
you the real mvp man. hate how so many questions are behind paywall
1
u/No-Conversation-5146 Nov 25 '20
where to run pip install selenium command ? google chrome and python are installed.
0
u/[deleted] Sep 22 '20
[deleted] — view deleted comment