remove example problem data and related starter code handling from CodeChallenge component
This commit is contained in:
@@ -184,84 +184,6 @@ const CodeChallenge = () => {
|
|||||||
setTerminalInput('');
|
setTerminalInput('');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Example problem data
|
|
||||||
const problems = {
|
|
||||||
"Q.1": {
|
|
||||||
id: "two-sum",
|
|
||||||
title: "Two Sum",
|
|
||||||
description: "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
|
|
||||||
constraints: "You may assume that each input would have exactly one solution, and you may not use the same element twice.",
|
|
||||||
examples: [
|
|
||||||
{
|
|
||||||
input: "nums = [2,7,11,15], target = 9",
|
|
||||||
output: "[0,1]",
|
|
||||||
explanation: "Because nums[0] + nums[1] == 9, we return [0, 1]."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: "nums = [3,2,4], target = 6",
|
|
||||||
output: "[1,2]"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: "nums = [3,3], target = 6",
|
|
||||||
output: "[0,1]"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
starterCode: ``
|
|
||||||
},
|
|
||||||
"Q.2": {
|
|
||||||
id: "palindrome-number",
|
|
||||||
title: "Palindrome Number",
|
|
||||||
description: "Given an integer x, return true if x is a palindrome, and false otherwise.",
|
|
||||||
examples: [
|
|
||||||
{
|
|
||||||
input: "x = 121",
|
|
||||||
output: "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: "x = -121",
|
|
||||||
output: "false",
|
|
||||||
explanation: "From left to right, it reads -121. From right to left, it reads 121-. Therefore it is not a palindrome."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
starterCode: ``
|
|
||||||
},
|
|
||||||
"Q.3": {
|
|
||||||
id: "valid-parentheses",
|
|
||||||
title: "Valid Parentheses",
|
|
||||||
description: "Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.",
|
|
||||||
constraints: "An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order.",
|
|
||||||
examples: [
|
|
||||||
{
|
|
||||||
input: 's = "()"',
|
|
||||||
output: "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: 's = "()[]{}"',
|
|
||||||
output: "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: 's = "(]"',
|
|
||||||
output: "false"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
starterCode: ``
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get appropriate starter code based on language
|
|
||||||
const getStarterCode = (problem, lang) => {
|
|
||||||
// Language-specific starter code templates
|
|
||||||
const templates = {
|
|
||||||
'JavaScript': problem.starterCode,
|
|
||||||
'C': ``,
|
|
||||||
'Python': ``,
|
|
||||||
'Java': ``,
|
|
||||||
'C++': ``
|
|
||||||
};
|
|
||||||
|
|
||||||
return templates[lang] || problem.starterCode;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set initial code based on active problem
|
// Set initial code based on active problem
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const currentQuestion = getCurrentQuestion();
|
const currentQuestion = getCurrentQuestion();
|
||||||
@@ -286,10 +208,6 @@ const CodeChallenge = () => {
|
|||||||
setCode(currentQuestion.code_template || getDefaultTemplate(currentQuestion.programming_language || 'JavaScript'));
|
setCode(currentQuestion.code_template || getDefaultTemplate(currentQuestion.programming_language || 'JavaScript'));
|
||||||
setTerminalOutput([]);
|
setTerminalOutput([]);
|
||||||
}
|
}
|
||||||
} else if (problems[activeQuestion]) {
|
|
||||||
// Fallback to example problems if no real test data
|
|
||||||
setCode(getStarterCode(problems[activeQuestion], language));
|
|
||||||
setTerminalOutput([]);
|
|
||||||
}
|
}
|
||||||
}, [activeQuestion]);
|
}, [activeQuestion]);
|
||||||
|
|
||||||
@@ -533,7 +451,7 @@ const CodeChallenge = () => {
|
|||||||
setIsRunning(true);
|
setIsRunning(true);
|
||||||
const currentQuestion = getCurrentQuestion();
|
const currentQuestion = getCurrentQuestion();
|
||||||
setTerminalOutput([
|
setTerminalOutput([
|
||||||
{ type: 'system', content: `Running ${currentQuestion?.title || problems[activeQuestion]?.id || 'code'}...` }
|
{ type: 'system', content: `Running ${currentQuestion?.question_text || currentQuestion?.title || 'code'}...` }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -578,7 +496,7 @@ const CodeChallenge = () => {
|
|||||||
setIsRunning(true);
|
setIsRunning(true);
|
||||||
const currentQuestion = getCurrentQuestion();
|
const currentQuestion = getCurrentQuestion();
|
||||||
setTerminalOutput([
|
setTerminalOutput([
|
||||||
{ type: 'system', content: `Submitting solution for ${currentQuestion?.title || problems[activeQuestion]?.id || 'problem'}...` }
|
{ type: 'system', content: `Submitting solution for ${currentQuestion?.question_text || currentQuestion?.title || 'problem'}...` }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -805,18 +723,12 @@ const CodeChallenge = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to example problems
|
// No question data available
|
||||||
const problem = problems[activeQuestion];
|
|
||||||
if (!problem) return null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="problem-container">
|
<div className="problem-container">
|
||||||
<div className="problem-description">
|
<div className="problem-description">
|
||||||
<p>{problem.description}</p>
|
<p>No question data available. Please ensure a test is selected.</p>
|
||||||
{problem.constraints && <p>{problem.constraints}</p>}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Test cases section removed */}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user