Added new question
This commit is contained in:
parent
b57b6f14eb
commit
fabcf449e3
@ -11,3 +11,4 @@
|
|||||||
7. [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/description/) `Blind 75` `Leetcode 150` `Striver`
|
7. [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/description/) `Blind 75` `Leetcode 150` `Striver`
|
||||||
8. [3sum](https://leetcode.com/problems/3sum/description/) `Blind 75` `Leetcode 150` `Striver`
|
8. [3sum](https://leetcode.com/problems/3sum/description/) `Blind 75` `Leetcode 150` `Striver`
|
||||||
9. [Container With Most Water](https://leetcode.com/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-interview-150) `Blind 75` `Leetcode 150`
|
9. [Container With Most Water](https://leetcode.com/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-interview-150) `Blind 75` `Leetcode 150`
|
||||||
|
10. [Merge Intervals](https://leetcode.com/problems/merge-intervals/description/) `Leetcode 150` `Striver`
|
||||||
|
53
dsa/scripts/generate_leetcode_structure.py
Normal file
53
dsa/scripts/generate_leetcode_structure.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def create_package_structure(problem_name, method_signature):
|
||||||
|
"""Creates the package structure for a LeetCode problem"""
|
||||||
|
|
||||||
|
# Convert problem name to package format (lowercase with underscores)
|
||||||
|
package_name = problem_name.lower().replace(' ', '_')
|
||||||
|
|
||||||
|
# Base package path
|
||||||
|
base_path = "dsa/src/main/java/com/hithomelabs/dsa/array"
|
||||||
|
package_path = f"{base_path}/{package_name}"
|
||||||
|
|
||||||
|
# Create package directory
|
||||||
|
os.makedirs(package_path, exist_ok=True)
|
||||||
|
|
||||||
|
# Create Solution.java
|
||||||
|
solution_content = f"""package com.hithomelabs.dsa.array.{package_name};
|
||||||
|
|
||||||
|
public class Solution implements Solvable {{
|
||||||
|
{method_signature} {{
|
||||||
|
// TODO: Implement solution
|
||||||
|
throw new UnsupportedOperationException("Not implemented yet");
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Create Solvable.java
|
||||||
|
solvable_content = f"""package com.hithomelabs.dsa.array.{package_name};
|
||||||
|
|
||||||
|
interface Solvable {{
|
||||||
|
{method_signature};
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Write files
|
||||||
|
with open(f"{package_path}/Solution.java", "w") as f:
|
||||||
|
f.write(solution_content)
|
||||||
|
|
||||||
|
with open(f"{package_path}/Solvable.java", "w") as f:
|
||||||
|
f.write(solvable_content)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Usage: python generate_leetcode_structure.py \"Problem Name\" \"method_signature\"")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
problem_name = sys.argv[1]
|
||||||
|
method_signature = sys.argv[2]
|
||||||
|
create_package_structure(problem_name, method_signature)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.hithomelabs.dsa.array.merge_intervals;
|
||||||
|
|
||||||
|
|
||||||
|
public class Solution {
|
||||||
|
public int[][] merge(int[][] intervals) {
|
||||||
|
// Implementation of the merge function
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.hithomelabs.dsa.array.merge_intervals;
|
||||||
|
|
||||||
|
interface Solvable {
|
||||||
|
int[][] solve(int[][] intervals);
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
/home/hitanshu/Projects/DSA_sheets/dsa/src/test/java/com/hithomelabs/dsa/array/best_time_to_buy_and_sell_stock/SolutionTest.java
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.hithomelabs.dsa.array.merge_intervals;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
|
||||||
|
public class SolutionTest {
|
||||||
|
@Test
|
||||||
|
void testMerge() {
|
||||||
|
Solution solution = new Solution();
|
||||||
|
|
||||||
|
// Test case from the Leetcode URL for Merge Intervals
|
||||||
|
int[][] intervals1 = {{1, 3}, {2, 6}, {8, 10}, {15, 18}};
|
||||||
|
int[][] expected1 = {{1, 6}, {8, 10}, {15, 18}};
|
||||||
|
int[][] result1 = solution.merge(intervals1);
|
||||||
|
assertArrayEquals(expected1, result1);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user