Juspay Interview Question for Jr. Software Engineers


Country: India




Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String args[]) {
        seiveOfEratosthenesMod(90000, 99999);
    }
    
    public static void seiveOfEratosthenesMod(int l, int h){
        int[] arr = new int[h-1];
        for(int i = 0; i < h-1; i++)
            arr[i] = i+2;
        int n = (int)Math.sqrt(h);
        int in = 2;
        while(in <= n){
            for(int k = 0; k < h-1; k++){
                if(arr[k] != in && arr[k] % in == 0)
                    arr[k] = -1;
            }
            in++;   
        }
        
        int[] cond = new int[h-1];
        int prev = -1;
        for(int k = 0; k < h-1; k++){
            if(arr[k] != -1 && prev != -1 && (prev + arr[k] - 1) < h-1 && arr[prev + arr[k] - 1] != -1){
                cond[prev + arr[k] - 1] = arr[prev + arr[k] - 1];
            }
            if(arr[k] != -1)
                prev = arr[k];
        }
        
        for(int la = l; la < h-1; la++){
            if(cond[la] > 0)
                System.out.print(cond[la] + " ");
        }
        
    }

- sudip.innovates October 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Double_A October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Double_A October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Alkesh October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Alkesh October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Double_A October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Double_A October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int i,j,k,n1,n2,c,x,q,a,w;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
a=prime(i);
if(a==1)
{
c=1;
for(j=i;c!=0;j++)
{
q=prime(j);
if(q==1){
c=0;
x=i+j+1;
}
w=prime(x);
if(x==1)
printf("%d",x);
}
}
}
getch();
}
int prime(int i)
{
int q,a=0;

for(q=1;q<=i;q++)
{
if(i%q==0)
{
a++;
}
}
if(a==2)
{
return 1;
}
else
return 0;
}

- Double_A October 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

using namespace std;

void SieveOfEratosthenes(int l,int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
 
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
    int count =0;
    for (int p=l; p<=n; p++)
       if (prime[p])
          cout << p << " "<<endl;;
    
    for(int i=l;i<=n;i++)
     {
          if(prime[i])
            for(int j=2;j<=i;j++)
               if(prime[j]&&prime[i-j-1]){
                  count++;
                  break;
               }
               
     }
     cout<<"Number of prime numbers are:"<<count;
}

int main()
{
    int n = 30;
    SieveOfEratosthenes(1,7);
    return 0;
}

- doctorStrange November 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int main()
{
int i, prime,upper,lower, n,k=0,a[30],p,s=0,j;
printf(" ENTER THE LOWER LIMIT : ");
scanf("%d", &lower);
printf("\n ENTER THE UPPER LIMIT : ");
scanf("%d", &upper);
printf("\n PRIME NUMBERS LIST IS : ");
for(n=lower+1; n<upper; n++)
{
prime = 1;
for(i=2; i<n/2; i++)
if(n%i == 0)
{
prime = 0;
break;
}
if(prime)
{
a[k]=n;
k++;
}
}
for(i=0,j=i+1;i<k;i++,j++)
{
s=a[i]+a[j]+1;
for(p=i;p<k-1;p++)
{
if(s==a[p])
{
printf("\n%d + %d +1=%d\n",a[i],a[j],a[p]);
break;
}
}

}
}

- Anonymous March 13, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int main()
{
int i, prime,upper,lower, n,k=0,a[30],p,s=0,j;
printf(" ENTER THE LOWER LIMIT : ");
scanf("%d", &lower);
printf("\n ENTER THE UPPER LIMIT : ");
scanf("%d", &upper);
printf("\n PRIME NUMBERS LIST IS : ");
for(n=lower+1; n<upper; n++)
{
prime = 1;
for(i=2; i<n/2; i++)
if(n%i == 0)
{
prime = 0;
break;
}
if(prime)
{
a[k]=n;
k++;
}
}
for(i=0,j=i+1;i<k;i++,j++)
{
s=a[i]+a[j]+1;
for(p=i;p<k-1;p++)
{
if(s==a[p])
{
printf("\n%d + %d +1=%d\n",a[i],a[j],a[p]);
break;
}
}

}
}

- geethanjali March 13, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int main()
{
   int i, prime,upper,lower, n,k=0,a[30],p,s=0,j;
   printf(" ENTER THE LOWER LIMIT : ");
   scanf("%d", &lower);
   printf("\n ENTER THE UPPER LIMIT : ");
   scanf("%d", &upper);
   printf("\n PRIME NUMBERS LIST IS : ");
   for(n=lower+1; n<upper; n++)
   {
     prime = 1;
     for(i=2; i<n/2; i++)
       if(n%i == 0)
       {
         prime = 0;
         break;
       }
     if(prime)
     {
         a[k]=n;
         k++;
     }
    }
    for(i=0,j=i+1;i<k;i++,j++)
    {   
        s=a[i]+a[j]+1;
        for(p=i;p<k-1;p++)
        {
            if(s==a[p])
            {
                printf("\n%d + %d +1=%d\n",a[i],a[j],a[p]);
                break;
            }
        }
        
    }
 }

- geethanjali March 13, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

good way of coding

- Ram July 14, 2020 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More