-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.sql
More file actions
168 lines (145 loc) · 5.1 KB
/
data.sql
File metadata and controls
168 lines (145 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
-- Insert Two Sum problem
INSERT INTO problems (
id,
title,
difficulty,
category,
description,
constraints,
starter_code_js,
starter_code_java,
starter_code_cpp,
starter_code_py,
time_limit,
memory_limit,
created_at,
updated_at,
sample_input,
sample_output
) VALUES (
'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
'Two Sum',
'Easy',
'Array',
'Given an array of integers nums and an integer target, return indices of the two numbers 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.',
'2 <= nums.length <= 10^4
-10^9 <= nums[i] <= 10^9
-10^9 <= target <= 10^9
Only one valid answer exists',
'function twoSum(nums, target) {
// Your code here
return [];
}
const input = JSON.parse(require("fs").readFileSync(0, "utf8"));
const result = twoSum(input.nums, input.target);
console.log("[" + result.join(",") + "]");',
'import java.util.*;
import java.util.regex.*;
public class Main {
public static int[] twoSum(int[] nums, int target) {
// Your code here
return new int[]{};
}
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
while (sc.hasNextLine()) {
sb.append(sc.nextLine());
}
String input = sb.toString();
// Parse JSON manually
Pattern numsPattern = Pattern.compile("\\\"nums\\\":\\\\s*\\\\[([^\\\\]]+)\\\\]");
Pattern targetPattern = Pattern.compile("\\\"target\\\":\\\\s*(-?\\\\d+)");
Matcher numsMatcher = numsPattern.matcher(input);
Matcher targetMatcher = targetPattern.matcher(input);
if (numsMatcher.find() && targetMatcher.find()) {
String numsStr = numsMatcher.group(1);
String[] numsArray = numsStr.split(",");
int[] nums = new int[numsArray.length];
for (int i = 0; i < numsArray.length; i++) {
nums[i] = Integer.parseInt(numsArray[i].trim());
}
int target = Integer.parseInt(targetMatcher.group(1));
int[] result = twoSum(nums, target);
System.out.print("[");
for (int i = 0; i < result.length; i++) {
System.out.print(result[i]);
if (i < result.length - 1) {
System.out.print(",");
}
}
System.out.println("]");
}
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}',
'#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
vector<int> twoSum(vector<int>& nums, int target) {
// Your code here
return {};
}
int main() {
string input;
getline(cin, input);
// Find nums array
size_t numsStart = input.find("[");
size_t numsEnd = input.find("]");
string numsStr = input.substr(numsStart + 1, numsEnd - numsStart - 1);
// Parse nums array
vector<int> nums;
stringstream ss(numsStr);
string token;
while (getline(ss, token, '','')) {
// Remove whitespace
token.erase(0, token.find_first_not_of(" \\t"));
token.erase(token.find_last_not_of(" \\t") + 1);
nums.push_back(stoi(token));
}
// Find target
size_t targetPos = input.find("\"target\":");
size_t targetStart = input.find(":", targetPos) + 1;
size_t targetEnd = input.find_first_of(",}", targetStart);
string targetStr = input.substr(targetStart, targetEnd - targetStart);
// Remove whitespace from target
targetStr.erase(0, targetStr.find_first_not_of(" \\t"));
targetStr.erase(targetStr.find_last_not_of(" \\t") + 1);
int target = stoi(targetStr);
vector<int> result = twoSum(nums, target);
cout << "[";
for (int i = 0; i < result.size(); ++i) {
cout << result[i];
if (i != result.size() - 1) cout << ",";
}
cout << "]" << endl;
return 0;
}',
'import sys, json
def twoSum(nums, target):
# Your code here
return []
data = json.load(sys.stdin)
result = twoSum(data["nums"], data["target"])
print("[" + ",".join(map(str, result)) + "]")',
1000,
128,
now(),
now(),
'{"nums": [2,7,11,15], "target": 9}',
'[0,1]'
);
-- Insert test cases for Two Sum
INSERT INTO test_cases (problem_id, input, expected_output, is_hidden) VALUES
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '{"nums": [2,7,11,15], "target": 9}', '[0,1]', false),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '{"nums": [3,2,4], "target": 6}', '[1,2]', false),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '{"nums": [3,3], "target": 6}', '[0,1]', false),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '{"nums": [1,5,3,7,9,2], "target": 12}', '[1,3]', true),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '{"nums": [-1,-2,-3,-4,-5], "target": -8}', '[2,4]', true);