├── .env ├── .eslintrc.json ├── .gitignore ├── README.md ├── next.config.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── problem.json ├── public ├── next.svg └── vercel.svg ├── src ├── app │ ├── accounts │ │ ├── dashboard │ │ │ ├── [...id] │ │ │ │ └── page.tsx │ │ │ └── page.tsx │ │ ├── problems │ │ │ └── [id] │ │ │ │ └── page.tsx │ │ ├── signIn │ │ │ └── page.tsx │ │ └── signUp │ │ │ └── page.tsx │ ├── api │ │ ├── auth │ │ │ ├── profile │ │ │ │ └── route.ts │ │ │ ├── signIn │ │ │ │ └── route.ts │ │ │ ├── signOut │ │ │ │ └── route.ts │ │ │ └── signUp │ │ │ │ └── route.ts │ │ ├── handler │ │ │ ├── handelDisLikedproblems │ │ │ │ └── route.ts │ │ │ ├── handelFavoritesproblems │ │ │ │ └── route.ts │ │ │ ├── handelLikedproblems │ │ │ │ └── route.ts │ │ │ └── handelSolvedproblems │ │ │ │ └── route.ts │ │ ├── languages │ │ │ └── python │ │ │ │ ├── run │ │ │ │ └── route.ts │ │ │ │ └── submit │ │ │ │ └── route.ts │ │ └── utils │ │ │ ├── problemSets │ │ │ └── route.ts │ │ │ └── verifiedUserDetails │ │ │ └── route.ts │ ├── favicon.ico │ ├── globals.css │ ├── layout.tsx │ └── page.tsx ├── assets │ ├── choiceLock.pdf │ ├── finalChoiceLock.pdf │ ├── java.png │ ├── js.png │ ├── logo.png │ ├── logo2.webp │ ├── me1.png │ ├── plate.png │ └── python.png ├── components │ ├── Footer │ │ └── footer.tsx │ ├── Header │ │ ├── acountNavbar.tsx │ │ ├── landingPageNavbar.tsx │ │ ├── playgroundNavbar.tsx │ │ └── problemPageNavbar.tsx │ ├── Timer │ │ └── timer.tsx │ ├── Workspace │ │ ├── Playground │ │ │ ├── console │ │ │ │ └── consoleRunner.tsx │ │ │ └── playground.tsx │ │ ├── ProblemDescription │ │ │ └── problemDescription.tsx │ │ └── workspace.tsx │ └── home │ │ └── home.tsx ├── database │ └── dbConfig.ts ├── helpers │ ├── encryption.ts │ └── type.ts ├── hooks │ ├── useLocalStorage.ts │ └── useWindowSize.ts ├── middleware.ts └── models │ ├── problemModel.ts │ └── userModel.ts ├── tailwind.config.ts ├── tsconfig.json └── yarn.lock /.env: -------------------------------------------------------------------------------- 1 | MONGO_URl= "mongodb://localhost:27017/Leet-code-2023" 2 | SECRET_KEY="publicUserKey" 3 | TOKEN_NAME= "User-Token" -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # LeetCode Clone with Next.js and MongoDB 3 | 4 | Welcome to LeetCode-clone, a dynamic coding challenge platform built with Next.js and MongoDB. This platform not only provides a vast array of algorithmic problems for users to solve but also features automatic testcase evaluation to streamline the learning process. 5 | 6 | 7 | ## Key Features: 8 | 9 | 10 | - **Automatic Testcase Evaluation:** Submit your solution, and LeetCode will run it against a set of predefined test cases, providing instant feedback on correctness. 11 | - **User Authentication:** Secure user authentication system for account creation and login. 12 | - **Coding Challenges:** Diverse set of challenges to practice and improve algorithmic skills. 13 | - **Submission Checker:** Real-time evaluation of user submissions, highlighting test cases passed and failed. 14 | - **User Profile:** Track your progress, completed challenges, and submission history. 15 | - **Responsive Design:** User-friendly interface accessible across devices. 16 | 17 | 18 | ## Technology Stack: 19 | 20 | - **Frontend:** Next.js, TypeScript, TailwindCSS 21 | - **Backend:** Node.js, MongoDB 22 | - **Authentication:** crypto 23 | 24 | 25 | ## Installation 26 | 27 | ## Getting Started: 28 | 29 | - **1. Clone the repository:** `git clone [repository-url]` 30 | - **2. Install dependencies:** `npm install` in both the `frontend` and `backend` directories. 31 | - **4. Set up MongoDB:** Configure your MongoDB connection string in the backend `.env` file. Also Import the `problem.json` in your MongoDB 32 | - **5. Run the development server:** `npm run dev` in both the `frontend` and `backend` directories. 33 | 34 | ## Feedback 35 | 36 | If you have any feedback, please reach out to us at asahaayan@gmail.com 37 | 38 | 39 | ## Optimizations 40 | 41 | What optimizations did you make in your code? E.g. refactors, performance improvements, accessibility 42 | 43 | 44 | ## Screenshots 45 | 46 | ![Screenshot 2023-12-27 212721](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/6b2774ae-08cd-4994-90c1-44f8038fcdf6) 47 | ![Screenshot 2023-12-27 212737](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/738c0302-c8da-4676-9d46-d670c832c277) 48 | ![Screenshot 2023-12-27 213222](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/d001d4e3-457d-4706-8751-f577ae737582) 49 | ![Screenshot 2023-12-27 213119](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/6d84f212-4ac7-4ef6-b779-8e315b5d344c) 50 | ![Screenshot 2023-12-27 213141](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/4b3fd3dc-e699-4715-963d-3e0405b1c7e2) 51 | ![Screenshot 2023-12-27 213129](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/dd233ad8-3630-4861-8a12-94c53e42f485) 52 | ![Screenshot 2023-12-27 213210](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/193ae268-956a-41c4-9d1b-91be3ace83e6) 53 | ![Screenshot 2023-12-27 213256](https://github.com/MEARZIM/LeetCode-Clone/assets/89741434/267f0ad0-cd9a-40e2-88ce-4dd623a5eb2b) 54 | 55 | 56 | 57 | ## 🔗 Links 58 | [![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/) 59 | [![twitter](https://img.shields.io/badge/twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white)](https://twitter.com/) 60 | 61 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = {} 3 | 4 | module.exports = nextConfig 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leetcode-clone", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@codemirror/lang-javascript": "^6.2.1", 13 | "@codemirror/lang-python": "^6.1.3", 14 | "@types/node": "20.6.2", 15 | "@types/react": "18.2.22", 16 | "@types/react-dom": "18.2.7", 17 | "@uiw/codemirror-theme-vscode": "^4.21.21", 18 | "@uiw/react-codemirror": "^4.21.21", 19 | "autoprefixer": "10.4.15", 20 | "axios": "^1.6.2", 21 | "crypto": "^1.0.1", 22 | "eslint": "8.49.0", 23 | "eslint-config-next": "13.4.19", 24 | "mongoose": "^8.0.1", 25 | "next": "^13.5.5-canary.4", 26 | "postcss": "8.4.30", 27 | "python-shell": "^5.0.0", 28 | "react": "^18.2.0", 29 | "react-confetti": "^6.1.0", 30 | "react-dom": "18.2.0", 31 | "react-firebase-hooks": "^5.1.1", 32 | "react-icons": "^4.12.0", 33 | "react-split": "^2.0.14", 34 | "react-toastify": "^9.1.3", 35 | "tailwindcss": "3.3.3", 36 | "typescript": "5.2.2" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /problem.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "_id": { 3 | "$oid": "65813607db0ee3b9bc352d37" 4 | }, 5 | "id": "two-sum", 6 | "title": "Two Sum", 7 | "problemStatement": "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and youmay not use thesame element twice.

