Skip to content

Ecomm #4018

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 3 commits into from
Jul 29, 2024
Merged

Ecomm #4018

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
60 changes: 29 additions & 31 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,29 +200,28 @@ 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 @@ -231,13 +230,12 @@ 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
Binary file added src/data/showcase/pull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/data/userData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,15 @@ export const Users: User[] = [
website: "https://horse-ride-booking.vercel.app/",
source: null,
tags: ["opensource", "react", "redux", "motion", "javascript"],
},
//The Pull

{
title: "The Pull",
description: "Ecommerce wesbite template from where we can buy variety of shoes",
preview: require("./showcase/pull.png"),
website:"https://ridhima10.github.io/The_Pull/",
source: "https://github.com/Ridhima10/The_Pull",
tags: ["html", "css", "javascript"],
}
];
Loading