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

Maximum Depth of Binary Tree #1428

Closed
wants to merge 18 commits into from
187 changes: 187 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 Expand Up @@ -435,6 +490,17 @@ class Solution:
low = mid + 1
return low`,
},
timeComplexity: {
cpp: "O(log n)",
java: "O(log n)",
python: "O(log n)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},

isValidSudoku: {
Expand Down Expand Up @@ -501,6 +567,17 @@ class Solution:
blocks[(i//3)*3+j//3].add(curr)
return True`,
},
timeComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},

firstMissingPositive: {
Expand Down Expand Up @@ -554,6 +631,17 @@ class Solution:
if not present[i]: return i
return n + 1`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},

},

maxSubArray: {
Expand Down Expand Up @@ -599,6 +687,17 @@ class Solution:
max_sum = max(max_sum, curr_sum)
return max_sum`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},
mySqrt: {
title: "11. Sqrt(x)",
Expand Down Expand Up @@ -657,6 +756,17 @@ class Solution:
return res
`,
},
timeComplexity: {
cpp: "O(log n)",
java: "O(log n)",
python: "O(log n)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},

searchMatrix: {
Expand Down Expand Up @@ -714,6 +824,17 @@ class Solution:
return False
`,
},
timeComplexity: {
cpp: "O(log(m * n))",
java: "O(log(m * n))",
python: "O(log(m * n))",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},

deleteDuplicates: {
Expand Down Expand Up @@ -764,6 +885,17 @@ class Solution:
return head
`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},

mergeTwoSortedLists: {
Expand Down Expand Up @@ -812,6 +944,17 @@ class Solution:
nums1.sort()
`,
},
timeComplexity: {
cpp: "O((m+n) log(m+n))",
java: "O((m+n) log(m+n))",
python: "O((m+n) log(m+n))",
},
spaceComplexity: {
cpp: "O(1)",
java: "O(1)",
python: "O(1)",
},

},
inorderTraversal: {
title: "15. Binary Tree Inorder Traversal",
Expand Down Expand Up @@ -862,6 +1005,17 @@ class Solution:
return ans
`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(h)",
java: "O(h)",
python: "O(h)",
},

},

isSymmetric: {
Expand Down Expand Up @@ -912,6 +1066,17 @@ class Solution:
return self.isSymmetricTest(p.left, q.right) and self.isSymmetricTest(p.right, q.left)
`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(h)",
java: "O(h)",
python: "O(h)",
},

},

levelOrderTraversal: {
Expand Down Expand Up @@ -988,6 +1153,17 @@ class Solution:
return ans
`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(w)",
java: "O(w)",
python: "O(w)",
},

},

maxDepthBinaryTree: {
Expand Down Expand Up @@ -1027,6 +1203,17 @@ class Solution:
return max(leftDepth, rightDepth) + 1
`,
},
timeComplexity: {
cpp: "O(n)",
java: "O(n)",
python: "O(n)",
},
spaceComplexity: {
cpp: "O(h)",
java: "O(h)",
python: "O(h)",
},

},
hasPathSum: {
title: "19. Path Sum",
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