You can return the answer in any order.

", 8 | "examples": [ 9 | { 10 | "id": 0, 11 | "inputText": "nums = [2,7,11,15], target = 9", 12 | "outputText": "[0,1]", 13 | "explanation": "Because nums[0] + nums[1] == 9, we return [0, 1]." 14 | }, 15 | { 16 | "id": 1, 17 | "inputText": "nums = [3,2,4], target = 6", 18 | "outputText": "[1,2]", 19 | "explanation": "Because nums[1] + nums[2] == 6, we return [1, 2]." 20 | }, 21 | { 22 | "id": 2, 23 | "inputText": " nums = [3,3], target = 6", 24 | "outputText": "[0,1]" 25 | } 26 | ], 27 | "constraints": "
  • 2 ≤ nums.length ≤ 10
  • -10 ≤ nums[i] ≤ 10
  • -10 ≤ target ≤ 10
  • Only one valid answer exists.
  • ", 28 | "difficulty": "Easy", 29 | "category": "Array", 30 | "order": 1, 31 | "videoId": "8-k1C6ehKuw", 32 | "starterCode": "import sys\nimport ast\n\ndef two_sum(nums, target):\n ''' Write Your Code '''\n\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n # Parse command-line arguments as lists\n arg_lists = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n \n for arg_list in arg_lists:\n nums, target = arg_list\n nums = [int(num) for num in nums] # Convert string representation of numbers to integers\n result = two_sum(nums, target)\n print(result)\n else:\n nums = [2, 7, 11, 15]\n target = 9\n result = two_sum(nums, target)\n print(result)\n\n\n", 33 | "testCase": { 34 | "input": [ 35 | "[[2, 7, 11, 15], 9]", 36 | "[[3, 2, 4], 6]", 37 | "[[3, 3], 6]" 38 | ], 39 | "output": [ 40 | "[0, 1]", 41 | "[1, 2]", 42 | "[0, 1]" 43 | ] 44 | } 45 | }, 46 | { 47 | "_id": { 48 | "$oid": "65813607db0ee3b9bc352d38" 49 | }, 50 | "id": "reverse-linked-list", 51 | "title": "Reverse Linked List", 52 | "problemStatement": "

    Given the head of a singly linked list, reverse the list, and return the reversed list.

    ", 53 | "examples": [ 54 | { 55 | "id": 0, 56 | "inputText": "head = [1,2,3,4,5]", 57 | "outputText": "[5,4,3,2,1]" 58 | }, 59 | { 60 | "id": 1, 61 | "inputText": "head = [1,2,3]", 62 | "outputText": "[3,2,1]" 63 | }, 64 | { 65 | "id": 2, 66 | "inputText": "head = [1]", 67 | "outputText": "[1]" 68 | } 69 | ], 70 | "constraints": "
  • The number of nodes in the list is the range [0, 5000].
  • -5000 <= Node.val <= 5000
  • ", 71 | "difficulty": "Hard", 72 | "category": "Linked List", 73 | "order": 2, 74 | "videoId": "", 75 | "starterCode": "import ast\nimport sys\n\nclass ListNode:\n def __init__(self, value=0, next=None): \n self.value = value\n self.next = next\n\ndef reverse_linked_list(head):\n prev = None\n current = head\n ''' Write your logic '''\n \n\n# Function to convert a list to a linked list\ndef list_to_linked_list(lst):\n if not lst:\n return None\n\n head = ListNode(lst[0])\n current = head\n\n for value in lst[1:]:\n current.next = ListNode(value)\n current = current.next\n\n return head\n\n# Function to convert a linked list to a list\ndef linked_list_to_list(head):\n result = []\n while head:\n result.append(head.value)\n head = head.next\n return result\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n \n for i in nums:\n input_head = list_to_linked_list(i)\n reversed_head = reverse_linked_list(input_head)\n output_list = linked_list_to_list(reversed_head)\n print(output_list)\n \n else:\n \n # Example usage:\n input_list = [1, 2, 3, 4, 5]\n\n # Convert the input list to a linked list\n input_head = list_to_linked_list(input_list)\n\n # Reverse the linked list\n reversed_head = reverse_linked_list(input_head)\n\n # Convert the reversed linked list to a list\n output_list = linked_list_to_list(reversed_head)\n\n print(output_list)", 76 | "testCase": { 77 | "input": [ 78 | "[2, 7, 11, 15]", 79 | "[1,2]", 80 | "[0]" 81 | ], 82 | "output": [ 83 | "[15, 11, 7, 2]", 84 | "[2, 1]", 85 | "[0]" 86 | ] 87 | } 88 | }, 89 | { 90 | "_id": { 91 | "$oid": "65813607db0ee3b9bc352d39" 92 | }, 93 | "id": "jump-game", 94 | "title": "Jump Game", 95 | "problemStatement": "

    You are given an integer array nums. You are initially positioned at the first indexand each element in the array represents your maximum jump length at that position.

    Return true if you can reach the last index, or false otherwise.

    ", 96 | "examples": [ 97 | { 98 | "id": 0, 99 | "inputText": "nums = [2,3,1,1,4]", 100 | "outputText": "true", 101 | "explanation": "Jump 1 step from index 0 to 1, then 3 steps to the last index." 102 | }, 103 | { 104 | "id": 1, 105 | "inputText": "nums = [3,2,1,0,4]", 106 | "outputText": "false", 107 | "explanation": "You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index." 108 | } 109 | ], 110 | "constraints": "
  • 1 <= nums.length <= 10^4
  • 0 <= nums[i] <= 10^5
  • ", 111 | "difficulty": "Medium", 112 | "category": "Dynamic Programming", 113 | "order": 3, 114 | "videoId": "", 115 | "starterCode": "import ast\nimport sys\n\n\ndef can_jump(nums):\n '''Write Your Logic'''\n\n\n\nif __name__ == \"__main__\":\n # Check if command-line arguments are available\n if len(sys.argv) > 1:\n # Parse command-line arguments as integers\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = can_jump(i)\n print(result)\n \n else:\n nums = [2, 3, 1, 1, 4]\n result = can_jump(nums)\n print(result)\n", 116 | "testCase": { 117 | "input": [ 118 | "[2,3,1,1,4]", 119 | "[3,2,1,0,4]" 120 | ], 121 | "output": [ 122 | "True", 123 | "False" 124 | ] 125 | } 126 | }, 127 | { 128 | "_id": { 129 | "$oid": "65813607db0ee3b9bc352d3a" 130 | }, 131 | "id": "valid-parentheses", 132 | "title": "Valid Parentheses", 133 | "problemStatement": "

    Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

    An input string is valid if:

    ", 134 | "examples": [ 135 | { 136 | "id": 0, 137 | "inputText": "s = ()", 138 | "outputText": "True" 139 | }, 140 | { 141 | "id": 1, 142 | "inputText": "s = ()[]{}", 143 | "outputText": "True" 144 | }, 145 | { 146 | "id": 2, 147 | "inputText": "s = (]", 148 | "outputText": "False" 149 | }, 150 | { 151 | "id": 3, 152 | "inputText": "s = ([)]", 153 | "outputText": "False" 154 | } 155 | ], 156 | "constraints": "
  • 1 <= s.length <= 104
  • s consists of parentheses only '()[]{}'.
  • ", 157 | "difficulty": "Easy", 158 | "category": "Stack", 159 | "order": 4, 160 | "videoId": "xty7fr-k0TU", 161 | "starterCode": "import sys\n\ndef is_valid(s):\n ''' Write Your Code '''\n\n\nif __name__ == \"__main__\":\n # Check if command-line arguments are available\n if len(sys.argv) > 1:\n nums = [(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = is_valid(i)\n print(result)\n else:\n nums = \"({[]})\"\n result = is_valid(nums)\n print(result)\n", 162 | "testCase": { 163 | "input": [ 164 | "()", 165 | "()[]{}", 166 | "(]" 167 | ], 168 | "output": [ 169 | "True", 170 | "True", 171 | "False" 172 | ] 173 | } 174 | }, 175 | { 176 | "_id": { 177 | "$oid": "65813607db0ee3b9bc352d3b" 178 | }, 179 | "id": "search-a-2d-matrix", 180 | "title": "Search a 2D Matrix", 181 | "problemStatement": "

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

  • Integers in each row are sorted from left to right.
  • The first integer of each row is greater than the last integer of the previous row.
  • Given matrix, an m x n matrix, and target, return true if target is in the matrix, and false otherwise.

    ", 182 | "examples": [ 183 | { 184 | "id": 0, 185 | "inputText": "matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3", 186 | "outputText": "true" 187 | }, 188 | { 189 | "id": 1, 190 | "inputText": "matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13", 191 | "outputText": "false" 192 | }, 193 | { 194 | "id": 2, 195 | "inputText": "matrix = [[1]], target = 1", 196 | "outputText": "true" 197 | } 198 | ], 199 | "constraints": "
  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 100
  • -104 <= matrix[i][j], target <= 104
  • ", 200 | "difficulty": "Medium", 201 | "category": "Binary Search", 202 | "order": 5, 203 | "videoId": "ZfFl4torNg4", 204 | "starterCode": "import ast\nimport sys\n\ndef search_matrix(matrix, target):\n #Write Your Code\n\n\nif __name__ == \"__main__\":\n # Check if command-line arguments are available\n if len(sys.argv) > 1:\n arg_pairs = [ast.literal_eval(arg) for arg in sys.argv[1:]] \n for arg_pair in arg_pairs:\n matrix, target = arg_pair\n matrix = [list(row) for row in matrix] # Ensure each row is a list\n target = int(target)\n \n result = search_matrix(matrix, target)\n print(result)\n \n else:\n matrix = [\n [1,3,5,7],[10,11,16,20],[23,30,34,60]\n ]\n\n target = 3\n result = search_matrix(matrix, target)\n print(result)\n", 205 | "testCase": { 206 | "input": [ 207 | "[[[1,3,5,7],[10,11,16,20],[23,30,34,60]], 3]", 208 | "[[[1,3,5,7],[10,11,16,20],[23,30,34,60]], 13]" 209 | ], 210 | "output": [ 211 | "True", 212 | "False" 213 | ] 214 | } 215 | }, 216 | { 217 | "_id": { 218 | "$oid": "65813607db0ee3b9bc352d3c" 219 | }, 220 | "id": "container-with-most-water", 221 | "title": "Container With Most Water", 222 | "problemStatement": "

    You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
    Find two lines that together with the x-axis form a container, such that the container contains the most water.
    Return the maximum amount of water a container can store.
    Notice that you may not slant the container.

    ", 223 | "examples": [ 224 | { 225 | "id": 0, 226 | "inputText": "height = [1,8,6,2,5,4,8,3,7]", 227 | "explanation": "The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.", 228 | "outputText": "49" 229 | }, 230 | { 231 | "id": 1, 232 | "inputText": "height =[1,1]", 233 | "outputText": "1" 234 | } 235 | ], 236 | "constraints": "
  • n == height.length
  • 2 <= n <=10^5
  • 0 <= height[i] <= 104
  • ", 237 | "difficulty": "Medium", 238 | "category": "Two Pointers", 239 | "order": 6, 240 | "videoId": "", 241 | "starterCode": "import ast\nimport sys\n\n\ndef max_area(height):\n max_area_value = 0\n left = 0\n right = len(height) - 1\n ''' Write Your Logic '''\n\n\n return max_area_value\n\n# Example usage:\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n \n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = max_area(i)\n print(result)\n \n else:\n # Example Use\n height = [1, 8, 6, 2, 5, 4, 8, 3, 7]\n result = max_area(height)\n print(result)\n", 242 | "testCase": { 243 | "input": [ 244 | "[1, 8, 6, 2, 5, 4, 8, 3, 7]", 245 | "[1,1]" 246 | ], 247 | "output": [ 248 | "49", 249 | "1" 250 | ] 251 | } 252 | }, 253 | { 254 | "_id": { 255 | "$oid": "65813607db0ee3b9bc352d3d" 256 | }, 257 | "id": "merge-intervals", 258 | "title": "Merge Intervals", 259 | "problemStatement": "

    Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

    ", 260 | "examples": [ 261 | { 262 | "id": 0, 263 | "inputText": "intervals = [[1,3],[2,6],[8,10],[15,18]]", 264 | "explanation": "Since intervals [1,3] and [2,6] overlap, merge them into [1,6].", 265 | "outputText": "[[1,6],[8,10],[15,18]]" 266 | }, 267 | { 268 | "id": 1, 269 | "inputText": "intervals = [[1,4],[4,5]]", 270 | "explanation": "Intervals [1,4] and [4,5] are considered overlapping.", 271 | "outputText": "[[1,5]]" 272 | } 273 | ], 274 | "constraints": "
  • 1 <== intervals.length <= 104
  • intervals[i].length ==2
  • 0 <= starti <=endi <= 104
  • ", 275 | "difficulty": "Medium", 276 | "category": "intervals", 277 | "order": 7, 278 | "videoId": "", 279 | "starterCode": "import ast\nimport sys\n\ndef merge(intervals):\n #Write your logic \n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = merge(i)\n print(result)\n \n else: \n intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]\n result = merge(intervals)\n print(result)\n", 280 | "testCase": { 281 | "input": [ 282 | "[[1, 3], [2, 6], [8, 10], [15, 18]]", 283 | "[[1, 4], [4, 5]]" 284 | ], 285 | "output": [ 286 | "[[1, 6], [8, 10], [15, 18]]", 287 | "[[1, 5]]" 288 | ] 289 | } 290 | }, 291 | { 292 | "_id": { 293 | "$oid": "65813607db0ee3b9bc352d3e" 294 | }, 295 | "id": "maximum-depth-of-binary-tree", 296 | "title": "Maximum Depth of Binary Tree", 297 | "problemStatement": "

    Given the root of a binary tree, return its maximum depth.
    A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

    ", 298 | "examples": [ 299 | { 300 | "id": 0, 301 | "inputText": "root = [3,9,20,null,null,15,7]", 302 | "outputText": "3" 303 | }, 304 | { 305 | "id": 1, 306 | "inputText": "root = [1,null,2]", 307 | "outputText": "2" 308 | } 309 | ], 310 | "constraints": "
  • The number of nodes in the tree is in the range[0, 104]
  • -100 <= Node.val <= 100
  • ", 311 | "difficulty": "Easy", 312 | "category": "Tree", 313 | "order": 8, 314 | "videoId": "4qYTqOiRMoM", 315 | "starterCode": "import ast\nimport sys\n\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef list_to_tree(nodes):\n if not nodes:\n return None\n\n root = TreeNode(nodes[0])\n queue = [root]\n i = 1\n\n while i < len(nodes):\n current = queue.pop(0)\n\n if nodes[i] is not None:\n current.left = TreeNode(nodes[i])\n queue.append(current.left)\n i += 1\n\n if i < len(nodes) and nodes[i] is not None:\n current.right = TreeNode(nodes[i])\n queue.append(current.right)\n i += 1\n\n return root\n\ndef max_depth(root):\n ''' Write Your Code '''\n\n\n\n\n\nif __name__ == \"__main__\":\n \n if len(sys.argv) > 1: \n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n root = list_to_tree(i)\n result = max_depth(root)\n print(result)\n \n else:\n input_list = [3, 9, 20, None, None, 15, 7]\n root = list_to_tree(input_list)\n result = max_depth(root)\n print(result)\n \n", 316 | "testCode": { 317 | "input": [ 318 | "[3, 9, 20, None, None, 15, 7]", 319 | "[1,None,2]" 320 | ], 321 | "output": [ 322 | "3", 323 | "2" 324 | ] 325 | } 326 | }, 327 | { 328 | "_id": { 329 | "$oid": "65813607db0ee3b9bc352d3f" 330 | }, 331 | "id": "best-time-to-buy-and-sell-stock", 332 | "title": "Best Time to Buy and Sell Stock", 333 | "problemStatement": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.
    You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
    Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

    ", 334 | "examples": [ 335 | { 336 | "id": 0, 337 | "inputText": "prices = [7,1,5,3,6,4]", 338 | "explanation": "Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.", 339 | "outputText": "5" 340 | }, 341 | { 342 | "id": 1, 343 | "inputText": "prices = [7,6,4,3,1]", 344 | "explanation": "In this case, no transactions are done and the max profit = 0.", 345 | "outputText": "0" 346 | } 347 | ], 348 | "constraints": "
  • 1 <= prices.length <= 105
  • 0 <= prices[i] <= 104
  • ", 349 | "difficulty": "Easy", 350 | "category": "Array", 351 | "order": 9, 352 | "videoId": "", 353 | "starterCode": "import ast\nimport sys\n\n\ndef max_profit(prices):\n if not prices or len(prices) < 2:\n return 0\n\n min_price = prices[0]\n max_profit = 0\n\n '''' Write Your Code '''\n \n\n return max_profit\n\n\n\n\nif __name__ == \"__main__\":\n \n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = max_profit(i)\n print(result)\n \n else:\n prices = [7, 1, 5, 3, 6, 4]\n result = max_profit(prices)\n print(result)\n ", 354 | "testCase": { 355 | "Input": [ 356 | "[7, 1, 5, 3, 6, 4]", 357 | "[7,6,4,3,1]" 358 | ], 359 | "OutPut": [ 360 | "5", 361 | "0" 362 | ] 363 | } 364 | }, 365 | { 366 | "_id": { 367 | "$oid": "6581aa6bdb0ee3b9bc352d46" 368 | }, 369 | "id": "subsets", 370 | "title": "Subsets", 371 | "problemStatement": "

    Given an integer array nums of unique elements, return all possible subsets(the power set). The solution set must not contain duplicate subsets. Return the solution in any order.

    ", 372 | "examples": [ 373 | { 374 | "id": 0, 375 | "inputText": "nums = [1,2,3]", 376 | "outputText": "[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]" 377 | }, 378 | { 379 | "id": 1, 380 | "inputText": "nums = [0]", 381 | "outputText": "[[],[0]]" 382 | } 383 | ], 384 | "constraints": "
  • 1 <= nums.length <= 10
  • -10 <= num[i] <= 10
  • All the numbers of nums are unique.
  • ", 385 | "difficulty": "Medium", 386 | "category": "Backtracking", 387 | "order": 10, 388 | "videoId": "", 389 | "starterCode": "import sys\nimport ast\n\n\ndef subsets(nums):\n ''' Write Your Logic '''\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n nums = [ast.literal_eval(arg) for arg in sys.argv[1:]]\n for i in nums:\n result = subsets(i)\n print(result)\n \n else:\n prices = [1, 2, 3]\n result = subsets(prices)\n print(result)\n ", 390 | "testCase": { 391 | "input": [ 392 | "[1,2,3]", 393 | "[0]" 394 | ], 395 | "output": [ 396 | "[[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]", 397 | "[[], [0]]" 398 | ] 399 | } 400 | }] -------------------------------------------------------------------------------- /public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/accounts/dashboard/[...id]/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | import axios from 'axios'; 3 | import React, { useEffect, useState } from 'react' 4 | import AcountNavbar from '@/components/Header/acountNavbar' 5 | import { IoSearch } from "react-icons/io5"; 6 | import { AiOutlineSolution } from "react-icons/ai"; 7 | import { ImYoutube2 } from "react-icons/im"; 8 | import { ImCheckboxChecked, ImCheckboxUnchecked } from "react-icons/im"; 9 | import { useRouter } from 'next/navigation'; 10 | import { Users, ProblemList } from '@/helpers/type'; 11 | 12 | const page = ({ params }: any) => { 13 | 14 | const router = useRouter(); 15 | const [problems, setProblems] = useState([]); 16 | const [user, setUser] = useState(); 17 | const [difficultyColors, setDifficultyColor] = useState([ 18 | { 19 | type: 'Hard', 20 | color: 'text-red-500', 21 | }, 22 | { 23 | type: 'Medium', 24 | color: 'text-orange-400', 25 | }, 26 | { 27 | type: 'Easy', 28 | color: 'text-lime-400', 29 | }, 30 | ]); 31 | 32 | const getData = async () => { 33 | try { 34 | const problemSet = await axios.get('../../api/utils/problemSets'); 35 | setProblems(problemSet.data.data); 36 | 37 | 38 | const user = await axios.get('../../api/utils/verifiedUserDetails'); 39 | setUser(user.data.user); 40 | 41 | 42 | 43 | } catch (error) { 44 | console.log(error); 45 | } 46 | 47 | } 48 | 49 | useEffect(() => { 50 | getData(); 51 | }, []) 52 | 53 | return ( 54 |
    55 | 56 | 57 |
    58 |
    59 |
    60 | 61 |
    62 |
    63 | 64 |
    65 | 66 |
    67 |
    68 | 69 | 70 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 90 | 91 | 92 | {problems.map((problem: any, index) => ( 93 | 94 | 112 | 119 | 128 | 131 | 135 | 138 | 139 | ))} 140 | 141 | 142 | 143 |
    72 | Status 73 | 75 | Problem Title 76 | 78 | Difficulty 79 | 81 | Category 82 | 84 | Solution 85 | 87 | Video Solution 88 |
    95 | {/* status show */} 96 |
    97 | {user?.problemList.map((userProblem: ProblemList, index) => ( 98 |
    99 | {userProblem._id === problem._id ? ( 100 | userProblem.solved ? ( 101 | 102 | ) : ( 103 | 104 | ) 105 | ) : ( 106 | '' 107 | )} 108 |
    109 | ))} 110 |
    111 |
    113 |
    { 114 | router.push(`/accounts/problems/${problem.id}`); 115 | }}> 116 | {problem.order}. {problem.title} 117 |
    118 |
    { 120 | if (difficultyTypes.type === problem.difficulty) { 121 | return " " + difficultyTypes.color + " "; 122 | } 123 | })}`}> 124 |
    125 | {problem.difficulty} 126 |
    127 |
    129 | {problem.category} 130 | 132 | {/* {problem.solution} */} 133 | 134 | 136 | 137 |
    144 |
    145 |
    146 |
    147 | ) 148 | } 149 | 150 | export default page 151 | -------------------------------------------------------------------------------- /src/app/accounts/dashboard/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | import React, { useEffect, useState } from 'react' 3 | import axios from 'axios'; 4 | import { useRouter } from 'next/navigation'; 5 | import { CgProfile } from "react-icons/cg"; 6 | import Navbar from "@/components/Header/acountNavbar" 7 | import { toast } from 'react-toastify'; 8 | import { Users } from '@/helpers/type'; 9 | 10 | 11 | const page = () => { 12 | const router = useRouter(); 13 | const [user, setUser] = useState(); 14 | 15 | const getUser = async () => { 16 | const res = await axios.get('../../api/utils/verifiedUserDetails'); 17 | setUser(res.data.user); 18 | } 19 | useEffect(() => { 20 | getUser(); 21 | }, []) 22 | 23 | const handelSignOut = async ()=>{ 24 | try { 25 | const res = await axios.get('../../api/auth/signOut'); 26 | if (res.status==200) { 27 | toast.success("Successfully logged Out",{ 28 | position: "top-center", 29 | autoClose: 2000, 30 | theme: "light" 31 | }); 32 | } 33 | router.push('/accounts/signIn'); 34 | 35 | } catch (error) { 36 | 37 | } 38 | } 39 | 40 | 41 | console.log(); 42 | return ( 43 |
    44 | 45 |
    46 |
    47 |
    48 |
    49 |
    50 |

    {user?.totalSolved?.toString()}

    51 |

    Solve Problem

    52 |
    53 |
    54 |

    {user?.totalLikes?.toString()}

    55 |

    Likes

    56 |
    57 |
    58 |

    {user?.totalDisLikes?.toString()}

    59 |

    DisLikes

    60 |
    61 |
    62 |
    63 |
    64 | 65 | 66 |
    67 |
    68 | 69 |
    70 | 78 | 84 |
    85 |
    86 | 87 |
    88 |

    {user?.username}

    89 |

    Kolkata

    90 | 91 |

    Email - {user?.email}

    92 |

    Computer Science

    93 |
    94 | 95 |
    96 |

    Made By - Ayan Saha 97 |
    98 | eat {`->`} code {`->`} sleep 99 |

    100 | 101 |
    102 | 103 |
    104 |
    105 |
    106 | ) 107 | } 108 | 109 | 110 | export default page 111 | -------------------------------------------------------------------------------- /src/app/accounts/problems/[id]/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | import React, { useEffect, useState } from 'react' 3 | import Navbar from '@/components/Header/problemPageNavbar' 4 | import Workspace from '@/components/Workspace/workspace' 5 | import axios from 'axios' 6 | 7 | 8 | 9 | const page = () => { 10 | 11 | const [users, setUsers] = useState(); 12 | const [problems, setProbelems] = useState(); 13 | 14 | const getUser = async () => { 15 | let responce = await axios.get('../../../api/utils/verifiedUserDetails'); 16 | setUsers(responce.data.user); 17 | // console.log(responce.data.user); 18 | } 19 | 20 | const getProblems = async () => { 21 | const rest = await axios.get('../../../api/utils/problemSets'); 22 | setProbelems(rest.data.data); 23 | // console.log(res.data.data); 24 | } 25 | 26 | useEffect(() => { 27 | getUser(); 28 | getProblems(); 29 | }, []) 30 | 31 | 32 | return ( 33 |
    34 | 35 | 36 |
    37 | ) 38 | } 39 | 40 | export default page 41 | -------------------------------------------------------------------------------- /src/app/accounts/signIn/page.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import React, { useEffect, useState } from 'react' 3 | import Logo from '@/assets/logo2.webp' 4 | import Navbar from '@/components/Header/acountNavbar' 5 | import Image from 'next/image' 6 | import Link from 'next/link' 7 | import { useRouter } from 'next/navigation' 8 | import axios from 'axios' 9 | import { toast } from 'react-toastify' 10 | 11 | const page = () => { 12 | const [email, setEmail] = useState(""); 13 | const [password, setPassword] = useState(""); 14 | const [loading, setLoading] = useState(false); 15 | const router = useRouter(); 16 | 17 | const onSignin = async (e: any) => { 18 | e.preventDefault(); 19 | 20 | try { 21 | 22 | setLoading(true); 23 | const res = await axios.post("../api/auth/signIn",{ 24 | email: email, 25 | password: password 26 | }) 27 | 28 | if (res.status === 200) { 29 | toast.success("Successfully logged in",{ 30 | position: "top-center", 31 | autoClose: 2000, 32 | theme: "light" 33 | }); 34 | router.push(`/accounts/dashboard/${res.data.data}`); 35 | } 36 | 37 | 38 | } catch (error:any) { 39 | toast.error(error.response.data.error,{ 40 | position: "top-center", 41 | autoClose: 2000, 42 | theme: "light" 43 | }) 44 | 45 | // console.log(error); 46 | }finally{ 47 | setLoading(false); 48 | } 49 | } 50 | 51 | return ( 52 |
    53 | 54 | 55 |
    56 |
    57 |
    58 | 59 | Logo 60 |

    LeetCode

    61 |
    62 |
    63 | 64 |
    65 | { 67 | setEmail(e.target.value); 68 | }} /> 69 |
    70 |
    71 | 72 |
    73 |
    74 | 75 |
    76 | Forgot password? 77 |
    78 |
    79 |
    80 | { 82 | setPassword(e.target.value); 83 | }} /> 84 |
    85 |
    86 | 87 |
    88 | 91 |
    92 |
    93 | 94 |

    95 | Create Your Account   96 | SignUp 97 |

    98 |
    99 | 100 |
    101 | 102 |
    103 | 104 |
    105 | ) 106 | } 107 | 108 | export default page 109 | -------------------------------------------------------------------------------- /src/app/accounts/signUp/page.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import React, { useState } from 'react' 3 | import Navbar from '@/components/Header/acountNavbar' 4 | import Link from 'next/link' 5 | import Image from 'next/image' 6 | import Logo from '@/assets/logo2.webp' 7 | import { useRouter } from 'next/navigation' 8 | import axios from 'axios' 9 | import { toast } from 'react-toastify' 10 | 11 | const page = () => { 12 | const router = useRouter(); 13 | const [userName, setUserName] = useState(""); 14 | const [email, setEmail] = useState(""); 15 | const [password, setPassword] = useState(""); 16 | const [passwordChecker, setPasswordChecker] = useState(false); 17 | const [loding, setLoding] = useState(false); 18 | 19 | 20 | const validPasswordChecker = (pass: string ,confPass: string)=>{ 21 | if(pass === confPass){ 22 | setPasswordChecker(true); 23 | }else{ 24 | setPasswordChecker(false); 25 | } 26 | } 27 | 28 | const onSignup = async (e:any) => { 29 | e.preventDefault(); 30 | setLoding(true); 31 | 32 | try { 33 | const res = await axios.post('../api/auth/signUp', { 34 | username: userName, 35 | email: email, 36 | password: password, 37 | }) 38 | 39 | if (res.status === 200) { 40 | toast.success(res.data.message,{ 41 | position: "top-center", 42 | autoClose: 2000, 43 | theme: "light" 44 | }) 45 | console.log(res) 46 | router.push('/accounts/signIn'); 47 | } 48 | 49 | } catch (error: any) { 50 | toast.error(error.response.data.error,{ 51 | position: "top-center", 52 | autoClose: 2000, 53 | theme: "light" 54 | }) 55 | 56 | //rest of the errors 57 | console.log(error); 58 | }finally { 59 | setLoding(false); 60 | } 61 | 62 | } 63 | return ( 64 |
    65 | 66 |
    67 |
    68 |
    69 | 70 | Logo 71 |

    LeetCode

    72 |
    73 |
    74 | 75 |
    76 | { 78 | setUserName(e.target.value) 79 | }}/> 80 |
    81 | 82 |
    83 |
    84 | 85 |
    86 | { 88 | setEmail(e.target.value); 89 | }}/> 90 |
    91 | 92 |
    93 | 94 |
    95 |
    96 | { 99 | setPassword(e.target.value); 100 | }}/> 101 |
    102 |
    103 | 104 |
    105 |
    106 | { 108 | validPasswordChecker(password, e.target.value); 109 | }}/> 110 |
    111 |
    112 | 113 |
    114 | 117 |
    118 |
    119 | 120 |

    121 | Do you have An Account ?  122 | SignIn 123 |

    124 |
    125 | 126 |
    127 | 128 |
    129 |
    130 | ) 131 | } 132 | 133 | export default page 134 | -------------------------------------------------------------------------------- /src/app/api/auth/profile/route.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/app/api/auth/profile/route.ts -------------------------------------------------------------------------------- /src/app/api/auth/signIn/route.ts: -------------------------------------------------------------------------------- 1 | import connectDB from "@/database/dbConfig"; 2 | import { random,authentication } from "@/helpers/encryption"; 3 | import { createUser, getUserByEmail } from "@/models/userModel"; 4 | import { NextRequest, NextResponse } from "next/server"; 5 | 6 | 7 | connectDB(); 8 | 9 | export const POST = async(req: NextRequest, res: NextResponse) => { 10 | try { 11 | 12 | const data = await req.json(); 13 | const { email, password } = data; 14 | 15 | if (!email || !password) { 16 | return NextResponse.json({ error: "Invalid email or password" },{status: 409}); 17 | } 18 | 19 | const verifiedUser = await getUserByEmail(email).select('+authentication.salt + authentication.password'); 20 | // console.log(verifiedUser._id.toString()); 21 | 22 | if (!verifiedUser) { 23 | return NextResponse.json({ error: "User Not Found" },{status: 400}); 24 | } 25 | 26 | if (verifiedUser.authentication && verifiedUser.authentication.salt) { 27 | 28 | const expectedHash = authentication(verifiedUser.authentication.salt, password); 29 | 30 | if (expectedHash !== verifiedUser.authentication.password) { 31 | 32 | // If passwords do not match, return an error response with a 408 status code 33 | return NextResponse.json({ error: "Password Not matched" }, { status: 408 }); 34 | 35 | } else { 36 | 37 | // Passwords match 38 | // console.log("Passwords match"); 39 | 40 | //creating a token and saving it 41 | const salt = random(); 42 | verifiedUser.authentication.sessionToken = authentication(salt, verifiedUser._id.toString()); 43 | await verifiedUser.save(); 44 | 45 | const oneDayInMilliseconds = 24 * 60 * 60 * 1000; 46 | const response = NextResponse.json({ 47 | data: verifiedUser._id, 48 | message: "login successful", 49 | success: true, 50 | expires: Date.now() + oneDayInMilliseconds 51 | }) 52 | 53 | response.cookies.set(process.env.TOKEN_NAME!, verifiedUser.authentication.sessionToken,{ 54 | httpOnly: true, 55 | path:"/", 56 | }); 57 | 58 | return response; 59 | 60 | // return NextResponse.json(verifiedUser,{status: 200}); 61 | 62 | } 63 | } else { 64 | 65 | // Handle the case where 'verifiedUser.authentication' is undefined 66 | return NextResponse.json({ error: "User Not Found" }, { status: 404 }); 67 | 68 | } 69 | 70 | } catch (error) { 71 | console.log(error); 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /src/app/api/auth/signOut/route.ts: -------------------------------------------------------------------------------- 1 | import { NextResponse } from "next/server"; 2 | 3 | export const GET = async (res: NextResponse) =>{ 4 | try { 5 | 6 | const response = NextResponse.json({ 7 | message: "LogOut Successfully", 8 | success: true 9 | }); 10 | 11 | response.cookies.set(process.env.TOKEN_NAME!, "", { 12 | httpOnly: true, 13 | expires: new Date(0) 14 | }); 15 | 16 | return response; 17 | 18 | } catch (error) { 19 | console.log(error); 20 | } 21 | } -------------------------------------------------------------------------------- /src/app/api/auth/signUp/route.ts: -------------------------------------------------------------------------------- 1 | import connectDB from "@/database/dbConfig"; 2 | import { random, authentication } from "@/helpers/encryption"; 3 | import { createUser, getUserByEmail } from "@/models/userModel"; 4 | import { getProblems } from "@/models/problemModel"; 5 | 6 | import { NextRequest, NextResponse } from "next/server"; 7 | 8 | connectDB(); 9 | 10 | export const POST = async (req: NextRequest, res: NextResponse) => { 11 | 12 | try { 13 | const data = await req.json(); 14 | const { username, email, password } = data; 15 | // console.log(data); 16 | 17 | if (!username || !email || !password) { 18 | return NextResponse.json({ error: "Enter username or email" }, { status: 404 }); 19 | } 20 | 21 | const existUser = await getUserByEmail(email); 22 | 23 | if (existUser) { 24 | console.log("User already exists"); 25 | return NextResponse.json({ error: 'User already exists' }, { status: 409 }); 26 | } 27 | 28 | const problems = await getProblems(); 29 | 30 | const salt = random(); 31 | 32 | // Create a new user with the same password but encrypted 33 | const res= await createUser({ 34 | username: username, 35 | email: email, 36 | authentication: { 37 | salt, 38 | password: authentication(salt, password), 39 | }, 40 | 41 | totalLikes: 0, 42 | totalDisLikes: 0, 43 | totalSolved: 0, 44 | 45 | 46 | problemList: problems.map((problem) => { 47 | return { 48 | _id: problem._id, 49 | like: false, 50 | dislike: false, 51 | favorite: false, 52 | solved: false, 53 | solvedAnswer: "", 54 | }; 55 | }), 56 | 57 | }) 58 | 59 | 60 | 61 | return NextResponse.json({ message: "User created" }, { status: 200 }); 62 | 63 | } catch (error: any) { 64 | console.log(error); 65 | return NextResponse.json({ error: error.message }, { status: 404 }); 66 | } 67 | } -------------------------------------------------------------------------------- /src/app/api/handler/handelDisLikedproblems/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from 'next/server' 2 | import connectDB from "@/database/dbConfig"; 3 | import { getUserById, updateUserById } from '@/models/userModel'; 4 | 5 | 6 | connectDB(); 7 | 8 | export const POST = async (req: NextRequest, res: NextResponse) => { 9 | const data = await req.json(); 10 | const { disLike, index, user } = data; 11 | 12 | try { 13 | 14 | const updateObject: Record = {}; 15 | updateObject[`problemList.${index}.dislike`] = disLike; 16 | await updateUserById(user._id, updateObject); 17 | 18 | 19 | const updatedUser = await getUserById(user._id); 20 | 21 | const dislikedProblems = updatedUser.problemList.filter((problem: any) => problem.dislike === true) 22 | 23 | await updateUserById(user._id, {totalDisLikes: dislikedProblems.length}); 24 | 25 | 26 | const response = NextResponse.json({ 27 | message: "DisLiked Successfully", 28 | success: true, 29 | }) 30 | 31 | return response 32 | 33 | } catch (error) { 34 | console.log(error); 35 | return error; 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/app/api/handler/handelFavoritesproblems/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from 'next/server' 2 | import connectDB from "@/database/dbConfig"; 3 | import { updateUserById } from '@/models/userModel'; 4 | 5 | 6 | connectDB(); 7 | 8 | export const POST = async (req: NextRequest, res: NextResponse) => { 9 | const data = await req.json(); 10 | const { favorite, index, user } = data; 11 | 12 | try { 13 | const updateObject: Record = {}; 14 | updateObject[`problemList.${index}.favorite`] = favorite; 15 | 16 | 17 | 18 | await updateUserById(user._id, updateObject); 19 | 20 | const response = NextResponse.json({ 21 | message: "favorite Successfully", 22 | success: true, 23 | }) 24 | 25 | return response 26 | 27 | } catch (error) { 28 | console.log(error); 29 | return error; 30 | } 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/app/api/handler/handelLikedproblems/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from 'next/server' 2 | import connectDB from "@/database/dbConfig"; 3 | import { getUserById, updateUserById } from '@/models/userModel'; 4 | 5 | 6 | connectDB(); 7 | 8 | export const POST = async (req: NextRequest, res: NextResponse) => { 9 | const data = await req.json(); 10 | const { like, index, user } = data; 11 | 12 | try { 13 | const updateObject: Record = {}; 14 | updateObject[`problemList.${index}.like`] = like; 15 | await updateUserById(user._id, updateObject); 16 | 17 | 18 | const updatedUser = await getUserById(user._id) 19 | 20 | const likedProblems = updatedUser.problemList.filter((problem: any) => problem.like === true); 21 | 22 | 23 | // Update 'totalLikes' in a single call 24 | await updateUserById(user._id, { totalLikes: likedProblems.length }); 25 | 26 | const response = NextResponse.json({ 27 | message: "Liked Successfully", 28 | success: true, 29 | }) 30 | 31 | return response 32 | 33 | } catch (error) { 34 | console.log(error); 35 | return error; 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/app/api/handler/handelSolvedproblems/route.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/app/api/handler/handelSolvedproblems/route.ts -------------------------------------------------------------------------------- /src/app/api/languages/python/run/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from 'next/server'; 2 | import { PythonShell } from 'python-shell'; 3 | 4 | export const POST = async (req: NextRequest, res: NextResponse) => { 5 | const data = await req.json(); 6 | 7 | const { code } = data; 8 | // console.log(code); 9 | 10 | try { 11 | const message = await PythonShell.runString(code) 12 | const response = NextResponse.json({ 13 | data: message, 14 | message: "Compilation Finished", 15 | success: true, 16 | }) 17 | 18 | return response; 19 | 20 | } catch (error: any) { 21 | const response = NextResponse.json({ 22 | data: null, 23 | message: 'Error during compilation', 24 | success: false, 25 | status: error.status, 26 | error: error.message, 27 | }); 28 | 29 | return response; 30 | } 31 | 32 | 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/app/api/languages/python/submit/route.ts: -------------------------------------------------------------------------------- 1 | import connectDB from '@/database/dbConfig'; 2 | import { getUserById, updateUserById } from '@/models/userModel'; 3 | import { NextRequest, NextResponse } from 'next/server'; 4 | import { PythonShell } from 'python-shell'; 5 | 6 | connectDB(); 7 | 8 | export const POST = async (req: NextRequest, res: NextResponse) => { 9 | const data = await req.json(); 10 | const { user, index, code, problem } = data; 11 | 12 | 13 | 14 | try { 15 | 16 | // Maping the command line parameters 17 | let options = { 18 | args: problem.testCase.input.map((value: string)=>{ 19 | return value 20 | }) 21 | }; 22 | 23 | // Return the output as list(Pyhton) 24 | const message = await PythonShell.runString(code,options) 25 | 26 | 27 | // map the outputs 28 | const Output = problem.testCase.output.map((value: string)=>{ 29 | return value 30 | }) 31 | 32 | 33 | // check if all the tests passed or failed 34 | let checkResultCount = 0; 35 | for (let index = 0; index < Output.length; index++) { 36 | if (Output[index] === message[index]) { 37 | checkResultCount++; 38 | }else{ 39 | break; 40 | } 41 | } 42 | 43 | // returning the responce 44 | if (checkResultCount === Output.length) { 45 | 46 | const updateObject: Record = {}; 47 | 48 | // set the solved part true 49 | updateObject[`problemList.${index}.solved`] = true; 50 | await updateUserById(user._id, updateObject); 51 | 52 | // set the solved code in db 53 | updateObject[`problemList.${index}.solvedAnswer`] = code; 54 | await updateUserById(user._id, updateObject); 55 | 56 | // set the solved 57 | updateObject[`problemList.${index}.solved`] = true; 58 | await updateUserById(user._id, updateObject); 59 | 60 | // Set Total number of Solves 61 | const updatedUser = await getUserById(user._id); 62 | 63 | const solvedproblems = updatedUser.problemList.filter((problem: any) => problem.solved === true); 64 | await updateUserById(user._id, { totalSolved: solvedproblems.length }); 65 | 66 | 67 | 68 | const response = NextResponse.json({ 69 | data: message, 70 | message: "All Test Cases passed", 71 | success: true, 72 | }) 73 | 74 | 75 | 76 | return response; 77 | }else{ 78 | const responseTaseCase = NextResponse.json({ 79 | data: checkResultCount, 80 | message: "All TestCase Not Passed", 81 | success: false, 82 | }) 83 | return responseTaseCase 84 | } 85 | 86 | 87 | 88 | } catch (error: any) { 89 | // Handle error 90 | const response = NextResponse.json({ 91 | data: null, 92 | message: 'Error during compilation', 93 | success: false, 94 | status: error.status, 95 | error: error.message, 96 | }); 97 | 98 | return response; 99 | } 100 | 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/app/api/utils/problemSets/route.ts: -------------------------------------------------------------------------------- 1 | import connectDB from '@/database/dbConfig'; 2 | import { NextRequest, NextResponse } from 'next/server'; 3 | import {getProblems} from '@/models/problemModel' 4 | 5 | connectDB(); 6 | 7 | export const GET = async (req: NextRequest, res:NextResponse) =>{ 8 | try { 9 | const data = await getProblems(); 10 | return NextResponse.json({data}); 11 | 12 | } catch (error) { 13 | console.log(error) 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /src/app/api/utils/verifiedUserDetails/route.ts: -------------------------------------------------------------------------------- 1 | import connectDB from "@/database/dbConfig"; 2 | import {getUserBySessionToken} from '@/models/userModel'; 3 | import { NextResponse } from 'next/server' 4 | import type { NextRequest } from 'next/server' 5 | 6 | connectDB(); 7 | 8 | export const GET = async (request: NextRequest) => { 9 | try { 10 | 11 | const token = request.cookies.get(process.env.TOKEN_NAME!)?.value || ''; 12 | 13 | const user = await getUserBySessionToken(token); 14 | 15 | if (user) { 16 | return NextResponse.json({user}); 17 | } 18 | 19 | } catch (error) { 20 | console.error(error); 21 | } 22 | 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MEARZIM/LeetCode-Clone/33de0a972a3ebd749eb76637e02d91574353ec98/src/app/favicon.ico -------------------------------------------------------------------------------- /src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | .split { 6 | display: flex; 7 | flex-direction: row; 8 | } 9 | 10 | .gutter { 11 | background-color: #eee; 12 | background-repeat: no-repeat; 13 | background-position: 50%; 14 | } 15 | 16 | .gutter:hover{ 17 | background-color: #282828; 18 | } 19 | 20 | .gutter.gutter-horizontal { 21 | background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg=='); 22 | cursor: col-resize; 23 | } 24 | 25 | .gutter.gutter-horizontal ::-webkit-scrollbar{ 26 | width: 5px; 27 | } 28 | 29 | .gutter.gutter-vertical { 30 | background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII='); 31 | cursor: row-resize; 32 | } 33 | 34 | ::-webkit-scrollbar { 35 | width: 0.5rem; 36 | background-color: #282828; 37 | } 38 | 39 | ::-webkit-scrollbar-track { 40 | background: #282828; 41 | } 42 | 43 | ::-webkit-scrollbar-thumb { 44 | background: #4d4d4d; 45 | } 46 | 47 | code { 48 | border-radius: 5px; 49 | border-width: 1px; 50 | font-family: sans-serif; 51 | font-size: 0.75rem; 52 | font-weight: 500; 53 | line-height: 1rem; 54 | padding: 0.125rem; 55 | letter-spacing: 1px; 56 | white-space: pre-wrap; 57 | background-color: hsla(0, 0%, 100%, 0.07); 58 | border-color: rgba(247, 250, 255, 0.12); 59 | color: rgba(239, 241, 246, 0.75); 60 | } 61 | 62 | 63 | .example-card pre { 64 | background-color: hsla(0, 0%, 100%, 0.1); 65 | border-radius: 0.5rem; 66 | color: rgba(239, 241, 246, 0.75); 67 | font-size: 0.98rem; 68 | line-height: 1.25rem; 69 | margin-bottom: 1rem; 70 | margin-top: 1rem; 71 | padding: 1rem; 72 | white-space: pre-wrap; 73 | } 74 | 75 | .example-card pre strong { 76 | color: white; 77 | font-size: 1rem; 78 | } 79 | 80 | 81 | 82 | .cm-scroller { 83 | background-color: #282828 !important; 84 | } 85 | .cm-focused { 86 | outline: none !important; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import './globals.css' 2 | import type { Metadata } from 'next' 3 | import Footer from '@/components/Footer/footer' 4 | import { ToastContainer } from 'react-toastify'; 5 | import 'react-toastify/dist/ReactToastify.css'; 6 | 7 | export const metadata: Metadata = { 8 | title: 'LeetCode Clone', 9 | description: 'Created by Ayan Saha', 10 | } 11 | 12 | export default function RootLayout({ 13 | children, 14 | }: { 15 | children: React.ReactNode 16 | }) { 17 | return ( 18 | 19 | 20 | {children} 21 |