Skip to content

PR Not showing in leaderboard #4066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dsa-solutions/gfg-solutions/Easy problems/Square-Root.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
---
id: square-root
title: Square Root
sidebar_label: Square-Root
Expand Down Expand Up @@ -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)$
108 changes: 54 additions & 54 deletions dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

```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 [];
}
```

</TabItem>
<TabItem value="Python" label="Python">
Expand All @@ -484,39 +483,40 @@ function twoSumProblem() {
right -= 1

return []
```

````

</TabItem>
<TabItem value="Java" label="Java">
<SolutionAuthor name="@ajay-dhangar"/>
```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];
}
}
````

</TabItem>
<TabItem value="C++" label="C++">
Expand Down Expand Up @@ -552,7 +552,7 @@ function twoSumProblem() {
return {};
}
};
```
```

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

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

---
---

<Tabs>
<TabItem value="javascript" label="JavaScript">
<LiteYouTubeEmbed
id="mK1_vjxMfh4"
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
/>
</TabItem>

Expand All @@ -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
/>
</TabItem>
<TabItem value="java" label="Java">
Expand All @@ -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
/>
</TabItem>
</Tabs>
Expand All @@ -640,4 +640,4 @@ The hash table approach is the most efficient and is recommended for large input
{['ajay-dhangar'].map(username => (
<Author key={username} username={username} />
))}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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."
---

Expand Down Expand Up @@ -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:

Expand Down
60 changes: 31 additions & 29 deletions dsa-solutions/lc-solutions/0900-0999/0906-super-palindromes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
```

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
```

Expand All @@ -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:**
Expand Down
Loading