<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EfficiEval</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #151515;
color: white;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
text-align: center;
}
.container {
width: 80%;
max-width: 600px;
}
.code-section {
margin-bottom: 20px;
}
textarea {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 2px solid #1ce783;
border-radius: 5px;
resize: vertical;
color: black;
}
.button {
margin-bottom: 20px;
}
button {
padding: 10px 20px;
margin: 0 10px;
background-color: #1ce783;
border: none;
border-radius: 5px;
color: white;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0d904f;
}
.result {
display: flex;
flex-direction: column;
align-items: center;
}
label {
margin-bottom: 5px;
}
.result textarea {
width: 100px;
margin-bottom: 10px;
padding: 5px;
}
</style>
</head>
<body>
<div class="container">
<script>
function analyzeTimeComplexity(javaCode) {
let timeComplexity = "O(1)";
if (javaCode.includes("if") && javaCode.includes("else")) {
timeComplexity = "O(1)";
} else if (javaCode.includes("if") && javaCode.includes("else if") && javaCode.includes("else")) {
timeComplexity = "O(n)";
} else if (javaCode.includes("for") && !javaCode.includes("for each")) {
timeComplexity = "O(n)";
} else if (javaCode.includes("switch")) {
timeComplexity = "O(n)";
} else if (javaCode.includes("for each")) {
timeComplexity = "O(n)";
} else if (javaCode.includes("while") || javaCode.includes("do-while")) {
timeComplexity = "O(n)";
} else if (javaCode.includes("for") && javaCode.includes("for") && !javaCode.includes("for each")) {
timeComplexity = "O(n^2)";
} else if (javaCode.includes("for") && (javaCode.includes("while") || javaCode.includes("do-while"))) {
timeComplexity = "O(n^2)";
}
return timeComplexity;
}
// Function to get the time complexity and display it
function calculateTimeComplexity() {
const codeTextArea = document.getElementById("code");
const timeTextArea = document.getElementById("time");
const javaCode = codeTextArea.value;
const timeComplexity = analyzeTimeComplexity(javaCode);
timeTextArea.value = timeComplexity;
}
</script>
<div class="code-section">
<p><strong>CODE:</strong></p>
<textarea id="code" rows="10" placeholder="Paste or write Java code here"></textarea>
</div>
<div class="button">
<button onclick="calculateTimeComplexity()">Submit</button>
</div>
<div class="result">
<label for="time"><b>Time Complexity</b></label>
<textarea id="time" rows="1" readonly></textarea>
</div>
</div>
</body>
</html>