Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
#note
Useful way to find sum of digits from 1 to n
dp[i]=dp[i/10]+i%10;
#note
If we want to look through all subsets of array:
int n=arr.length;
for(int i=0; i<(1<<n); i++){
for(int j=0; j<n; j++){
if((i&(1<<j))>0){
System.out.println(arr[j]+" ");
}
}
}
🔥2👌1
Leetcode in Java && Oracle
image_2023-01-15_02-26-20.png
#note
union-find algorithm is to find cycle in undirected graph
#note
Use Sieve of Eratosthenes algorithm to find all prime numbers till n.
algorithm Sieve of Eratosthenes is
input: an integer n > 1.
output: all prime numbers from 2 through n.

let A be an array of Boolean values, indexed by integers 2 to n,
initially all set to true.

for i = 2, 3, 4, ..., not exceeding √n do
if A[i] is true
for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n do
set A[j] := false

return all i such that A[i] is true.

Time - O(nloglogn)

Example problem: https://leetcode.com/problems/closest-prime-numbers-in-range/description