Skip to content

Commit 853ecff

Browse files
committed
More questions and answers
1 parent ead61df commit 853ecff

File tree

8 files changed

+125
-1
lines changed

8 files changed

+125
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export async function seedQuestions() {
162162
'- **Test Case 1**: `a = "11"` and `b = "1"`, the sum is `"100"`.\n' +
163163
'- **Test Case 2**: `a = "1010"` and `b = "1011"`, the sum is `"10101"`.',
164164
complexity: "Easy",
165-
category: ["Data Structures", "Strings"],
165+
category: ["Data Structures", "Strings", "Bit Manipulation"],
166166
testcaseInputFileUrl: "./src/scripts/testcases/addBinaryInput.txt",
167167
testcaseOutputFileUrl: "./src/scripts/testcases/addBinaryOutput.txt",
168168
pythonTemplate: `# Please do not modify the main function\ndef main():\n\ta = input().strip()\n\tb = input().strip()\n\tprint(solution(a, b))\n\n\n# Write your code here\ndef solution(a, b):\n\t# Implement your solution here\n\treturn ""\n\n\nif __name__ == "__main__":\n\tmain()\n`,
@@ -190,6 +190,42 @@ export async function seedQuestions() {
190190
javaTemplate: `import java.util.*;\n\nclass TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\tTreeNode(int val) { this.val = val; }\n\tTreeNode(int val, TreeNode left, TreeNode right) {\n\t\tthis.val = val;\n\t\tthis.left = left;\n\t\tthis.right = right;\n\t}\n}\n\npublic class Main {\n\t// Please do not modify the main function\n\tpublic static void main(String[] args) {\n\t\tTreeNode root = deserialize(new Scanner(System.in).nextLine().trim());\n\t\tSystem.out.println(solution(root));\n\t}\n\n\t// Write your code here\n\tpublic static int solution(TreeNode root) {\n\t\t// Implement your solution here\n\t\treturn 0;\n\t}\n\n\t// Helper function to deserialize input\n\tpublic static TreeNode deserialize(String data) {\n\t\t// Implement a function to build a tree from input\n\t\treturn null;\n\t}\n}`,
191191
cTemplate: `#include <stdio.h>\n#include <stdlib.h>\n\nstruct TreeNode {\n\tint val;\n\tstruct TreeNode *left;\n\tstruct TreeNode *right;\n};\n\n// Function to implement\nint solution(struct TreeNode* root) {\n\t// Implement your solution here\n\treturn 0;\n}\n\n// Please do not modify the main function\nint main() {\n\t// Implement tree deserialization if needed\n\treturn 0;\n}`,
192192
},
193+
{
194+
title: "Jump Game",
195+
description:
196+
"Given an array of non-negative integers `nums`, where each element represents the maximum jump length from that position, determine if you can reach the last index.\n\n" +
197+
"Return string `true` if you can reach the last index, or string `false` otherwise.\n\n" +
198+
"### Explanation\n" +
199+
"- **Test Case 1**: Given `nums = [2, 3, 1, 1, 4]`, you can jump from index 0 to index 1, then to the last index, so the result is `true`.\n" +
200+
"- **Test Case 2**: Given `nums = [3, 2, 1, 0, 4]`, no matter what, you will always end up at index 3 (0), so the result is `false`.",
201+
complexity: "Medium",
202+
category: ["Algorithms", "Arrays", "Dynamic Programming"],
203+
testcaseInputFileUrl: "./src/scripts/testcases/jumpGameInput.txt",
204+
testcaseOutputFileUrl: "./src/scripts/testcases/jumpGameOutput.txt",
205+
pythonTemplate: `# Please do not modify the main function\ndef main():\n\tnums = list(map(int, input().strip().split()))\n\tprint(solution(nums))\n\n\n# Write your code here\ndef solution(nums):\n\t# Implement your solution here\n\treturn False\n\n\nif __name__ == "__main__":\n\tmain()\n`,
206+
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> numsList = new ArrayList<>();\n while (scanner.hasNextInt()) {\n numsList.add(scanner.nextInt());\n }\n int[] nums = numsList.stream().mapToInt(i -> i).toArray();\n System.out.println(solution(nums));\n }\n\n // Write your code here\n public static boolean solution(int[] nums) {\n // Implement your solution here\n return false;\n }\n}`,
207+
cTemplate: `#include <stdio.h>\n#include <stdbool.h>\n\n// Function to implement\nbool solution(int* nums, int numsSize) {\n // Implement your solution here\n return false;\n}\n\n// Please do not modify the main function\nint main() {\n int nums[1000], numsSize = 0, x;\n while (scanf("%d", &x) == 1) {\n nums[numsSize++] = x;\n }\n printf(solution(nums, numsSize) ? "true\\n" : "false\\n");\n return 0;\n}`,
208+
},
209+
{
210+
title: "Binary Tree Inorder Traversal",
211+
description:
212+
"Given the `root` of a binary tree, return the **inorder traversal** of its nodes' values.\n\n" +
213+
"Inorder traversal is defined as visiting the left subtree, then the current node, and finally the right subtree.\n\n" +
214+
"### Explanation\n" +
215+
"- ![image](https://assets.leetcode.com/uploads/2024/08/29/screenshot-2024-08-29-202743.png)\n" +
216+
"- **Test Case 1**: Given the tree `[1, null, 2, 3]`, the inorder traversal is `[1, 3, 2]`.\n\n\n" +
217+
"- ![image](https://assets.leetcode.com/uploads/2024/08/29/tree_2.png)\n" +
218+
"- **Test Case 2**: Given the tree `[1, 2, 3, 4, 5, null, 8 ,null, null, 6, 7, 9]`, the inorder traversal is `[4, 2, 6, 5, 7, 1, 3, 9, 8]`.",
219+
complexity: "Easy",
220+
category: ["Tree"],
221+
testcaseInputFileUrl:
222+
"./src/scripts/testcases/binaryTreeInorderTraversalInput.txt",
223+
testcaseOutputFileUrl:
224+
"./src/scripts/testcases/binaryTreeInorderTraversalOutput.txt",
225+
pythonTemplate: `# Definition for a binary tree node.\nclass TreeNode:\n\tdef __init__(self, val=0, left=None, right=None):\n\t\tself.val = val\n\t\tself.left = left\n\t\tself.right = right\n\n# Please do not modify the main function\ndef main():\n\troot = deserialize(input().strip())\n\tprint(" ".join(map(str, solution(root))))\n\n\n# Write your code here\ndef solution(root):\n\t# Implement your solution here\n\treturn []\n\n\n# Helper function to deserialize input\n\ndef deserialize(data):\n\t# Implement a function to build a tree from input\n\treturn None\n\n\nif __name__ == "__main__":\n\tmain()\n`,
226+
javaTemplate: `import java.util.*;\n\nclass TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\tTreeNode(int val) { this.val = val; }\n\tTreeNode(int val, TreeNode left, TreeNode right) {\n\t\tthis.val = val;\n\t\tthis.left = left;\n\t\tthis.right = right;\n\t}\n}\n\npublic class Main {\n\t// Please do not modify the main function\n\tpublic static void main(String[] args) {\n\t\tTreeNode root = deserialize(new Scanner(System.in).nextLine().trim());\n\t\tList<Integer> result = solution(root);\n\t\tSystem.out.println(String.join(" ", result.stream().map(String::valueOf).toArray(String[]::new)));\n\t}\n\n\t// Write your code here\n\tpublic static List<Integer> solution(TreeNode root) {\n\t\t// Implement your solution here\n\t\treturn new ArrayList<>();\n\t}\n\n\t// Helper function to deserialize input\n\tpublic static TreeNode deserialize(String data) {\n\t\t// Implement a function to build a tree from input\n\t\treturn null;\n\t}\n}`,
227+
cTemplate: `#include <stdio.h>\n#include <stdlib.h>\n\nstruct TreeNode {\n\tint val;\n\tstruct TreeNode *left;\n\tstruct TreeNode *right;\n};\n\n// Function to implement\nint* solution(struct TreeNode* root, int* returnSize) {\n\t// Implement your solution here\n\t*returnSize = 0;\n\treturn NULL;\n}\n\n// Please do not modify the main function\nint main() {\n\t// Implement tree deserialization if needed\n\treturn 0;\n}`,
228+
},
193229
];
194230

