Skip to content

Instantly share code, notes, and snippets.

@ChrisSwanson
Last active February 18, 2024 10:03
Show Gist options
  • Save ChrisSwanson/67e48aae01821b3d40e0f825ec637c3f to your computer and use it in GitHub Desktop.
Save ChrisSwanson/67e48aae01821b3d40e0f825ec637c3f to your computer and use it in GitHub Desktop.
blind-75-leetsolves
#!/usr/bin/env python3
import os
problems = {
"problems": {
"Array": {
"two-sum": {
"name": "Two Sum",
"premium": False,
"url": "https://leetcode.com/problems/two-sum/"
},
"best-time-to-buy-and-sell-stock": {
"name": "Best Time to Buy and Sell Stock",
"premium": False,
"url": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock/"
},
"contains-duplicate": {
"name": "Contains Duplicate",
"premium": False,
"url": "https://leetcode.com/problems/contains-duplicate/"
},
"product-of-array-except-self": {
"name": "Product of Array Except Self",
"premium": False,
"url": "https://leetcode.com/problems/product-of-array-except-self/"
},
"maximum-subarray": {
"name": "Maximum Subarray",
"premium": False,
"url": "https://leetcode.com/problems/maximum-subarray/"
},
"maximum-product-subarray": {
"name": "Maximum Product Subarray",
"premium": False,
"url": "https://leetcode.com/problems/maximum-product-subarray/"
},
"find-minimum-in-rotated-sorted-array": {
"name": "Find Minimum in Rotated Sorted Array",
"premium": False,
"url": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/"
},
"search-in-rotated-sorted-array": {
"name": "Search in Rotated Sorted Array",
"premium": False,
"url": "https://leetcode.com/problems/search-in-rotated-sorted-array/"
},
"3sum": {
"name": "3 Sum",
"premium": False,
"url": "https://leetcode.com/problems/3sum/"
},
"container-with-most-water": {
"name": "Container With Most Water",
"premium": False,
"url": "https://leetcode.com/problems/container-with-most-water/"
}
}, "Binary": {
"sum-of-two-integers": {
"name": "Sum of Two Integers",
"premium": False,
"url": "https://leetcode.com/problems/sum-of-two-integers/"
},
"number-of-1-bits": {
"name": "Number of 1 Bits",
"premium": False,
"url": "https://leetcode.com/problems/number-of-1-bits/"
},
"counting-bits": {
"name": "Counting Bits",
"premium": False,
"url": "https://leetcode.com/problems/counting-bits/"
},
"missing-number": {
"name": "Missing Number",
"premium": False,
"url": "https://leetcode.com/problems/missing-number/"
},
"reverse-bits": {
"name": "Reverse Bits",
"premium": False,
"url": "https://leetcode.com/problems/reverse-bits/"
}
}, "Dynamic Programming": {
"climbing-stairs": {
"name": "Climbing Stairs",
"premium": False,
"url": "https://leetcode.com/problems/climbing-stairs/"
},
"coin-change": {
"name": "Coin Change",
"premium": False,
"url": "https://leetcode.com/problems/coin-change/"
},
"longest-increasing-subsequence": {
"name": "Longest Increasing Subsequence",
"premium": False,
"url": "https://leetcode.com/problems/longest-increasing-subsequence/"
},
"longest-common-subsequence": {
"name": "Longest Common Subsequence",
"premium": False,
"url": "https://leetcode.com/problems/longest-common-subsequence/"
},
"word-break": {
"name": "Word Break Problem",
"premium": False,
"url": "https://leetcode.com/problems/word-break/"
},
"combination-sum-iv": {
"name": "Combination Sum",
"premium": False,
"url": "https://leetcode.com/problems/combination-sum-iv/"
},
"house-robber": {
"name": "House Robber",
"premium": False,
"url": "https://leetcode.com/problems/house-robber/"
},
"house-robber-ii": {
"name": "House Robber II",
"premium": False,
"url": "https://leetcode.com/problems/house-robber-ii/"
},
"decode-ways": {
"name": "Decode Ways",
"premium": False,
"url": "https://leetcode.com/problems/decode-ways/"
},
"unique-paths": {
"name": "Unique Paths",
"premium": False,
"url": "https://leetcode.com/problems/unique-paths/"
},
"jump-game": {
"name": "Jump Game",
"premium": False,
"url": "https://leetcode.com/problems/jump-game/"
}
}, "Graph": {
"clone-graph": {
"name": "Clone Graph",
"premium": False,
"url": "https://leetcode.com/problems/clone-graph/"
},
"course-schedule": {
"name": "Course Schedule",
"premium": False,
"url": "https://leetcode.com/problems/course-schedule/"
},
"pacific-atlantic-water-flow": {
"name": "Pacific Atlantic Water Flow",
"premium": False,
"url": "https://leetcode.com/problems/pacific-atlantic-water-flow/"
},
"number-of-islands": {
"name": "Number of Islands",
"premium": False,
"url": "https://leetcode.com/problems/number-of-islands/"
},
"longest-consecutive-sequence": {
"name": "Longest Consecutive Sequence",
"premium": False,
"url": "https://leetcode.com/problems/longest-consecutive-sequence/"
},
"alien-dictionary": {
"name": "Alien Dictionary",
"premium": True,
"url": "https://leetcode.com/problems/alien-dictionary/"
},
"graph-valid-tree": {
"name": "Graph Valid Tree",
"premium": True,
"url": "https://leetcode.com/problems/graph-valid-tree/"
},
"number-of-connected-components-in-an-undirected-graph": {
"name": "Number of Connected Components in an Undirected Graph",
"premium": True,
"url": "https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/"
}
}, "Interval": {
"insert-interval": {
"name": "Insert Interval",
"premium": False,
"url": "https://leetcode.com/problems/insert-interval/"
},
"merge-intervals": {
"name": "Merge Intervals",
"premium": False,
"url": "https://leetcode.com/problems/merge-intervals/"
},
"non-overlapping-intervals": {
"name": "Non-overlapping Intervals",
"premium": False,
"url": "https://leetcode.com/problems/non-overlapping-intervals/"
},
"meeting-rooms": {
"name": "Meeting Rooms",
"premium": True,
"url": "https://leetcode.com/problems/meeting-rooms/"
},
"meeting-rooms-ii": {
"name": "Meeting Rooms II",
"premium": True,
"url": "https://leetcode.com/problems/meeting-rooms-ii/"
}
}, "Linked List": {
"reverse-linked-list": {
"name": "Reverse a Linked List",
"premium": False,
"url": "https://leetcode.com/problems/reverse-linked-list/"
},
"linked-list-cycle": {
"name": "Detect Cycle in a Linked List",
"premium": False,
"url": "https://leetcode.com/problems/linked-list-cycle/"
},
"merge-two-sorted-lists": {
"name": "Merge Two Sorted Lists",
"premium": False,
"url": "https://leetcode.com/problems/merge-two-sorted-lists/"
},
"merge-k-sorted-lists": {
"name": "Merge K Sorted Lists",
"premium": False,
"url": "https://leetcode.com/problems/merge-k-sorted-lists/"
},
"remove-nth-node-from-end-of-list": {
"name": "Remove Nth Node From End Of List",
"premium": False,
"url": "https://leetcode.com/problems/remove-nth-node-from-end-of-list/"
},
"reorder-list": {
"name": "Reorder List",
"premium": False,
"url": "https://leetcode.com/problems/reorder-list/"
}
}, "Matrix": {
"set-matrix-zeroes": {
"name": "Set Matrix Zeroes",
"premium": False,
"url": "https://leetcode.com/problems/set-matrix-zeroes/"
},
"spiral-matrix": {
"name": "Spiral Matrix",
"premium": False,
"url": "https://leetcode.com/problems/spiral-matrix/"
},
"rotate-image": {
"name": "Rotate Image",
"premium": False,
"url": "https://leetcode.com/problems/rotate-image/"
},
"word-search": {
"name": "Word Search",
"premium": False,
"url": "https://leetcode.com/problems/word-search/"
}
}, "String": {
"longest-substring-without-repeating-characters": {
"name": "Longest Substring Without Repeating Characters",
"premium": False,
"url": "https://leetcode.com/problems/longest-substring-without-repeating-characters/"
},
"longest-repeating-character-replacement": {
"name": "Longest Repeating Character Replacement",
"premium": False,
"url": "https://leetcode.com/problems/longest-repeating-character-replacement/"
},
"minimum-window-substring": {
"name": "Minimum Window Substring",
"premium": False,
"url": "https://leetcode.com/problems/minimum-window-substring/"
},
"valid-anagram": {
"name": "Valid Anagram",
"premium": False,
"url": "https://leetcode.com/problems/valid-anagram/"
},
"group-anagrams": {
"name": "Group Anagrams",
"premium": False,
"url": "https://leetcode.com/problems/group-anagrams/"
},
"valid-parentheses": {
"name": "Valid Parentheses",
"premium": False,
"url": "https://leetcode.com/problems/valid-parentheses/"
},
"valid-palindrome": {
"name": "Valid Palindrome",
"premium": False,
"url": "https://leetcode.com/problems/valid-palindrome/"
},
"longest-palindromic-substring": {
"name": "Longest Palindromic Substring",
"premium": False,
"url": "https://leetcode.com/problems/longest-palindromic-substring/"
},
"palindromic-substrings": {
"name": "Palindromic Substrings",
"premium": False,
"url": "https://leetcode.com/problems/palindromic-substrings/"
},
"encode-and-decode-strings": {
"name": "Encode and Decode Strings",
"premium": True,
"url": "https://leetcode.com/problems/encode-and-decode-strings/"
}
}, "Tree": {
"maximum-depth-of-binary-tree": {
"name": "Maximum Depth of Binary Tree",
"premium": False,
"url": "https://leetcode.com/problems/maximum-depth-of-binary-tree/"
},
"same-tree": {
"name": "Same Tree",
"premium": False,
"url": "https://leetcode.com/problems/same-tree/"
},
"invert-binary-tree": {
"name": "Invert/Flip Binary Tree",
"premium": False,
"url": "https://leetcode.com/problems/invert-binary-tree/"
},
"binary-tree-maximum-path-sum": {
"name": "Binary Tree Maximum Path Sum",
"premium": False,
"url": "https://leetcode.com/problems/binary-tree-maximum-path-sum/"
},
"binary-tree-level-order-traversal": {
"name": "Binary Tree Level Order Traversal",
"premium": False,
"url": "https://leetcode.com/problems/binary-tree-level-order-traversal/"
},
"serialize-and-deserialize-binary-tree": {
"name": "Serialize and Deserialize Binary Tree",
"premium": False,
"url": "https://leetcode.com/problems/serialize-and-deserialize-binary-tree/"
},
"subtree-of-another-tree": {
"name": "Subtree of Another Tree",
"premium": False,
"url": "https://leetcode.com/problems/subtree-of-another-tree/"
},
"construct-binary-tree-from-preorder-and-inorder-traversal": {
"name": "Construct Binary Tree from Preorder and Inorder Traversal",
"premium": False,
"url": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/"
},
"validate-binary-search-tree": {
"name": "Validate Binary Search Tree",
"premium": False,
"url": "https://leetcode.com/problems/validate-binary-search-tree/"
},
"kth-smallest-element-in-a-bst": {
"name": "Kth Smallest Element in a BST",
"premium": False,
"url": "https://leetcode.com/problems/kth-smallest-element-in-a-bst/"
},
"lowest-common-ancestor-of-a-binary-search-tree": {
"name": "Lowest Common Ancestor of BST",
"premium": False,
"url": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/"
},
"implement-trie-prefix-tree": {
"name": "Implement Trie (Prefix Tree)",
"premium": False,
"url": "https://leetcode.com/problems/implement-trie-prefix-tree/"
},
"add-and-search-word-data-structure-design": {
"name": "Add and Search Word",
"premium": False,
"url": "https://leetcode.com/problems/add-and-search-word-data-structure-design/"
},
"word-search-ii": {
"name": "Word Search II",
"premium": False,
"url": "https://leetcode.com/problems/word-search-ii/"
}
}, "Heap": {
"merge-k-sorted-lists": {
"name": "Merge K Sorted Lists",
"premium": False,
"url": "https://leetcode.com/problems/merge-k-sorted-lists/"
},
"top-k-frequent-elements": {
"name": "Top K Frequent Elements",
"premium": False,
"url": "https://leetcode.com/problems/top-k-frequent-elements/"
},
"find-median-from-data-stream": {
"name": "Find Median from Data Stream",
"premium": False,
"url": "https://leetcode.com/problems/find-median-from-data-stream/"
}
}
},
"references": [
{
"name": "14 Patterns to Ace Any Coding Interview Question",
"url": "https://hackernoon.com/14-patterns-to-ace-any-coding-interview-question-c5bb3357f6ed"
},
{
"name": "Grind 75",
"url": "https://www.techinterviewhandbook.org/grind75"
}
]
}
def create_markdown_checklist():
num = 1
# if checklist.md does not exist, create it
if not os.path.exists("checklist.md"):
with open("checklist.md", "w") as file:
# create markdown checklist from the problems json
checklist = ""
for category in problems["problems"]:
checklist += f"## {category}\n"
for problem in problems["problems"][category]:
problem_name = problems["problems"][category][problem]["name"]
problem_url = problems["problems"][category][problem]["url"]
problem_premium = problems["problems"][category][problem]["premium"]
if problem_premium:
problem_name += " (Leetcode Premium)"
checklist += f"- [ ] {num} [{problem_name}]({problem_url})\n"
num += 1
checklist += "\n"
file.write(checklist)
def create_directories():
num = 1
# create directories for each category
for category in problems["problems"]:
category_lower = category.replace(" ", "-").lower()
category_path = f"./solutions/{category_lower}"
for problem in problems["problems"][category]:
premium = "" if not problems["problems"][category][problem]["premium"] else "+"
problem_path = f"{category_path}/{num}-{problem.replace(' ', '-').lower()}{premium}"
num += 1
# if the directory does not exist, create it
if not os.path.exists(problem_path):
os.makedirs(problem_path)
# create a markdown file for the problem if it does not exist
notes_markdown = f"{problem_path}/NOTES.md"
# if not os.path.isfile(notes_markdown):
with open(notes_markdown, "w") as file:
file.write(f"# {problems['problems'][category][problem]['name']}\n\n")
file.write(f"URL: [{problems['problems'][category][problem]['url']}]({problems['problems'][category][problem]['url']})\n\n")
if __name__ == "__main__":
create_markdown_checklist()
create_directories()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment