This is a personal project to practice coding and writing tests. The provided shell script helps create a structured layout for solving coding problems and writing corresponding unit tests. Additionally, a NodeJS sub-project is included to automatically generate content for the README and test files using ChatGPT.
create_leetcode_structure.sh
The shell script (create_leetcode_structure.sh) is used to create a directory structure for coding problems and their tests. It ensures that each problem has its own directory with a Java file for the solution, a corresponding test file, and a README file.
bulk_create_leetcode_structure.sh
The shell script (bulk_create_leetcode_structure.sh) automates the execution of create_leetcode_structure.sh for multiple questions listed in a JSON file (questions.json). It also installs jq if it's not already installed.
generate-content.js
The NodeJS script (generate-content.js) uses the ChatGPT API to insert data into the README and test files for each question. It reads the questions from the questions.json file and generates comprehensive descriptions and test cases.
create_leetcode_structure.sh
To use the script, run it with the required arguments:
./create_leetcode_structure.sh <QuestionNumber> <QuestionTitle> <Topic>
./create_leetcode_structure.sh 1 TwoSum array_string
This command will:
- Create the necessary directories for the problem and test.
- Generate a Java file for the problem (TwoSum.java) in the appropriate directory.
- Generate a corresponding test file (TwoSumTests.java).
- Create a README.md file in the problem's directory.
bulk_create_leetcode_structure.sh
To automate the creation of the structure for multiple questions:
./bulk_create_leetcode_structure.sh
This script reads the list of questions from the questions.json file and runs create_leetcode_structure.sh for each one.
generate-content.js
To use the NodeJS script for generating content:
- Set your ChatGPT API key in the terminal:
export CHATGPT_API_KEY=your_api_key_here
Run the script:
node generate-content.js
This script will generate content for the README and test files for each question listed in the questions.json file.
The project follows a specific directory structure to organize the problems and their tests. Here is an example of the structure after running the scripts:
.
├── src
│ ├── main
│ │ └── java
│ │ └── leetcode
│ │ ├── array_string
│ │ │ └── q1
│ │ │ ├── TwoSum.java
│ │ │ └── README.md
│ │ └── prims_algorithm
│ │ └── q1135
│ │ ├── ConnectingCitiesMinCost.java
│ │ └── README.md
│ └── test
│ └── java
│ └── leetcode
│ ├── array_string
│ │ └── q1
│ │ └── TwoSumTests.java
│ └── prims_algorithm
│ └── q1135
│ └── ConnectingCitiesMinCostTests.java
├── leetcode-chatgpt
│ ├── generate-content.js
│ ├── package.json
│ └── .env
├── questions.json
├── run_leetcode_structure.sh
└── create_leetcode_structure.sh
- src/main/java/leetcode//q/.java: Java file containing the solution for the problem.
- src/test/java/leetcode//q/Tests.java: Java file containing the unit tests for the problem.
- src/main/java/leetcode//q/README.md: README file specific to the problem, to provide additional details or documentation.
- Ensure that the scripts (create_leetcode_structure.sh and bulk_create_leetcode_structure.sh) are executable. You can make them executable by running:
chmod +x create_leetcode_structure.sh run_leetcode_structure.sh
-
Make sure you have jq installed. The run_leetcode_structure.sh script will attempt to install it if it's not already available.
-
Set your ChatGPT API key before running the NodeJS script to generate content:
This setup provides a comprehensive structure and automation for practicing coding problems, writing tests, and generating necessary documentation using ChatGPT.
- ✅ Question #347 (Medium) - Top K Frequent Elements
- Question #692 (Medium) - Top K Frequent Words
- Question #451 (Medium) - Sort Characters By Frequency
- Question #973 (Medium) - K Closest Points to Origin
- Question #1167 (Medium) - Minimum Cost to Connect Sticks
- Question #215 (Medium) - Kth Largest Element in an Array
- Question #378 (Medium) - Kth Smallest Element in a Sorted Matrix
- Question #846 (Medium) - Hand of Straights
- Question #373 (Medium) - Find K Pairs with Smallest Sums
- Question #759 (Medium) - Employee Free Time
- ✅ Question #34 (Medium) - Find First and Last Position of Element in Sorted Array
- ✅ Question #658 (Medium) - Find K Closest Elements
- ✅ Question #912 (Medium) - Sort an Array
- ✅ Question #162 (Medium) - Find Peak Element
- Question #743 (Medium) - Network Delay Time
- Question #787 (Medium) - Cheapest Flights Within K Stops
- Question #1631 (Medium) - Path With Minimum Effort
- ✅ Question #1584 (Medium) - Min Cost to Connect All Points
- ✅ Question #1135 (Medium) - Connecting Cities With Minimum Cost
- Question #684 (Medium) - Redundant Connection
- Question #721 (Medium) - Accounts Merge
- Question #952 (Hard) - Largest Component Size by Common Factor
- Question #1202 (Medium) - Smallest String With Swaps
- Question #1584 (Medium) - Min Cost to Connect All Points
- Question #1135 (Medium) - Connecting Cities With Minimum Cost
- Question #1168 (Medium) - Optimize Water Distribution in a Village
- Question #1489 (Hard) - Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
- Question #1584 (Medium) - Min Cost to Connect All Points
- Question #1135 (Medium) - Connecting Cities With Minimum Cost
- Question #103 (Medium) - Binary Tree Zigzag Level Order Traversal
- Question #105 (Medium) - Construct Binary Tree from Preorder and Inorder Traversal
- Question #114 (Medium) - Flatten Binary Tree to Linked List
- Question #144 (Medium) - Binary Tree Preorder Traversal
- Question #199 (Medium) - Binary Tree Right Side View
- Question #222 (Medium) - Count Complete Tree Nodes
- Question #230 (Medium) - Kth Smallest Element in a BST
- Question #236 (Medium) - Lowest Common Ancestor of a Binary Tree
- Question #297 (Hard) - Serialize and Deserialize Binary Tree
- Question #337 (Medium) - House Robber III
- Question #508 (Medium) - Most Frequent Subtree Sum
- Question #513 (Medium) - Find Bottom Left Tree Value
- Question #515 (Medium) - Find Largest Value in Each Tree Row
- Question #662 (Medium) - Maximum Width of Binary Tree
- Question #958 (Medium) - Check Completeness of a Binary Tree
- Question #39 (Medium) - Combination Sum
- Question #46 (Medium) - Permutations
- Question #78 (Medium) - Subsets
- Question #90 (Medium) - Subsets II
- Question #131 (Medium) - Palindrome Partitioning
- Question #212 (Hard) - Word Search II
- Question #216 (Medium) - Combination Sum III
- Question #306 (Medium) - Additive Number
- Question #491 (Medium) - Increasing Subsequences
- Question #784 (Medium) - Letter Case Permutation
- Question #70 (Easy) - Climbing Stairs
- Question #91 (Medium) - Decode Ways
- Question #198 (Medium) - House Robber
- Question #300 (Medium) - Longest Increasing Subsequence
- Question #322 (Medium) - Coin Change
- Question #416 (Medium) - Partition Equal Subset Sum
- Question #494 (Medium) - Target Sum
- Question #152 (Medium) - Maximum Product Subarray
- ✅ Question #22 (Medium) - Generate Parentheses
- Question #44 (Hard) - Wildcard Matching
- Question #93 (Medium) - Restore IP Addresses
- Question #131 (Medium) - Palindrome Partitioning
- Question #301 (Hard) - Remove Invalid Parentheses
- ✅ Question #88 (Easy) - Merge Sorted Array
- Question #27 (Easy) - Remove Element
- Question #26 (Easy) - Remove Duplicates from Sorted Array
- Question #80 (Medium) - Remove Duplicates from Sorted Array II
- Question #169 (Easy) - Majority Element
- Question #189 (Medium) - Rotate Array
- Question #121 (Easy) - Best Time to Buy and Sell Stock
- Question #122 (Medium) - Best Time to Buy and Sell Stock II
- Question #55 (Medium) - Jump Game
- Question #45 (Medium) - Jump Game II
- Question #274 (Medium) - H-Index
- Question #380 (Medium) - Insert Delete GetRandom O(1)
- ✅ Question #238 (Medium) - Product of Array Except Self
- Question #134 (Medium) - Gas Station
- Question #135 (Hard) - Candy
- Question #42 (Hard) - Trapping Rain Water
- Question #13 (Easy) - Roman to Integer
- Question #12 (Medium) - Integer to Roman
- Question #58 (Easy) - Length of Last Word
- Question #14 (Easy) - Longest Common Prefix
- Question #125 (Easy) - Valid Palindrome
- Question #392 (Easy) - Is Subsequence
- Question #167 (Medium) - Two Sum II - Input Array Is Sorted
- Question #11 (Medium) - Container With Most Water
- Question #15 (Medium) - 3Sum
- Question #209 (Medium) - Minimum Size Subarray Sum
- Question #3 (Medium) - Longest Substring Without Repeating Characters
- Question #30 (Hard) - Substring with Concatenation of All Words
- Question #76 (Hard) - Minimum Window Substring
- Question #438 (Medium) - Find All Anagrams in a String
- Question #567 (Medium) - Permutation in String
- ✅ Question #36 (Medium) - Valid Sudoku
- ✅ Question #54 (Medium) - Spiral Matrix
- ✅ Question #48 (Medium) - Rotate Image
- Question #73 (Medium) - Set Matrix Zeroes
- Question #289 (Medium) - Game of Life
- Question #383 (Easy) - Ransom Note
- Question #205 (Easy) - Isomorphic Strings
- Question #290 (Easy) - Word Pattern
- Question #242 (Easy) - Valid Anagram
- Question #49 (Medium) - Group Anagrams
- Question #1 (Easy) - Two Sum
- Question #202 (Easy) - Happy Number
- Question #219 (Easy) - Contains Duplicate II
- Question #128 (Medium) - Longest Consecutive Sequence
- Question #228 (Easy) - Summary Ranges
- Question #56 (Medium) - Merge Intervals
- Question #57 (Medium) - Insert Interval
- Question #452 (Medium) - Minimum Number of Arrows to Burst Balloons
- Question #435 (Medium) - Non-overlapping Intervals
- Question #20 (Easy) - Valid Parentheses
- Question #71 (Medium) - Simplify Path
- Question #155 (Medium) - Min Stack
- Question #150 (Medium) - Evaluate Reverse Polish Notation
- Question #224 (Hard) - Basic Calculator
- Question #141 (Easy) - Linked List Cycle
- ✅ Question #2 (Medium) - Add Two Numbers
- Question #21 (Easy) - Merge Two Sorted Lists
- Question #138 (Medium) - Copy List with Random Pointer
- Question #92 (Medium) - Reverse Linked List II
- Question #25 (Hard) - Reverse Nodes in k-Group
- ✅ Question #19 (Medium) - Remove Nth Node From End of List
- ✅ Question #82 (Medium) - Remove Duplicates from Sorted List II
- Question #61 (Medium) - Rotate List
- Question #86 (Medium) - Partition List
- Question #208 (Medium) - Implement Trie (Prefix Tree)
- Question #648 (Medium) - Search Suggestions System
- Question #739 (Medium) - Daily Temperatures
- Question #901 (Medium) - Online Stock Span
- Question #207 (Medium) - Course Schedule
- Question #210 (Medium) - Course Schedule II
- Question #133 (Medium) - Clone Graph
- Question #417 (Medium) - Pacific Atlantic Water Flow
- ✅ Question #72 (Medium) - Edit Distance
- ✅ Question #146 (Medium) - LRU Cache
- ✅ Question #200 (Medium) - Number of Islands
- ✅ Question #938 (Easy) - Range Sum of BST