From 4ca0972e1b9346d96a99ddf5d00bf1059d1cc5af Mon Sep 17 00:00:00 2001 From: Sadaf <137484958+SadafKausar2025@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:50:21 +0530 Subject: [PATCH] PR Not showing in leaderboard --- .../Easy problems/Square-Root.md | 3 +- .../lc-solutions/0000-0099/0001-two-sum.md | 108 +++++++++--------- .../0138-Copy-List-with-Random-Pointer.md | 12 +- .../0900-0999/0906-super-palindromes.md | 60 +++++----- 4 files changed, 94 insertions(+), 89 deletions(-) diff --git a/dsa-solutions/gfg-solutions/Easy problems/Square-Root.md b/dsa-solutions/gfg-solutions/Easy problems/Square-Root.md index f0c2eb177..47f866b73 100644 --- a/dsa-solutions/gfg-solutions/Easy problems/Square-Root.md +++ b/dsa-solutions/gfg-solutions/Easy problems/Square-Root.md @@ -1,4 +1,5 @@ --- +--- id: square-root title: Square Root sidebar_label: Square-Root @@ -190,4 +191,4 @@ class Solution { The provided solutions efficiently find the floor value of the square root of a given integer `x` using binary search. This approach ensures a time complexity of $ O(log N) and an auxiliary space complexity of $O(1)$. The algorithms are designed to handle large values of `x` up to 10^7 efficiently without relying on built-in square root functions. **Time Complexity:** $O(log N)$ -**Auxiliary Space:** $O(1)$ +**Auxiliary Space:** $O(1)$ \ No newline at end of file diff --git a/dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md b/dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md index f67a76c94..687dbe2e4 100644 --- a/dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md +++ b/dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md @@ -7,14 +7,13 @@ tags: - Hash Table - Two Pointer - Array - - LeetCode - JavaScript - TypeScript description: "This is a solution to the Two Sum problem on LeetCode." sidebar_position: 1 --- -In this tutorial, we will solve the Two Sum problem using three different approaches: brute force, hash table, and two-pointer technique. We will provide the implementation of the solution in JavaScript, TypeScript, Python, Java, C++, and more. +In this tutorial, we will solve the Two Sum problem using three different approaches :brute force, hash table, and two-pointer technique. We will provide the implementation of the solution in JavaScript, TypeScript, Python, Java, C++, and more. ## Problem Description @@ -441,28 +440,28 @@ function twoSumProblem() { - ```ts - function twoSum(nums: number[], target: number): number[] { - const sortedNums = nums.map((num, index) => [num, index]); - sortedNums.sort((a, b) => a[0] - b[0]); - - let left = 0; - let right = sortedNums.length - 1; - - while (left < right) { - const sum = sortedNums[left][0] + sortedNums[right][0]; - if (sum === target) { - return [sortedNums[left][1], sortedNums[right][1]]; - } else if (sum < target) { - left++; - } else { - right--; - } - } +```ts +function twoSum(nums: number[], target: number): number[] { + const sortedNums = nums.map((num, index) => [num, index]); + sortedNums.sort((a, b) => a[0] - b[0]); + + let left = 0; + let right = sortedNums.length - 1; + + while (left < right) { + const sum = sortedNums[left][0] + sortedNums[right][0]; + if (sum === target) { + return [sortedNums[left][1], sortedNums[right][1]]; + } else if (sum < target) { + left++; + } else { + right--; + } + } - return []; - } - ``` + return []; +} +``` @@ -484,39 +483,40 @@ function twoSumProblem() { right -= 1 return [] - ``` + +```` ```java - class Solution { - public int[] twoSum(int[] nums, int target) { - int[][] sortedNums = new int[nums.length][2]; - for (int i = 0; i < nums.length; i++) { - sortedNums[i] = new int[] {nums[i], i}; - } +class Solution { + public int[] twoSum(int[] nums, int target) { + int[][] sortedNums = new int[nums.length][2]; + for (int i = 0; i < nums.length; i++) { + sortedNums[i] = new int[] {nums[i], i}; + } - Arrays.sort(sortedNums, (a, b) -> Integer.compare(a[0], b[0])); + Arrays.sort(sortedNums, (a, b) -> Integer.compare(a[0], b[0])); - int left = 0; - int right = sortedNums.length - 1; + int left = 0; + int right = sortedNums.length - 1; - while (left < right) { - int sum = sortedNums[left][0] + sortedNums[right][0]; - if (sum == target) { - return new int[] {sortedNums[left][1], sortedNums[right][1]}; - } else if (sum < target) { - left++; - } else { - right--; - } - } + while (left < right) { + int sum = sortedNums[left][0] + sortedNums[right][0]; + if (sum == target) { + return new int[] {sortedNums[left][1], sortedNums[right][1]}; + } else if (sum < target) { + left++; + } else { + right--; + } + } - return new int[0]; - } - } - ``` + return new int[0]; + } +} +```` @@ -552,7 +552,7 @@ function twoSumProblem() { return {}; } }; - ``` +``` @@ -585,8 +585,8 @@ The hash table approach is the most efficient and is recommended for large input - --- - +--- + @@ -604,7 +604,7 @@ The hash table approach is the most efficient and is recommended for large input params="autoplay=1&autohide=1&showinfo=0&rel=0" title="Two Sum Problem Explanation | Two Sum Problem Solution | Two Sum Problem Approach" poster="maxresdefault" - webp + webp /> @@ -613,7 +613,7 @@ The hash table approach is the most efficient and is recommended for large input params="autoplay=1&autohide=1&showinfo=0&rel=0" title="Two Sum Problem Explanation | Two Sum Problem Solution | Two Sum Problem Approach" poster="maxresdefault" - webp + webp /> @@ -640,4 +640,4 @@ The hash table approach is the most efficient and is recommended for large input {['ajay-dhangar'].map(username => ( ))} - \ No newline at end of file + diff --git a/dsa-solutions/lc-solutions/0100-0199/0138-Copy-List-with-Random-Pointer.md b/dsa-solutions/lc-solutions/0100-0199/0138-Copy-List-with-Random-Pointer.md index af38b51f5..39b957a96 100644 --- a/dsa-solutions/lc-solutions/0100-0199/0138-Copy-List-with-Random-Pointer.md +++ b/dsa-solutions/lc-solutions/0100-0199/0138-Copy-List-with-Random-Pointer.md @@ -6,8 +6,7 @@ tags: - Java - Python - C++ - - JavaScript - + - JavaScript description: "This is a solution to the Copy List with Random Pointer problem on LeetCode." --- @@ -37,13 +36,16 @@ Output: [[7,null],[13,0],[11,4],[10,2],[1,0]] ``` Input: head = [[1,1],[2,1]] Output: [[1,1],[2,1]] - ``` ---- +### Constraints: -## Solution for Copy List with Random Pointer +- The number of nodes in the list is in the range [0, 1000]. +- `-10000 <= Node.val <= 10000` +- Node.random is null or is pointing to some node in the linked list. +--- +## Approach to Solve the Copy List with Random Pointer Problem ### Understand the Problem: diff --git a/dsa-solutions/lc-solutions/0900-0999/0906-super-palindromes.md b/dsa-solutions/lc-solutions/0900-0999/0906-super-palindromes.md index b4c6801dc..bdc410957 100644 --- a/dsa-solutions/lc-solutions/0900-0999/0906-super-palindromes.md +++ b/dsa-solutions/lc-solutions/0900-0999/0906-super-palindromes.md @@ -2,15 +2,15 @@ id: super-palindromes title: Super Palindromes sidebar_label: Super Palindromes -tags: - - Palindrome - - Math +tags: + - Palindrome + - Math --- ## Problem Description -| Problem Statement | Solution Link | LeetCode Profile | -| :------------------------------------------------------ | :------------------------------------------------------------------------- | :------------------------------------------------------ | +| Problem Statement | Solution Link | LeetCode Profile | +| :-------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------- | :--------------------------------------------------- | | [Super Palindromes](https://leetcode.com/problems/super-palindromes/description/) | [Super Palindromes Solution on LeetCode](https://leetcode.com/problems/super-palindromes/solutions/) | [Nikita Saini](https://leetcode.com/u/Saini_Nikita/) | ## Problem Description @@ -62,7 +62,7 @@ def super_palindromes(left, right): left, right = int(left), int(right) count = 0 limit = int(math.sqrt(right)) + 1 - + for i in range(1, limit): s = str(i) pal = s + s[::-1] @@ -71,14 +71,14 @@ def super_palindromes(left, right): break if num >= left and is_palindrome(str(num)): count += 1 - + pal = s + s[-2::-1] num = int(pal) ** 2 if num > right: break if num >= left and is_palindrome(str(num)): count += 1 - + return count ``` @@ -178,7 +178,7 @@ int superPalindromes(char* left, char* right) { for (long long i = 1; i < limit; i++) { sprintf(s, "%lld", i); int len = strlen(s); - + // Palindrome of even length snprintf(pal, 40, "%s%s", s, strrev(strdup(s))); long long num1 = atoll(pal) * atoll(pal); @@ -200,28 +200,29 @@ int superPalindromes(char* left, char* right) { ```javascript function isPalindrome(s) { - return s === s.split('').reverse().join(''); + return s === s.split("").reverse().join(""); } function superPalindromes(left, right) { - let l = BigInt(left), r = BigInt(right); - let count = 0; - let limit = BigInt(Math.sqrt(Number(r))) + BigInt(1); - - for (let i = BigInt(1); i < limit; i++) { - let s = i.toString(); - let pal1 = s + s.split('').reverse().join(''); - let num1 = BigInt(pal1) ** BigInt(2); - if (num1 > r) break; - if (num1 >= l && isPalindrome(num1.toString())) count++; - - let pal2 = s + s.slice(0, -1).split('').reverse().join(''); - let num2 = BigInt(pal2) ** BigInt(2); - if (num2 > r) break; - if (num2 >= l && isPalindrome(num2.toString())) count++; - } - - return count; + let l = BigInt(left), + r = BigInt(right); + let count = 0; + let limit = BigInt(Math.sqrt(Number(r))) + BigInt(1); + + for (let i = BigInt(1); i < limit; i++) { + let s = i.toString(); + let pal1 = s + s.split("").reverse().join(""); + let num1 = BigInt(pal1) ** BigInt(2); + if (num1 > r) break; + if (num1 >= l && isPalindrome(num1.toString())) count++; + + let pal2 = s + s.slice(0, -1).split("").reverse().join(""); + let num2 = BigInt(pal2) ** BigInt(2); + if (num2 > r) break; + if (num2 >= l && isPalindrome(num2.toString())) count++; + } + + return count; } ``` @@ -230,12 +231,13 @@ function superPalindromes(left, right) { 1. **Generate Palindromes:** - Iterate through possible values of `i` from 1 to the square root of the right boundary. - Construct palindromes by concatenating `s` with its reverse and with its reverse minus the last character. - 2. **Square Palindromes:** + - Compute the square of each palindrome. - Check if the squared value is within the range `[left, right]`. 3. **Check for Super-Palindromes:** + - Verify if the squared palindrome is also a palindrome. 4. **Count and Return:**