diff --git a/src/data/problemData.ts b/src/data/problemData.ts index 02a389dc6..02ee79af1 100644 --- a/src/data/problemData.ts +++ b/src/data/problemData.ts @@ -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", @@ -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", @@ -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: { @@ -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: { @@ -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: { @@ -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", @@ -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: { @@ -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: { @@ -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: { @@ -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)", @@ -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: { @@ -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: { @@ -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: { @@ -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", @@ -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: { @@ -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: { diff --git a/src/pages/dsa-interview/index.tsx b/src/pages/dsa-interview/index.tsx index 7637a1f88..ac3d54a11 100644 --- a/src/pages/dsa-interview/index.tsx +++ b/src/pages/dsa-interview/index.tsx @@ -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 = () => { @@ -127,6 +127,17 @@ const DSAQuestions: React.FC = () => {
{problemsData[key].solution.cpp}+ {/* Time and Space Complexity */} + {problemsData[key].timeComplexity?.cpp && ( +
Time Complexity: {problemsData[key].timeComplexity.cpp}
+Space Complexity: {problemsData[key].spaceComplexity.cpp}
+{problemsData[key].solution.java}+ {/* Time and Space Complexity */} + {problemsData[key].timeComplexity?.java && ( +
Time Complexity: {problemsData[key].timeComplexity.java}
+Space Complexity: {problemsData[key].spaceComplexity.java}
+{problemsData[key].solution.python}+ {/* Time and Space Complexity */} + {problemsData[key].timeComplexity?.python && ( +
Time Complexity: {problemsData[key].timeComplexity.python}
+Space Complexity: {problemsData[key].spaceComplexity.python}
+