Skip to content

Commit c26169e

Browse files
committed
Add seed qns, fix minor bug in code exe
1 parent 9bd6b1d commit c26169e

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

backend/code-execution-service/src/controllers/codeExecutionControllers.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ export const executeCode = async (req: Request, res: Response) => {
7979
stdout = "";
8080
}
8181

82-
// Extract the last line as the result value
83-
// and the rest as stdout
84-
const lines = stdout.trim().split("\n");
85-
const resultValue = lines.pop() || "";
86-
stdout = lines.join("\n");
82+
let resultValue = "";
83+
if (restofResult.stderr) {
84+
resultValue = "";
85+
stdout = stdout.trim();
86+
} else {
87+
// Extract the last line as the result value and the rest as stdout only if there is no error
88+
const lines = stdout.trim().split("\n");
89+
resultValue = lines.pop() || "";
90+
stdout = lines.join("\n");
91+
}
8792

8893
return {
8994
...restofResult,

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable */
2+
13
import { exit } from "process";
24
import connectDB from "../config/db";
35
import Question from "../models/Question";
@@ -38,7 +40,7 @@ export async function seedQuestions() {
3840
{
3941
title: "Two Sum",
4042
description:
41-
"Given an array of integers `nums` and an integer `target`, 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. You can return the answer in any order.",
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.",
4244
complexity: "Easy",
4345
category: ["Arrays"],
4446
testcaseInputFileUrl: "./src/scripts/testcases/twoSumInput.txt",
@@ -67,16 +69,7 @@ export async function seedQuestions() {
6769
"Each test case consists of two lines:\n" +
6870
"- The first line contains the elements of `nums1`, a sorted array of integers.\n" +
6971
"- The second line contains the elements of `nums2`, another sorted array of integers.\n\n" +
70-
"Test cases are separated by a double newline. For example, an input file with two test cases could look like:\n" +
71-
"```\n" +
72-
"1 3\n2\n\n1 2\n3 4\n" +
73-
"```\n\n" +
74-
"### Output\n" +
75-
"For each test case, output a single line containing the median of the two sorted arrays. Results should be separated by a double newline.\n\n" +
76-
"The corresponding output file for the example above would be:\n" +
77-
"```\n" +
78-
"2.0\n\n2.5\n" +
79-
"```\n\n" +
72+
"For each test case, output a single line containing the median of the two sorted arrays.\n\n" +
8073
"### Explanation\n" +
8174
"- **Test Case 1**: `nums1 = [1, 3]` and `nums2 = [2]` have a combined sorted array `[1, 2, 3]`, with median `2.0`.\n" +
8275
"- **Test Case 2**: `nums1 = [1, 2]` and `nums2 = [3, 4]` have a combined sorted array `[1, 2, 3, 4]`, with median `2.5`.",
@@ -91,6 +84,24 @@ export async function seedQuestions() {
9184
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 List<Integer> nums1 = new ArrayList<>();\n List<Integer> nums2 = new ArrayList<>();\n boolean isNums2 = false;\n while (scanner.hasNextLine()) {\n String line = scanner.nextLine().trim();\n if (line.isEmpty()) {\n isNums2 = !isNums2;\n continue;\n }\n List<Integer> nums = isNums2 ? nums2 : nums1;\n for (String num : line.split(" ")) {\n nums.add(Integer.parseInt(num));\n }\n }\n System.out.println(solution(nums1.stream().mapToInt(i -> i).toArray(), nums2.stream().mapToInt(i -> i).toArray()));\n }\n\n // Write your code here\n public static double solution(int[] nums1, int[] nums2) {\n // Implement your solution here\n return 0.0;\n }\n}`,
9285
cTemplate: `#include <stdio.h>\n#include <stdlib.h>\n\n// Function to implement\ndouble solution(int* nums1, int nums1Size, int* nums2, int nums2Size) {\n // Implement your solution here\n return 0.0;\n}\n\n// Please do not modify the main function\nint main() {\n int nums1[100], nums2[100], n1 = 0, n2 = 0;\n char line[1000];\n while (fgets(line, sizeof(line), stdin)) {\n if (line[0] == '\\n') break;\n char* token = strtok(line, \" \");\n while (token) {\n nums1[n1++] = atoi(token);\n token = strtok(NULL, \" \");\n }\n }\n while (fgets(line, sizeof(line), stdin)) {\n if (line[0] == '\\n') break;\n char* token = strtok(line, \" \");\n while (token) {\n nums2[n2++] = atoi(token);\n token = strtok(NULL, \" \");\n }\n }\n printf(\"%.1f\\n\", solution(nums1, n1, nums2, n2));\n return 0;\n}`,
9386
},
87+
{
88+
title: "Longest Palindromic Substring",
89+
description:
90+
"Given a string `s`, return the **longest palindromic substring** in `s`.\n\n" +
91+
"For each test case, output a single line containing the longest palindromic substring in `s`.\n\n" +
92+
"### Explanation\n" +
93+
"- **Test Case 1**: For input `babad`, one of the longest palindromic substrings is `bab`.\n" +
94+
"- **Test Case 2**: For input `cbbd`, the longest palindromic substring is `bb`.",
95+
complexity: "Medium",
96+
category: ["Strings", "Dynamic Programming"],
97+
testcaseInputFileUrl:
98+
"./src/scripts/testcases/longestPalindromicSubstringInput.txt",
99+
testcaseOutputFileUrl:
100+
"./src/scripts/testcases/longestPalindromicSubstringOutput.txt",
101+
pythonTemplate: `# Please do not modify the main function\ndef main():\n\ts = input().strip()\n\tprint(solution(s))\n\n\n# Write your code here\ndef solution(s):\n\t# Implement your solution here\n\treturn ""\n\n\nif __name__ == "__main__":\n\tmain()\n`,
102+
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}`,
103+
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}`,
104+
},
94105
];
95106

96107
try {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
babad
2+
3+
cbbd
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bab
2+
3+
bb

frontend/src/contexts/CollabContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ const CollabProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
8383
for (let i = 0; i < res.data.data.length; i++) {
8484
if (!res.data.data[i].isMatch) {
8585
isMatch = false;
86+
break;
8687
}
87-
break;
8888
}
8989

9090
if (isMatch) {

0 commit comments

Comments
 (0)