remove example problem data and related starter code handling from CodeChallenge component

This commit is contained in:
ishikabhoyar
2025-11-03 19:59:49 +05:30
parent 0c844c3122
commit c579f972b8

View File

@@ -184,84 +184,6 @@ const CodeChallenge = () => {
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
useEffect(() => {
const currentQuestion = getCurrentQuestion();
@@ -286,10 +208,6 @@ const CodeChallenge = () => {
setCode(currentQuestion.code_template || getDefaultTemplate(currentQuestion.programming_language || 'JavaScript'));
setTerminalOutput([]);
}
} else if (problems[activeQuestion]) {
// Fallback to example problems if no real test data
setCode(getStarterCode(problems[activeQuestion], language));
setTerminalOutput([]);
}
}, [activeQuestion]);
@@ -533,7 +451,7 @@ const CodeChallenge = () => {
setIsRunning(true);
const currentQuestion = getCurrentQuestion();
setTerminalOutput([
{ type: 'system', content: `Running ${currentQuestion?.title || problems[activeQuestion]?.id || 'code'}...` }
{ type: 'system', content: `Running ${currentQuestion?.question_text || currentQuestion?.title || 'code'}...` }
]);
try {
@@ -578,7 +496,7 @@ const CodeChallenge = () => {
setIsRunning(true);
const currentQuestion = getCurrentQuestion();
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 {
@@ -805,18 +723,12 @@ const CodeChallenge = () => {
);
}
// Fallback to example problems
const problem = problems[activeQuestion];
if (!problem) return null;
// No question data available
return (
<div className="problem-container">
<div className="problem-description">
<p>{problem.description}</p>
{problem.constraints && <p>{problem.constraints}</p>}
<p>No question data available. Please ensure a test is selected.</p>
</div>
{/* Test cases section removed */}
</div>
);
};