Leetcode with dani
Открыть в Telegram
Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts
Больше1 258
Подписчики
Нет данных24 часа
+17 дней
-730 день
Архив постов
1 258
So, the prime numbers are the unmarked ones: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 and 97.
1 258
We move to our next unmarked number 5 and mark all multiples of 5 and are greater than or equal to the square of it.
1 258
Now we move to our next unmarked number 3 and mark all the numbers which are multiples of 3 and are greater than or equal to the square of it.
1 258
According to the algorithm we will mark all the numbers which are divisible by 2 and are greater than or equal to the square of it.
1 258
Let us take an example when n = 100. So, we need to print all prime numbers smaller than or equal to 100.
We create a list of all numbers from 2 to 100.
1 258
Sieve of Eratosthenes
Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.
Example:
Input : n =10
Output : 2 3 5 7
Input : n = 20
Output: 2 3 5 7 11 13 17 19
The sieve of Eratosthenes is one of the most efficient ways to find all primes smaller than n when n is smaller than 10 million or so.
Following is the algorithm to find all the prime numbers less than or equal to a given integer n by the Eratosthene’s method:
When the algorithm terminates, all the numbers in the list that are not marked are prime.
Explanation with Example:
1 258
Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.
Example:
Input : n =10
Output : 2 3 5 7
Input : n = 20
Output: 2 3 5 7 11 13 17 19
1 258
Repost from N/a
🏆 LeetCode 490. The Maze (Premium) 🏆
There's a ball in a maze with:
- Empty spaces (
0) and walls (1).
The ball can roll in any direction:
- Up, down, left, or right 🌐
But here's the catch:
- It won't stop until it hits a wall! 🚧
- Once it stops, it can choose another direction to roll.
### Task 🎯
Given:
- An m x n maze
- The ball's starting position and a destination
Determine:
- Can the ball stop at the destination?
- If yes, return true. Otherwise, return false.
📝 Assumption: All borders of the maze are walls.
---
### Examples 🔍
Example 1:
Input:
maze = [
[0,0,1,0,0],
[0,0,0,0,0],
[0,0,0,1,0],
[1,1,0,1,1],
[0,0,0,0,0]
],
start = [0,4],
destination = [4,4]
Output: true
Explanation: One possible path: left ➡️ down ➡️ left ➡️ down ➡️ right ➡️ down ➡️ right 🎯
---
Example 2:
Input:
maze = [
[0,0,1,0,0],
[0,0,0,0,0],
[0,0,0,1,0],
[1,1,0,1,1],
[0,0,0,0,0]
],
start = [0,4],
destination = [3,2]
Output: false
Explanation: The ball can pass through the destination, but it cannot stop there. ❌
---
Example 3:
Input:
maze = [
[0,0,0,0,0],
[1,1,0,0,1],
[0,0,0,0,0],
[0,1,0,0,1],
[0,1,0,0,0]
],
start = [4,3],
destination = [0,1]
Output: false
---
### Constraints 📏
- Maze Dimensions: 1 ≤ m, n ≤ 100
- Cells contain only 0 (empty) or 1 (wall).
- Start and destination are in empty spaces and won’t initially overlap.
Can you solve it? 🤔1 258
🌟 Join Our LeetCode VIP Channel! 🌟
Unlock your coding potential for just 50 Birr (or $0.50)! Gain exclusive access to premium LeetCode questions, detailed solutions, and a supportive community to help you ace your coding interviews.
Why join?
• Curated problems tailored for interview success
• Step-by-step solutions and tips
• Connect with fellow coders and share insights
Don't miss out on this opportunity to level up your skills! Join now!
Уже доступно! Исследование Telegram 2025 — ключевые инсайты года 
