Skip to content

Commit 01b919d

Browse files
authored
Merge pull request #4066 from SadafKausar2025/changes
PR Not showing in leaderboard
2 parents 733bdbc + 4ca0972 commit 01b919d

File tree

4 files changed

+94
-89
lines changed

4 files changed

+94
-89
lines changed

dsa-solutions/gfg-solutions/Easy problems/Square-Root.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
---
23
id: square-root
34
title: Square Root
45
sidebar_label: Square-Root
@@ -190,4 +191,4 @@ class Solution {
190191
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.
191192

192193
**Time Complexity:** $O(log N)$
193-
**Auxiliary Space:** $O(1)$
194+
**Auxiliary Space:** $O(1)$

dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md

+54-54
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ tags:
77
- Hash Table
88
- Two Pointer
99
- Array
10-
- LeetCode
1110
- JavaScript
1211
- TypeScript
1312
description: "This is a solution to the Two Sum problem on LeetCode."
1413
sidebar_position: 1
1514
---
1615

17-
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.
16+
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.
1817

1918
## Problem Description
2019

@@ -441,28 +440,28 @@ function twoSumProblem() {
441440
<TabItem value="TypeScript" label="TypeScript">
442441
<SolutionAuthor name="@ajay-dhangar"/>
443442

444-
```ts
445-
function twoSum(nums: number[], target: number): number[] {
446-
const sortedNums = nums.map((num, index) => [num, index]);
447-
sortedNums.sort((a, b) => a[0] - b[0]);
448-
449-
let left = 0;
450-
let right = sortedNums.length - 1;
451-
452-
while (left < right) {
453-
const sum = sortedNums[left][0] + sortedNums[right][0];
454-
if (sum === target) {
455-
return [sortedNums[left][1], sortedNums[right][1]];
456-
} else if (sum < target) {
457-
left++;
458-
} else {
459-
right--;
460-
}
461-
}
443+
```ts
444+
function twoSum(nums: number[], target: number): number[] {
445+
const sortedNums = nums.map((num, index) => [num, index]);
446+
sortedNums.sort((a, b) => a[0] - b[0]);
447+
448+
let left = 0;
449+
let right = sortedNums.length - 1;
450+
451+
while (left < right) {
452+
const sum = sortedNums[left][0] + sortedNums[right][0];
453+
if (sum === target) {
454+
return [sortedNums[left][1], sortedNums[right][1]];
455+
} else if (sum < target) {
456+
left++;
457+
} else {
458+
right--;
459+
}
460+
}
462461
463-
return [];
464-
}
465-
```
462+
return [];
463+
}
464+
```
466465

467466
</TabItem>
468467
<TabItem value="Python" label="Python">
@@ -484,39 +483,40 @@ function twoSumProblem() {
484483
right -= 1
485484
486485
return []
487-
```
486+
487+
````
488488
489489
</TabItem>
490490
<TabItem value="Java" label="Java">
491491
<SolutionAuthor name="@ajay-dhangar"/>
492492
```java
493-
class Solution {
494-
public int[] twoSum(int[] nums, int target) {
495-
int[][] sortedNums = new int[nums.length][2];
496-
for (int i = 0; i < nums.length; i++) {
497-
sortedNums[i] = new int[] {nums[i], i};
498-
}
493+
class Solution {
494+
public int[] twoSum(int[] nums, int target) {
495+
int[][] sortedNums = new int[nums.length][2];
496+
for (int i = 0; i < nums.length; i++) {
497+
sortedNums[i] = new int[] {nums[i], i};
498+
}
499499

500-
Arrays.sort(sortedNums, (a, b) -> Integer.compare(a[0], b[0]));
500+
Arrays.sort(sortedNums, (a, b) -> Integer.compare(a[0], b[0]));
501501

502-
int left = 0;
503-
int right = sortedNums.length - 1;
502+
int left = 0;
503+
int right = sortedNums.length - 1;
504504

505-
while (left < right) {
506-
int sum = sortedNums[left][0] + sortedNums[right][0];
507-
if (sum == target) {
508-
return new int[] {sortedNums[left][1], sortedNums[right][1]};
509-
} else if (sum < target) {
510-
left++;
511-
} else {
512-
right--;
513-
}
514-
}
505+
while (left < right) {
506+
int sum = sortedNums[left][0] + sortedNums[right][0];
507+
if (sum == target) {
508+
return new int[] {sortedNums[left][1], sortedNums[right][1]};
509+
} else if (sum < target) {
510+
left++;
511+
} else {
512+
right--;
513+
}
514+
}
515515

516-
return new int[0];
517-
}
518-
}
519-
```
516+
return new int[0];
517+
}
518+
}
519+
````
520520

521521
</TabItem>
522522
<TabItem value="C++" label="C++">
@@ -552,7 +552,7 @@ function twoSumProblem() {
552552
return {};
553553
}
554554
};
555-
```
555+
```
556556

557557
</TabItem>
558558
</Tabs>
@@ -585,16 +585,16 @@ The hash table approach is the most efficient and is recommended for large input
585585

586586
<TabItem value="en" label="English">
587587

588-
---
589-
588+
---
589+
590590
<Tabs>
591591
<TabItem value="javascript" label="JavaScript">
592592
<LiteYouTubeEmbed
593593
id="mK1_vjxMfh4"
594594
params="autoplay=1&autohide=1&showinfo=0&rel=0"
595595
title="Two Sum Problem Explanation | Two Sum Problem Solution | Two Sum Problem Approach"
596596
poster="maxresdefault"
597-
webp
597+
webp
598598
/>
599599
</TabItem>
600600

@@ -604,7 +604,7 @@ The hash table approach is the most efficient and is recommended for large input
604604
params="autoplay=1&autohide=1&showinfo=0&rel=0"
605605
title="Two Sum Problem Explanation | Two Sum Problem Solution | Two Sum Problem Approach"
606606
poster="maxresdefault"
607-
webp
607+
webp
608608
/>
609609
</TabItem>
610610
<TabItem value="java" label="Java">
@@ -613,7 +613,7 @@ The hash table approach is the most efficient and is recommended for large input
613613
params="autoplay=1&autohide=1&showinfo=0&rel=0"
614614
title="Two Sum Problem Explanation | Two Sum Problem Solution | Two Sum Problem Approach"
615615
poster="maxresdefault"
616-
webp
616+
webp
617617
/>
618618
</TabItem>
619619
</Tabs>
@@ -640,4 +640,4 @@ The hash table approach is the most efficient and is recommended for large input
640640
{['ajay-dhangar'].map(username => (
641641
<Author key={username} username={username} />
642642
))}
643-
</div>
643+
</div>

dsa-solutions/lc-solutions/0100-0199/0138-Copy-List-with-Random-Pointer.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ tags:
66
- Java
77
- Python
88
- C++
9-
- JavaScript
10-
9+
- JavaScript
1110
description: "This is a solution to the Copy List with Random Pointer problem on LeetCode."
1211
---
1312

@@ -37,13 +36,16 @@ Output: [[7,null],[13,0],[11,4],[10,2],[1,0]]
3736
```
3837
Input: head = [[1,1],[2,1]]
3938
Output: [[1,1],[2,1]]
40-
4139
```
4240

43-
---
41+
### Constraints:
4442

45-
## Solution for Copy List with Random Pointer
43+
- The number of nodes in the list is in the range [0, 1000].
44+
- `-10000 <= Node.val <= 10000`
45+
- Node.random is null or is pointing to some node in the linked list.
46+
---
4647

48+
## Approach to Solve the Copy List with Random Pointer Problem
4749

4850
### Understand the Problem:
4951

dsa-solutions/lc-solutions/0900-0999/0906-super-palindromes.md

+31-29
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
id: super-palindromes
33
title: Super Palindromes
44
sidebar_label: Super Palindromes
5-
tags:
6-
- Palindrome
7-
- Math
5+
tags:
6+
- Palindrome
7+
- Math
88
---
99

1010
## Problem Description
1111

12-
| Problem Statement | Solution Link | LeetCode Profile |
13-
| :------------------------------------------------------ | :------------------------------------------------------------------------- | :------------------------------------------------------ |
12+
| Problem Statement | Solution Link | LeetCode Profile |
13+
| :-------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------- | :--------------------------------------------------- |
1414
| [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/) |
1515

1616
## Problem Description
@@ -62,7 +62,7 @@ def super_palindromes(left, right):
6262
left, right = int(left), int(right)
6363
count = 0
6464
limit = int(math.sqrt(right)) + 1
65-
65+
6666
for i in range(1, limit):
6767
s = str(i)
6868
pal = s + s[::-1]
@@ -71,14 +71,14 @@ def super_palindromes(left, right):
7171
break
7272
if num >= left and is_palindrome(str(num)):
7373
count += 1
74-
74+
7575
pal = s + s[-2::-1]
7676
num = int(pal) ** 2
7777
if num > right:
7878
break
7979
if num >= left and is_palindrome(str(num)):
8080
count += 1
81-
81+
8282
return count
8383
```
8484

@@ -178,7 +178,7 @@ int superPalindromes(char* left, char* right) {
178178
for (long long i = 1; i < limit; i++) {
179179
sprintf(s, "%lld", i);
180180
int len = strlen(s);
181-
181+
182182
// Palindrome of even length
183183
snprintf(pal, 40, "%s%s", s, strrev(strdup(s)));
184184
long long num1 = atoll(pal) * atoll(pal);
@@ -200,28 +200,29 @@ int superPalindromes(char* left, char* right) {
200200

201201
```javascript
202202
function isPalindrome(s) {
203-
return s === s.split('').reverse().join('');
203+
return s === s.split("").reverse().join("");
204204
}
205205

206206
function superPalindromes(left, right) {
207-
let l = BigInt(left), r = BigInt(right);
208-
let count = 0;
209-
let limit = BigInt(Math.sqrt(Number(r))) + BigInt(1);
210-
211-
for (let i = BigInt(1); i < limit; i++) {
212-
let s = i.toString();
213-
let pal1 = s + s.split('').reverse().join('');
214-
let num1 = BigInt(pal1) ** BigInt(2);
215-
if (num1 > r) break;
216-
if (num1 >= l && isPalindrome(num1.toString())) count++;
217-
218-
let pal2 = s + s.slice(0, -1).split('').reverse().join('');
219-
let num2 = BigInt(pal2) ** BigInt(2);
220-
if (num2 > r) break;
221-
if (num2 >= l && isPalindrome(num2.toString())) count++;
222-
}
223-
224-
return count;
207+
let l = BigInt(left),
208+
r = BigInt(right);
209+
let count = 0;
210+
let limit = BigInt(Math.sqrt(Number(r))) + BigInt(1);
211+
212+
for (let i = BigInt(1); i < limit; i++) {
213+
let s = i.toString();
214+
let pal1 = s + s.split("").reverse().join("");
215+
let num1 = BigInt(pal1) ** BigInt(2);
216+
if (num1 > r) break;
217+
if (num1 >= l && isPalindrome(num1.toString())) count++;
218+
219+
let pal2 = s + s.slice(0, -1).split("").reverse().join("");
220+
let num2 = BigInt(pal2) ** BigInt(2);
221+
if (num2 > r) break;
222+
if (num2 >= l && isPalindrome(num2.toString())) count++;
223+
}
224+
225+
return count;
225226
}
226227
```
227228

@@ -230,12 +231,13 @@ function superPalindromes(left, right) {
230231
1. **Generate Palindromes:**
231232
- Iterate through possible values of `i` from 1 to the square root of the right boundary.
232233
- Construct palindromes by concatenating `s` with its reverse and with its reverse minus the last character.
233-
234234
2. **Square Palindromes:**
235+
235236
- Compute the square of each palindrome.
236237
- Check if the squared value is within the range `[left, right]`.
237238

238239
3. **Check for Super-Palindromes:**
240+
239241
- Verify if the squared palindrome is also a palindrome.
240242

241243
4. **Count and Return:**

0 commit comments

Comments
 (0)