## Samsung Interview Question for SDE-2s

• 1
of 1 vote

Country: United States
Interview Type: In-Person

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

Cumulative Multiplication from the left ( discounting at the point ):
{1, 2, 8, 24, 120}

Cumulative Multiplication from the right (discounting at the point):
{360,90,30,6,1}

Now multiply these 2 arrays together

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

Nice one!

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

Was this riddle an actual Samsung SDE-2 interview question? What skill are they testing?

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

2

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

this will fail in the case of 1,3,0,4,6 check this out

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

this will fail in the case of 1,3,0,4,6 check this out

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

``````int main()
{
int x[5]= {1,1,1,1,1}, y[5]={2,4,3,5,6};
for(int i=0; i<5; i++)
{
for (int j=0; j<5; j++)
{
if(i==j)
continue;
x[i] = x[i]*y[j];

}
}
for (int i=0; i<5; i++)
cout <<  x[i] << " ";

return 0;
}``````

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

``````int main()
{
int x[5]= {1,1,1,1,1}, y[5]={2,4,3,5,6};
for(int i=0; i<5; i++)
{
for (int j=0; j<5; j++)
{
if(i==j)
continue;
x[i] = x[i]*y[j];

}
}
for (int i=0; i<5; i++)
cout <<  x[i] << " ";

return 0;
}``````

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

``````int x[5]= {1,1,1,1,1}, y[5]={2,4,3,5,6};
for(int i=0; i<5; i++)
{
for (int j=0; j<5; j++)
{
if(i==j)
continue;
x[i] = x[i]*y[j];
}}``````

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

``````#include<iostream>
using namespace std;

int main()
{
int x[5]= {2,4,3,5,6};
int prod[5];
int temp = 1;

for (int i = 0;i < 5;i++){
prod[i] = temp;
temp = temp*x[i];
}

temp = 1;

for (int j = 4;j >=0;j--){
prod[j] = prod[j]*temp;
temp = temp*x[j];
}
for (int i=0; i<5; i++)
cout <<  prod[i] << " ";

return 0;
}``````

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

#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int* orig= new int[n];
int*copy = new int[n];
for(int i=0;i<n;i++)
{
cin>>orig[i];
}
for(int i=0;i<n;i++)
{
copy[i] = orig[i];
}

for(int i=0;i<n;i++)
{
int p =1;
for(int j=0;j<n;j++)
{
if(i==j)
{
continue;
}
p = p*copy[j];
}
orig[i] = p;
}
for(int i=0;i<n;i++)
{
cout<<orig[i]<<" ";
}
return 0;
}

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

#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int* orig= new int[n];
int*copy = new int[n];
for(int i=0;i<n;i++)
{
cin>>orig[i];
}
for(int i=0;i<n;i++)
{
copy[i] = orig[i];
}

for(int i=0;i<n;i++)
{
int p =1;
for(int j=0;j<n;j++)
{
if(i==j)
{
continue;
}
p = p*copy[j];
}
orig[i] = p;
}
for(int i=0;i<n;i++)
{
cout<<orig[i]<<" ";
}
return 0;
}

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

``````package previous_questions;

import java.util.Scanner;

public class ArrayMultiplication {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i< n; i++) {
arr[i] = sc.nextInt();
}
printMultiplication(arr,n);

}
}
public static void printMultiplication(int arr[],int length) {
int[] result = new int[length];
for(int j = 0; j<length; j++) {
result[j] = 1;
}
for(int j = 0; j < length; j++) {
//int i =0;
int size = length-1;
while(size >= 0) {
if(size == j) {
result[j] = result[j] *1;
}
else {
result[j]*=arr[size];
}
size--;
}

}
for(int j = 0; j<length; j++) {
System.out.print(result[j]+" ");
}

}
}``````

Comment hidden because of low score. Click to expand.
-1
of 1 vote

``````public static void main(String args[])
{
int array[]={2,4,3,5,6};

int multi=1;
for(int i=0;i<array.length;i++)
{
multi=multi*array[i];
}

System.out.println("multi: "+multi);

for(int i=0;i<array.length;i++)
{
array[i]=multi/array[i];
}

for(int i:array)
{
System.out.print(i+" ");
}

}``````

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

Division is not allowed. Please refer solution given by SK, this is correct one.

Comment hidden because of low score. Click to expand.
-1
of 1 vote

``````public static void main(String args[])
{
int array[]={2,4,3,5,6};

int multi=1;
for(int i=0;i<array.length;i++)
{
multi=multi*array[i];
}

System.out.println("multi: "+multi);

for(int i=0;i<array.length;i++)
{
array[i]=multi/array[i];
}

for(int i:array)
{
System.out.print(i+" ");
}

}``````

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.

### 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.