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

Next Permutation !! #1404

Closed
wants to merge 6 commits 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
55 changes: 55 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 Expand Up @@ -125,6 +127,16 @@ class Solution:

return max_area`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},
},
threeSum: {
title: "3. 3Sum",
Expand Down Expand Up @@ -210,6 +222,16 @@ class Solution:
k -= 1
return res`,
},
timeComplexity: {
cpp: "O(n^2)",
java: "O(n^2)",
python: "O(n^2)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},
},

isValidParentheses: {
Expand Down Expand Up @@ -268,6 +290,17 @@ class Solution:
stack.append(char)
return not stack`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},

},

mergeTwoLists: {
Expand Down Expand Up @@ -323,6 +356,17 @@ class Solution:
l2.next = self.mergeTwoLists(l1, l2.next)
return l2`,
},
timeComplexity: {
cpp: "O(n + m)",
java: "O(n + m)",
python: "O(n + m)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},

nextPermutation: {
Expand Down Expand Up @@ -383,6 +427,17 @@ class Solution:
nums[i], nums[j] = nums[j], nums[i]
nums[i + 1:] = nums[i + 1:][::-1]`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},
searchInsert: {
title: "7. Search Insert Position",
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