├── .gitignore ├── README.md ├── blind_75.pdf ├── export_all_questions.py ├── question_links.txt └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .venv 2 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Basically a fork of [yask's repo](https://github.com/yask123/all_leetcode_questions) but I don't think the repo name 'all-leetcode-questions' fits given the smaller amount of questions here. 2 | 3 | Repo is updated to work with LeetCode's GraphQL API and only includes the [Blind 75](https://www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU). The code should theoretically work with any Leetcode question list though. 4 | 5 | Questions are currently only available in PDF format. 6 | 7 | Feel free to submit a PR to include other lists e.g topic specific lists. 8 | 9 | ### Usage 10 | 11 | You can download '.pdf' file from this repo and view it however you want. 12 | 13 | ### Building PDF 14 | 15 | This repo relies on WeasyPrint which itself has some annoying dependencies to install. Refer to their [documentation](https://doc.courtbouillon.org/weasyprint/latest/first_steps.html) for platform specific installation steps. 16 | 17 | __NOTE__ For MacOS you may also need to install LibMagic with `brew install libmagic` 18 | 19 | Run the following to install other dependencies 20 | ```python 21 | virtualenv .venv 22 | source .venv/bin/activate 23 | pip install -r requirements.txt 24 | ``` 25 | 26 | In virtualenv, run `python3 export_all_questions.py` to generate PDF. 27 | 28 | ### Updating questions 29 | 30 | Add the new question link in the file `question_links.txt` and run `export_all_questions.py` python script. 31 | 32 | To get all questions in a LeetCode list, visit a LeetCode URL with problem links visible on the page e.g `https://leetcode.com/list/xi4ci4ig/`. Open up the dev console and run the following code. Make sure all problem links are visible e.g extend list view > 50 to show all problem links if needed. 33 | 34 | ``` 35 | var links = document.getElementsByTagName('a'); 36 | var all_links = Array.prototype.slice.call(links); 37 | var problems_str = ""; 38 | all_links.forEach(function(val) { 39 | if (val.href.includes('/problems/') && !val.href.includes('/solution')) { 40 | problems_str = problems_str.concat(`${val.href}\n`) 41 | } 42 | }); 43 | console.log(problems_str) 44 | ``` 45 | -------------------------------------------------------------------------------- /blind_75.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raiyansayeed/leetcode-download-questions/7ec53ff2f318e4aed87f41ce5b0aadb843fd2804/blind_75.pdf -------------------------------------------------------------------------------- /export_all_questions.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | from types import SimpleNamespace 4 | from weasyprint import HTML 5 | 6 | baseJSON = { 7 | "operationName": "questionData", 8 | "variables": { 9 | "titleSlug": "PLACEHOLDER" 10 | }, 11 | "query": "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n exampleTestcases\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n paidOnly\n hasVideoSolution\n paidOnlyVideo\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n enableDebugger\n envInfo\n libraryUrl\n adminUrl\n __typename\n }\n}\n" 12 | } 13 | 14 | graphQLEndpoint = 'https://leetcode.com/graphql' 15 | 16 | htmlstr = '
' 17 | htmlstr += '' 18 | 19 | def update_question_links(question_links): 20 | with open('question_links.txt') as f: 21 | links = f.read() 22 | 23 | links = links.split('\n') 24 | 25 | for each in links: 26 | question_links.append(each) 27 | 28 | def get_section(section_text): 29 | global htmlstr 30 | htmlstr += '
' 31 | htmlstr += f'

{section_text[1:]}

' 32 | htmlstr += '
' 33 | htmlstr += '

' 34 | 35 | def get_question(question_link): 36 | slug = question_link.split('https://leetcode.com/problems/', 1)[1] 37 | baseJSON['variables']['titleSlug'] = slug 38 | resp = requests.get(graphQLEndpoint, json=baseJSON) 39 | 40 | x = json.loads(resp.text, object_hook=lambda d: SimpleNamespace(**d)) 41 | 42 | global htmlstr 43 | htmlstr += '
' 44 | htmlstr += f'

{x.data.question.title}

' 45 | htmlstr += x.data.question.content 46 | htmlstr += '
' 47 | htmlstr += '

' 48 | 49 | def main(): 50 | question_links = [] 51 | update_question_links(question_links) 52 | for line in question_links: 53 | try: 54 | if line[0] == '~': 55 | get_section(line) 56 | else: 57 | get_question(line) 58 | 59 | print(line) 60 | print('------------------------------') 61 | 62 | except: 63 | continue 64 | 65 | global htmlstr 66 | htmlstr += '
' 67 | HTML(string=htmlstr).write_pdf('blind_75.pdf') 68 | 69 | 70 | if __name__=='__main__': 71 | print('\n') 72 | main() 73 | 74 | -------------------------------------------------------------------------------- /question_links.txt: -------------------------------------------------------------------------------- 1 | ~Array 2 | https://leetcode.com/problems/two-sum 3 | https://leetcode.com/problems/best-time-to-buy-and-sell-stock 4 | https://leetcode.com/problems/contains-duplicate 5 | https://leetcode.com/problems/product-of-array-except-self 6 | https://leetcode.com/problems/maximum-subarray 7 | https://leetcode.com/problems/maximum-product-subarray 8 | https://leetcode.com/problems/find-minimum-in-rotated-sorted-array 9 | https://leetcode.com/problems/search-in-rotated-sorted-array 10 | https://leetcode.com/problems/3sum 11 | https://leetcode.com/problems/container-with-most-water 12 | ~Binary 13 | https://leetcode.com/problems/sum-of-two-integers 14 | https://leetcode.com/problems/number-of-1-bits 15 | https://leetcode.com/problems/counting-bits 16 | https://leetcode.com/problems/missing-number 17 | https://leetcode.com/problems/reverse-bits 18 | ~Dynamic Programming 19 | https://leetcode.com/problems/climbing-stairs 20 | https://leetcode.com/problems/coin-change 21 | https://leetcode.com/problems/longest-increasing-subsequence 22 | https://leetcode.com/problems/longest-common-subsequence 23 | https://leetcode.com/problems/word-break 24 | https://leetcode.com/problems/combination-sum-iv 25 | https://leetcode.com/problems/house-robber 26 | https://leetcode.com/problems/house-robber-ii 27 | https://leetcode.com/problems/decode-ways 28 | https://leetcode.com/problems/unique-paths 29 | https://leetcode.com/problems/jump-game 30 | ~Graph 31 | https://leetcode.com/problems/clone-graph 32 | https://leetcode.com/problems/course-schedule 33 | https://leetcode.com/problems/pacific-atlantic-water-flow 34 | https://leetcode.com/problems/number-of-islands 35 | https://leetcode.com/problems/longest-consecutive-sequence 36 | https://leetcode.com/problems/alien-dictionary 37 | https://leetcode.com/problems/graph-valid-tree 38 | https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph 39 | ~Interval 40 | https://leetcode.com/problems/insert-interval 41 | https://leetcode.com/problems/merge-intervals 42 | https://leetcode.com/problems/non-overlapping-intervals 43 | https://leetcode.com/problems/meeting-rooms 44 | https://leetcode.com/problems/meeting-rooms-ii 45 | ~Linked List 46 | https://leetcode.com/problems/reverse-linked-list 47 | https://leetcode.com/problems/linked-list-cycle 48 | https://leetcode.com/problems/merge-two-sorted-lists 49 | https://leetcode.com/problems/merge-k-sorted-lists 50 | https://leetcode.com/problems/remove-nth-node-from-end-of-list 51 | https://leetcode.com/problems/reorder-list 52 | ~Matrix 53 | https://leetcode.com/problems/set-matrix-zeroes 54 | https://leetcode.com/problems/spiral-matrix 55 | https://leetcode.com/problems/rotate-image 56 | https://leetcode.com/problems/word-search 57 | ~String 58 | https://leetcode.com/problems/longest-substring-without-repeating-characters 59 | https://leetcode.com/problems/longest-repeating-character-replacement 60 | https://leetcode.com/problems/minimum-window-substring 61 | https://leetcode.com/problems/valid-anagram 62 | https://leetcode.com/problems/group-anagrams 63 | https://leetcode.com/problems/valid-parentheses 64 | https://leetcode.com/problems/valid-palindrome 65 | https://leetcode.com/problems/longest-palindromic-substring 66 | https://leetcode.com/problems/palindromic-substrings 67 | https://leetcode.com/problems/encode-and-decode-strings 68 | ~Tree 69 | https://leetcode.com/problems/maximum-depth-of-binary-tree 70 | https://leetcode.com/problems/same-tree 71 | https://leetcode.com/problems/invert-binary-tree 72 | https://leetcode.com/problems/binary-tree-maximum-path-sum 73 | https://leetcode.com/problems/binary-tree-level-order-traversal 74 | https://leetcode.com/problems/serialize-and-deserialize-binary-tree 75 | https://leetcode.com/problems/subtree-of-another-tree 76 | https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal 77 | https://leetcode.com/problems/validate-binary-search-tree 78 | https://leetcode.com/problems/kth-smallest-element-in-a-bst 79 | https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree 80 | https://leetcode.com/problems/implement-trie-prefix-tree 81 | https://leetcode.com/problems/add-and-search-word-data-structure-design 82 | https://leetcode.com/problems/word-search-ii 83 | ~Heap 84 | https://leetcode.com/problems/merge-k-sorted-lists 85 | https://leetcode.com/problems/top-k-frequent-elements 86 | https://leetcode.com/problems/find-median-from-data-stream 87 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.26.0 2 | weasyprint==53.0 --------------------------------------------------------------------------------