Solutions LTI Infinity Coding Challenge 2021
Problems and Code
Serena and Flowers
Solution :
Ronny's confidence
Solution
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int D ,K;
D= sc.nextInt();
K= sc.nextInt();
Integer[] dp = new Integer[1000];
Arrays.fill(dp,new Integer(-1));
List<Integer> DP = Arrays.asList(dp);
ArrayList<Integer> P = new ArrayList<>();
int i=2,k=0;
while(k < K){
if(isPrime(i)){
P.add(i);
k++;
}
i++;
}
System.out.println(calculateConfidence(D,P,DP));
}
static final int INT_MAX = Integer.MAX_VALUE;
static int calculateConfidence(int D, ArrayList<Integer> P, List<Integer> dp)
{
if(D==0) return 0;
if(D<0) return INT_MAX;
if(dp.get(D) != -1)
return dp.get(D);
dp.set(D,INT_MAX);
for(int i=0;i<P.size()-1;i++)
{
int current = calculateConfidence(D-P.get(i),P,dp);
if(current == INT_MAX) continue;
dp.set(D,Math.min(dp.get(D),current+1));
}
return dp.get(D);
}
static boolean isPrime(int n){
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
}
Zombies
Solution
Long Number Possibilities
Solution
Food Stalls
Solution
import java.util.*;
class FoodStalls{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
/** Storing in sets so to store only those color
numbers that stall supports ([i][j] == 1)*/
ArrayList<HashSet<Integer>> stallSet
= new ArrayList<HashSet<Integer>>(m);
ArrayList<HashSet<Integer>> personSet
= new ArrayList<HashSet<Integer>>(n);
for(int i=0;i<m;i++){
stallSet.add(new HashSet<Integer>());
for(int j=0;j<10;j++){
if(sc.nextInt()==1)
stallSet.get(i).add(j);
}
}
for(int i=0;i<n;i++){
personSet.add(new HashSet<Integer>());
for(int j=0;j<10;j++){
if(sc.nextInt()==1)
personSet.get(i).add(j);
}
}
int q = sc.nextInt();
int sum =0;
for(int i=0;i<q;i++){
int r = sc.nextInt();
int c = sc.nextInt();
/** If personSet and stallsSet
* intersect then add 1 to sum */
Set<Integer> intersection
= new HashSet<>(personSet.get(r-1));
intersection.retainAll(stallSet.get(c-1));
if(!intersection.isEmpty()){
sum += 1;
}
}
System.out.println(sum);
}
😭
ReplyDeleteNo worries we will try more harder to put the solution
Deletefood stall ?
ReplyDeleteUr website really helps a lot in placement scenario
ReplyDelete