Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Time and Space Complexity for 2sum problem !!! #1391

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/data/problemData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const problemsData = {

res[num] = i`,
},
timeComplexity: { cpp: "O(n)", java: "O(n)", python: "O(n)" },
spaceComplexity: { cpp: "O(1)", java: "O(1)", python: "O(1)" }
},
containerWithMostWater: {
title: "2. Container With Most Water",
Expand Down
37 changes: 35 additions & 2 deletions src/pages/dsa-interview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from "react";
import { motion, AnimatePresence } from "framer-motion";
import Layout from "@theme/Layout";
import Tabs from "@theme/Tabs"; // Import Tabs component
import TabItem from "@theme/TabItem"; // Import TabItem component
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import problemsData from "../../data/problemData";

const DSAQuestions: React.FC = () => {
Expand Down Expand Up @@ -127,6 +127,17 @@ const DSAQuestions: React.FC = () => {
<pre className="whitespace-pre-wrap bg-gray-200 dark:bg-gray-800 p-3 rounded-md text-sm font-mono mt-2 overflow-auto">
{problemsData[key].solution.cpp}
</pre>
{/* Time and Space Complexity */}
{problemsData[key].timeComplexity?.cpp && (
<div className="mt-2 text-gray-700 dark:text-gray-300">
<p><strong>Time Complexity:</strong> {problemsData[key].timeComplexity.cpp}</p>
</div>
)}
{problemsData[key].spaceComplexity?.cpp && (
<div className="mt-2 text-gray-700 dark:text-gray-300">
<p><strong>Space Complexity:</strong> {problemsData[key].spaceComplexity.cpp}</p>
</div>
)}
</div>
</TabItem>
<TabItem value="java" label="Java">
Expand All @@ -149,6 +160,17 @@ const DSAQuestions: React.FC = () => {
<pre className="whitespace-pre-wrap bg-gray-200 dark:bg-gray-800 p-3 rounded-md text-sm font-mono mt-2 overflow-auto">
{problemsData[key].solution.java}
</pre>
{/* Time and Space Complexity */}
{problemsData[key].timeComplexity?.java && (
<div className="mt-2 text-gray-700 dark:text-gray-300">
<p><strong>Time Complexity:</strong> {problemsData[key].timeComplexity.java}</p>
</div>
)}
{problemsData[key].spaceComplexity?.java && (
<div className="mt-2 text-gray-700 dark:text-gray-300">
<p><strong>Space Complexity:</strong> {problemsData[key].spaceComplexity.java}</p>
</div>
)}
</div>
</TabItem>
<TabItem value="python" label="Python">
Expand All @@ -171,6 +193,17 @@ const DSAQuestions: React.FC = () => {
<pre className="whitespace-pre-wrap bg-gray-200 dark:bg-gray-800 p-3 rounded-md text-sm font-mono mt-2 overflow-auto">
{problemsData[key].solution.python}
</pre>
{/* Time and Space Complexity */}
{problemsData[key].timeComplexity?.python && (
<div className="mt-2 text-gray-700 dark:text-gray-300">
<p><strong>Time Complexity:</strong> {problemsData[key].timeComplexity.python}</p>
</div>
)}
{problemsData[key].spaceComplexity?.python && (
<div className="mt-2 text-gray-700 dark:text-gray-300">
<p><strong>Space Complexity:</strong> {problemsData[key].spaceComplexity.python}</p>
</div>
)}
</div>
</TabItem>
</Tabs>
Expand Down
Loading