Skip to content

Commit ffd87c8

Browse files
committed
More qns
1 parent c26169e commit ffd87c8

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

backend/question-service/src/scripts/seed.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ export async function seedQuestions() {
4040
{
4141
title: "Two Sum",
4242
description:
43-
"Given an array of integers `nums` (line 1) and an integer `target` (line 2), return indices of the two numbers in a list such that they add up to `target`. You may assume that each input would have **exactly one solution**, and you may not use the same element twice. The list should be returned in sorted order.",
43+
"Given an array of integers `nums` and an integer `target`, find the indices of the two numbers in `nums` that add up to `target`. You may assume that each input has **exactly one solution**, and you cannot use the same element twice. Return the indices as a list sorted in ascending order.",
4444
complexity: "Easy",
4545
category: ["Arrays"],
4646
testcaseInputFileUrl: "./src/scripts/testcases/twoSumInput.txt",
4747
testcaseOutputFileUrl: "./src/scripts/testcases/twoSumOutput.txt",
48-
pythonTemplate: `# Please do not modify the main function\ndef main():\n\tprint(" ".join(solution()))\n\n\n# Write your code here\ndef solution():\n\treturn []\n\n\nif __name__ == "__main__":\n\tmain()\n`,
49-
javaTemplate: `public class Main {\n // Please do not modify the main function\n public static void main(String[] args) {\n System.out.println(String.join(" ", solution()));\n }\n\n // Write your code here\n public static String[] solution() {\n return new String[]{};\n }\n}`,
50-
cTemplate: `#include <stdio.h>\n\n// Function to implement\nconst char** solution() {\n static const char* result[] = {NULL}; // Placeholder\n return result;\n}\n\n// Please do not modify the main function\nint main() {\n const char** result = solution();\n for (int i = 0; result[i] != NULL; i++) {\n printf("%s ", result[i]);\n }\n printf("\\n");\n return 0;\n}`,
48+
pythonTemplate: `# Please do not modify the main function\ndef main():\n\tnums = list(map(int, input().split()))\n\ttarget = int(input().strip())\n\tprint(" ".join(map(str, solution(nums, target))))\n\n\n# Write your code here\ndef solution(nums, target):\n\t# Implement your solution here\n\treturn []\n\n\nif __name__ == "__main__":\n\tmain()\n`,
49+
javaTemplate: `import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Main {\n // Please do not modify the main function\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int[] nums = new int[n];\n for (int i = 0; i < n; i++) {\n nums[i] = scanner.nextInt();\n }\n int target = scanner.nextInt();\n System.out.println(Arrays.toString(solution(nums, target)));\n }\n\n // Write your code here\n public static int[] solution(int[] nums, int target) {\n // Implement your solution here\n return new int[]{};\n }\n}`,
50+
cTemplate: `#include <stdio.h>\n#include <stdlib.h>\n\n// Function to implement\nint* solution(int* nums, int numsSize, int target, int* returnSize) {\n *returnSize = 2; // Adjust as needed\n int* result = (int*)malloc(2 * sizeof(int));\n // Implement your solution here\n result[0] = -1; // Placeholder\n result[1] = -1; // Placeholder\n return result;\n}\n\n// Please do not modify the main function\nint main() {\n int n, target;\n scanf("%d", &n);\n int nums[n];\n for (int i = 0; i < n; i++) {\n scanf("%d", &nums[i]);\n }\n scanf("%d", &target);\n int returnSize;\n int* result = solution(nums, n, target, &returnSize);\n for (int i = 0; i < returnSize; i++) {\n printf("%d ", result[i]);\n }\n printf("\\n");\n free(result);\n return 0;\n}`,
5151
},
5252
{
5353
title: "Longest Substring Without Repeating Characters",
@@ -102,6 +102,34 @@ export async function seedQuestions() {
102102
javaTemplate: `import java.util.Scanner;\n\npublic class Main {\n // Please do not modify the main function\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String s = scanner.nextLine().trim();\n System.out.println(solution(s));\n }\n\n // Write your code here\n public static String solution(String s) {\n // Implement your solution here\n return "";\n }\n}`,
103103
cTemplate: `#include <stdio.h>\n#include <string.h>\n\n// Function to implement\nconst char* solution(const char* s) {\n // Implement your solution here\n return "";\n}\n\n// Please do not modify the main function\nint main() {\n char s[1000];\n fgets(s, sizeof(s), stdin);\n s[strcspn(s, "\\n")] = 0; // Remove newline\n printf("%s\\n", solution(s));\n return 0;\n}`,
104104
},
105+
{
106+
title: "ZigZag Conversion",
107+
description:
108+
"The string `PAYPALISHIRING` is written in a zigzag pattern on a given number of rows like this:\n\n" +
109+
"```\n" +
110+
"P A H N\n" +
111+
"A P L S I I G\n" +
112+
"Y I R\n" +
113+
"```\n\n" +
114+
"And then read line by line: `PAHNAPLSIIGYIR`.\n\n" +
115+
"Write the code that will take a string and make this conversion given a number of rows.\n\n" +
116+
"### Input\n" +
117+
"Each test case consists of two lines:\n" +
118+
"- The first line contains the string `s`.\n" +
119+
"- The second line contains an integer `numRows`, representing the number of rows for the zigzag pattern.\n\n" +
120+
"### Output\n" +
121+
"For each test case, output the zigzag converted string as a single line.\n\n" +
122+
"### Explanation\n" +
123+
"- **Test Case 1**: `PAYPALISHIRING` with `numRows = 3` converts to `PAHNAPLSIIGYIR`.\n" +
124+
"- **Test Case 2**: `PAYPALISHIRING` with `numRows = 4` converts to `HLOEL`.",
125+
complexity: "Medium",
126+
category: ["Strings"],
127+
testcaseInputFileUrl: "./src/scripts/testcases/zigzagInput.txt",
128+
testcaseOutputFileUrl: "./src/scripts/testcases/zigzagOutput.txt",
129+
pythonTemplate: `# Please do not modify the main function\ndef main():\n\timport sys\n\tinput = sys.stdin.read().strip().split("\\n\\n")\n\tfor case in input:\n\t\tlines = case.split("\\n")\n\t\ts = lines[0]\n\t\tnumRows = int(lines[1])\n\t\tprint(solution(s, numRows))\n\n\n# Write your code here\ndef solution(s, numRows):\n\t# Implement your solution here\n\treturn ""\n\n\nif __name__ == "__main__":\n\tmain()\n`,
130+
javaTemplate: `import java.util.*;\n\npublic class Main {\n // Please do not modify the main function\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String s = scanner.nextLine().trim();\n int numRows = Integer.parseInt(scanner.nextLine().trim());\n System.out.println(solution(s, numRows));\n }\n\n // Write your code here\n public static String solution(String s, int numRows) {\n // Implement your solution here\n return "";\n }\n}`,
131+
cTemplate: `#include <stdio.h>\n#include <string.h>\n\n// Function to implement\nconst char* solution(const char* s, int numRows) {\n // Implement your solution here\n return "";\n}\n\n// Please do not modify the main function\nint main() {\n char s[1000];\n int numRows;\n fgets(s, sizeof(s), stdin);\n s[strcspn(s, "\\n")] = 0; // Remove newline\n scanf("%d", &numRows);\n printf("%s\\n", solution(s, numRows));\n return 0;\n}`,
132+
},
105133
];
106134

107135
try {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Please do not modify the main function
2+
def main():
3+
nums = list(map(int, input().split()))
4+
target = int(input().strip())
5+
print(" ".join(map(str, solution(nums, target))))
6+
7+
8+
# Write your code here
9+
def solution(nums, target):
10+
# Implement your solution here
11+
num_map = {}
12+
for i, num in enumerate(nums):
13+
complement = target - num
14+
if complement in num_map:
15+
return sorted([num_map[complement], i])
16+
num_map[num] = i
17+
return []
18+
19+
20+
if __name__ == "__main__":
21+
main()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Please do not modify the main function
2+
def main():
3+
import sys
4+
5+
input = sys.stdin.read().strip().split("\n\n")
6+
for case in input:
7+
lines = case.split("\n")
8+
s = lines[0]
9+
numRows = int(lines[1])
10+
print(solution(s, numRows))
11+
12+
13+
# Write your code here
14+
def solution(s, numRows):
15+
if numRows == 1 or numRows >= len(s):
16+
return s
17+
18+
rows = [""] * numRows
19+
current_row = 0
20+
going_down = False
21+
22+
for char in s:
23+
rows[current_row] += char
24+
if current_row == 0 or current_row == numRows - 1:
25+
going_down = not going_down
26+
current_row += 1 if going_down else -1
27+
return "".join(rows)
28+
29+
30+
if __name__ == "__main__":
31+
main()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PAYPALISHIRING
2+
3
3+
4+
PAYPALISHIRING
5+
4
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PAHNAPLSIIGYIR
2+
3+
PINALSIGYAHRPI

0 commit comments

Comments
 (0)