-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem.json
74 lines (74 loc) · 6.2 KB
/
problem.json
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
{
"QuestionNo": 1,
"title": "Word Search",
"description": "Given an m x n grid of characters board and a string word, return true if the word exists in the grid.",
"difficulty": "Medium",
"tags": [
"backtracking",
"matrix"
],
"examples": [
{
"input": "board = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']],\nword = 'ABCCED'",
"output": "true",
"explanation": "The word 'ABCCED' can be constructed from adjacent letters on the board."
},
{
"input": "board = [['A', 'B', 'C', 'E'], ['S', 'S', 'C', 'S'], ['A', 'D', 'Y', 'E']],\nword = 'SEE'",
"output": "false",
"explanation": "The word 'SEE' cannot be constructed from adjacent letters on the board."
}
],
"constraints": "1 <= board.length,\nboard[i].length <= 200,\nword.length <= 10^3",
"testCases": [
{
"case": 1,
"input": {
"cpp": "vector<vector<char>> board = {{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}};\nstring word = \"ABCCED\";",
"java": "char[][] board = {{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}};\nString word = \"ABCCED\";",
"js": "const board = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']]\n const word = \"ABCCED\";",
"python": "board = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']]\nword = \"ABCCED\""
},
"output": true
},
{
"case": 2,
"input": {
"cpp": "vector<vector<char>> board = {{'A', 'B', 'C', 'E'}, {'S', 'S', 'C', 'S'}, {'A', 'D', 'Y', 'E'}};\nstring word = \"SEE\";",
"java": "char[][] board = {{'A', 'B', 'C', 'E'}, {'S', 'S', 'C', 'S'}, {'A', 'D', 'Y', 'E'}};\nString word = \"SEE\";",
"js": "const board = [['A', 'B', 'C', 'E'], ['S', 'S', 'C', 'S'], ['A', 'D', 'Y', 'E']];\nconst word = \"SEE\";",
"python": "board = [['A', 'B', 'C', 'E'], ['S', 'S', 'C', 'S'], ['A', 'D', 'Y', 'E']]\nword = \"SEE\""
},
"output": false
},
{
"case": 3,
"input": {
"cpp": "vector<vector<vector<char>>> boards = {{{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}}, {{'A', 'B', 'C', 'E'}, {'S', 'S', 'C', 'S'}, {'A', 'D', 'Y', 'E'}}, {{'X', 'Y', 'Z', 'W'}, {'Q', 'P', 'O', 'N'}, {'A', 'B', 'C', 'D'}}}; vector<string> words = {\"ABCCED\", \"SEE\", \"XYZ\"}; vector<bool> expectedOutputs = {true, false, true};",
"java": "List<char[][]> boards = List.of(new char[][] {{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}}, new char[][] {{'A', 'B', 'C', 'E'}, {'S', 'S', 'C', 'S'}, {'A', 'D', 'Y', 'E'}}, new char[][] {{'X', 'Y', 'Z', 'W'}, {'Q', 'P', 'O', 'N'}, {'A', 'B', 'C', 'D'}}); List<String> words = List.of(\"ABCCED\", \"SEE\", \"XYZ\"); List<Boolean> expectedOutputs = List.of(true, false, true);",
"js": "const boards = [[['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], [['A', 'B', 'C', 'E'], ['S', 'S', 'C', 'S'], ['A', 'D', 'Y', 'E']], [['X', 'Y', 'Z', 'W'], ['Q', 'P', 'O', 'N'], ['A', 'B', 'C', 'D']]]; const words = [\"ABCCED\", \"SEE\", \"XYZ\"]; const expectedOutputs = [true, false, true];",
"python": "boards = [[['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']], [['A', 'B', 'C', 'E'], ['S', 'S', 'C', 'S'], ['A', 'D', 'Y', 'E']], [['X', 'Y', 'Z', 'W'], ['Q', 'P', 'O', 'N'], ['A', 'B', 'C', 'D']]]\n words = [\"ABCCED\", \"SEE\", \"XYZ\"]\n expected_outputs = [True, False, True]"
},
"output": null
}
],
"defaultClass": {
"cpp": "class WordSearch {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n // Write your code here\n }\n};",
"java": "class WordSearch {\n public boolean exist(char[][] board, String word) {\n // Write your code here\n }\n}",
"js": "function exist(board, word) {\n // Write your code here\n}",
"python": "class WordSearch:\n def exist(self, board, word):\n # Write your code here"
},
"defaultBottomRun": {
"cpp": "int main() {\n WordSearch ws;\n ?Customvariable?\n cout << (ws.exist(board, word) ? \"true\" : \"false\") << endl;\n return 0;\n}",
"java": "public static void main(String[] args) {\n WordSearch ws = new WordSearch();\n ?Customvariable?\n System.out.println(ws.exist(board, word) ? \"true\" : \"false\");\n}",
"js": "?Customvariable?\nconsole.log(exist(board, word) ? \"true\" : \"false\");",
"python": "if __name__ == \"__main__\":\n board = [['A', 'B', 'C', 'E'], ['S', 'F', 'C', 'S'], ['A', 'D', 'E', 'E']]\n word = \"ABCCED\"\n ws = WordSearch()\n print(\"true\" if ws.exist(board, word) else \"false\")"
},
"defaultBottomSubmit": {
"cpp": "int main() {\n WordSearch ws;\n ?Customvariable?\n\n for (int i = 0; i < boards.size(); ++i) {\n if (ws.exist(boards[i], words[i]) != expectedOutputs[i]) {\n cout << \"Test case \" << i + 1 << \": Failed\" << endl;\n return 0;\n }\n }\n cout << \"All test cases passed.\" << endl;\n return 0;\n}",
"java": "public static void main(String[] args) {\n WordSearch ws = new WordSearch();\n ?Customvariable?\n\n for (int i = 0; i < boards.size(); i++) {\n if (ws.exist(boards.get(i), words.get(i)) != expectedOutputs.get(i)) {\n System.out.println(\"Test case \" + (i + 1) + \": Failed\");\n return;\n }\n }\n System.out.println(\"All test cases passed.\");\n}",
"js": "?Customvariable?\n\nboards.forEach((board, index) => {\n if (exist(board, words[index]) !== expectedOutputs[index]) {\n console.log(`Test case ${index + 1}: Failed`);\n process.exit(0);\n }\n});\nconsole.log(\"All test cases passed.\");",
"python": "if __name__ == \"__main__\":\n ?Customvariable?\n ws = WordSearch()\n for i, (board, word) in enumerate(zip(boards, words)):\n if ws.exist(board, word) != expected_outputs[i]:\n print(f\"Test case {i + 1}: Failed\")\n exit(0)\n print(\"All test cases passed.\")"
},
"NoOfTestCase": 3
}