## Samsung Interview Question

SDE-2s**Country:**United States

**Interview Type:**In-Person

```
#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;
}
```

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

}

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

}

```
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]+" ");
}
}
}
```

```
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+" ");
}
}
```

Cumulative Multiplication from the left ( discounting at the point ):

- SK September 04, 2015{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