195231
try {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Definition for a binary tree node.
2+
class TreeNode:
3+
def __init__(self, val=0, left=None, right=None):
4+
self.val = val
5+
self.left = left
6+
self.right = right
7+
8+
9+
# Please do not modify the main function
10+
def main():
11+
root = deserialize(input().strip())
12+
print(solution(root))
13+
14+
15+
# Write your code here
16+
def solution(root):
17+
result = []
18+
19+
def inorder(node):
20+
if not node:
21+
return
22+
inorder(node.left)
23+
result.append(node.val)
24+
inorder(node.right)
25+
26+
inorder(root)
27+
return result
28+
29+
30+
# Helper function to deserialize input in space-separated format
31+
def deserialize(data):
32+
if not data:
33+
return None
34+
35+
nodes = data.split()
36+
root = TreeNode(int(nodes[0]))
37+
queue = [root]
38+
i = 1
39+
40+
while queue and i < len(nodes):
41+
node = queue.pop(0)
42+
if nodes[i] != "null":
43+
node.left = TreeNode(int(nodes[i]))
44+
queue.append(node.left)
45+
i += 1
46+
if i < len(nodes) and nodes[i] != "null":
47+
node.right = TreeNode(int(nodes[i]))
48+
queue.append(node.right)
49+
i += 1
50+
51+
return root
52+
53+
54+
if __name__ == "__main__":
55+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 null 2 3
2+
3+
1 2 3 4 5 null 8 null null 6 7 9
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 3 2
2+
3+
4 2 6 5 7 1 3 9 8
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Please do not modify the main function
2+
def main():
3+
nums = list(map(int, input().strip().split()))
4+
print(solution(nums))
5+
6+
7+
# Write your code here
8+
def solution(nums):
9+
max_reach = 0
10+
for i in range(len(nums)):
11+
if i > max_reach:
12+
return "false"
13+
max_reach = max(max_reach, i + nums[i])
14+
if max_reach >= len(nums) - 1:
15+
return "true"
16+
return "false"
17+
18+
19+
if __name__ == "__main__":
20+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2 3 1 1 4
2+
3+
3 2 1 0 4
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
true
2+
3+
false

frontend/src/contexts/CollabContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const CollabProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
7777
language: matchCriteria?.language.toLowerCase(),
7878
});
7979

80+
console.log(res.data.data);
8081
setCompilerResult(res.data.data);
8182

8283
let isMatch = true;

0 commit comments

Comments
 (0)