diff --git a/src/data/problemData.ts b/src/data/problemData.ts index 02a389dc6..166b13d2b 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: { @@ -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: { @@ -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", @@ -1074,6 +1261,17 @@ class Solution: return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(h)", + java: "O(h)", + python: "O(h)", + }, + }, generatePascalTriangle: { @@ -1134,6 +1332,17 @@ class Solution: return res `, }, + timeComplexity: { + cpp: "O(n^2)", + java: "O(n^2)", + python: "O(n^2)", + }, + spaceComplexity: { + cpp: "O(n^2)", + java: "O(n^2)", + python: "O(n^2)", + }, + }, maxProfit: { @@ -1185,6 +1394,17 @@ class Solution: return result `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, hasCycle: { @@ -1257,6 +1477,17 @@ class Solution: return False `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, preorderTraversal: { title: "23. Binary Tree Preorder Traversal", @@ -1319,6 +1550,17 @@ class Solution: self.preorder(node.right, result) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(h)", + java: "O(h)", + python: "O(h)", + }, + }, postorderTraversal: { @@ -1382,6 +1624,17 @@ class Solution: result.append(node.val) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(h)", + java: "O(h)", + python: "O(h)", + }, + }, removeElements: { @@ -1428,6 +1681,17 @@ class Solution: return head `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(h)", + java: "O(h)", + python: "O(h)", + }, + }, reverseList: { @@ -1497,6 +1761,17 @@ class Solution: return head `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + }, findKthLargest: { @@ -1534,6 +1809,17 @@ class Solution: return nums[-k] `, }, + timeComplexity: { + cpp: "O(n log n)", + java: "O(n log n)", + python: "O(n log n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, containsDuplicate: { @@ -1573,6 +1859,17 @@ class Solution: return len(nums) > len(set(nums)) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + }, invertBinaryTree: { @@ -1619,6 +1916,17 @@ class Solution: return root `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(h)", + java: "O(h)", + python: "O(h)", + }, + }, MyQueue: { @@ -1725,6 +2033,17 @@ class Solution: return not self.s1 `, }, + timeComplexity: { + cpp: "O(n) for push, O(1) for pop and peek", + java: "O(n) for push, O(1) for pop and peek", + python: "O(n) for push, O(1) for pop and peek", + }, + spaceComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + }, isAnagram: { @@ -1785,6 +2104,17 @@ class Solution: return all(c == 0 for c in count) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, missingNumber: { @@ -1829,6 +2159,17 @@ class Solution: return n * (n + 1) // 2 - sum(nums) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, guessNumber: { @@ -1895,6 +2236,17 @@ class Solution: start = mid + 1 `, }, + timeComplexity: { + cpp: "O(log n)", + java: "O(log n)", + python: "O(log n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, intersect: { @@ -1976,6 +2328,17 @@ class Solution: return result `, }, + timeComplexity: { + cpp: "O(n log n + m log m)", + java: "O(n log n + m log m)", + python: "O(n log n + m log m)", + }, + spaceComplexity: { + cpp: "O(1) or O(min(n, m)) depending on the result size", + java: "O(n + m)", + python: "O(min(n, m))", + }, + }, runningSum: { @@ -2015,6 +2378,17 @@ class Solution: return nums `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(1)", + java: "O(1)", + python: "O(1)", + }, + }, shuffleString: { @@ -2060,6 +2434,17 @@ class Solution: return ''.join(res) `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + }, maxLevelSum: { @@ -2166,6 +2551,17 @@ class Solution: return result_level `, }, + timeComplexity: { + cpp: "O(n)", + java: "O(n)", + python: "O(n)", + }, + spaceComplexity: { + cpp: "O(w)", + java: "O(w)", + python: "O(w)", + }, + }, firstAlphabet: { @@ -2219,6 +2615,16 @@ class Solution: return result `, }, + "timeComplexity": { + "cpp": "O(n)", + "java": "O(n)", + "python": "O(n)" + }, + "spaceComplexity": { + "cpp": "O(w)", + "java": "O(w)", + "python": "O(w)" + } }, countLeaves: { @@ -2260,6 +2666,16 @@ class Solution: return self.countLeaves(root.left) + self.countLeaves(root.right) `, }, + "timeComplexity": { + "cpp": "O(n)", + "java": "O(n)", + "python": "O(n)" + }, + "spaceComplexity": { + "cpp": "O(h)", + "java": "O(h)", + "python": "O(h)" + } }, generateBinaryNumbers: { @@ -2320,6 +2736,16 @@ class Solution: return result `, }, + "timeComplexity": { + "cpp": "O(N)", + "java": "O(N)", + "python": "O(N)" + }, + "spaceComplexity": { + "cpp": "O(N)", + "java": "O(N)", + "python": "O(N)" + } }, minimumDifference: { @@ -2371,6 +2797,16 @@ class Solution: return minm `, }, + "timeComplexity": { + "cpp": "O(n log n)", + "java": "O(n log n)", + "python": "O(n log n)" + }, + "spaceComplexity": { + "cpp": "O(1)", + "java": "O(1)", + "python": "O(1)" + } }, mthHalf: { @@ -2403,6 +2839,16 @@ class Solution: return N // (2 ** (M - 1)) `, }, + "timeComplexity": { + "cpp": "O(1)", + "java": "O(1)", + "python": "O(1)" + }, + "spaceComplexity": { + "cpp": "O(1)", + "java": "O(1)", + "python": "O(1)" + } }, removeChars: { @@ -2462,6 +2908,16 @@ class Solution: return ''.join(ans) `, }, + "timeComplexity": { + "cpp": "O(m + n)", + "java": "O(m + n)", + "python": "O(m + n)" + }, + "spaceComplexity": { + "cpp": "O(1)", + "java": "O(1)", + "python": "O(1)" + } }, rotateArray: { 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}

+
+ )} + {problemsData[key].spaceComplexity?.cpp && ( +
+

Space Complexity: {problemsData[key].spaceComplexity.cpp}

+
+ )} @@ -149,6 +160,17 @@ const DSAQuestions: React.FC = () => {
                               {problemsData[key].solution.java}
                             
+ {/* Time and Space Complexity */} + {problemsData[key].timeComplexity?.java && ( +
+

Time Complexity: {problemsData[key].timeComplexity.java}

+
+ )} + {problemsData[key].spaceComplexity?.java && ( +
+

Space Complexity: {problemsData[key].spaceComplexity.java}

+
+ )}
@@ -171,6 +193,17 @@ const DSAQuestions: React.FC = () => {
                               {problemsData[key].solution.python}
                             
+ {/* Time and Space Complexity */} + {problemsData[key].timeComplexity?.python && ( +
+

Time Complexity: {problemsData[key].timeComplexity.python}

+
+ )} + {problemsData[key].spaceComplexity?.python && ( +
+

Space Complexity: {problemsData[key].spaceComplexity.python}

+
+ )}