## Samsung Interview Question for Software Engineers

Country: India
Interview Type: Written Test

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

the maximum is obviously the set it self so 1|2|3 in above case (=1|3=2|3}, the smallest seem to be the smallest|2nd smallest. O(n) algo, find the smallest, 2nd smallest and or all elements... or and sum. done.

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

could you please explain more in detail? it would be great help?

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

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

int main() {
int set[]={1,2,3};
int n=3;
int arr[(1<<n)][n];
int sum=0;
for(int i=0;i<(1<<n);i++)
{
int k=0;
for(int j=0;j<n;j++)
{
if(i&(1<<j))
arr[i][k++]=set[j];
}
if(k>1)
sum+=arr[i][0]|arr[i][k-1];
}
cout<<sum<<endl;
return 0;
}``````

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

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

int main() {
int set[]={1,2,3};
int n=3;
int arr[(1<<n)][n];
int sum=0;
for(int i=0;i<(1<<n);i++)
{
int k=0;
for(int j=0;j<n;j++)
{
if(i&(1<<j))
arr[i][k++]=set[j];
}
if(k>;1)
sum+=arr[i][0]|arr[i][k-1];
}
cout<<sum<<endl;
return 0;
}``````

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

``````#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);

for(int bit=0;bit<32;bit++){//taking contribution from bit
for(int i=0;i<n;i++){
//i th element is minimmum
for(int j=i+1;j<n;j++){
long long val=((1<<bit)&arr[i]);
long long val2=((1<<bit)&arr[j]);
if(val==0 && val2==0){
continue;
}
int countInBetweenElements=j-i-1;
long long temp=((pow(2,countInBetweenElements))*(pow(2,bit)));
}//mtlb jith element max lelia to bich walo se kitni trh k contibution aaenge
//i and j ka OR aaega power(2,countInBetweenElements)-1 subsets me
}
}

return 0;
}``````

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

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int i,j,k,mini[n],maxi[n],a[n];
for(i=0;i<n;i++)
{
cin >> a[i];
}
int ans=0;
sort(a,a+n);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
ans= ans+ pow(2,(j-i-1))*(a[i]|a[j]);
}
}
cout << ans;
return 0;
}``````

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

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int i,j,k,mini[n],maxi[n],a[n];
for(i=0;i<n;i++)
{
cin >> a[i];
}
int ans=0;
sort(a,a+n);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
ans= ans+ pow(2,(j-i-1))*(a[i]|a[j]);
}
}
cout << ans;
return 0;
}``````

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

``````#include<bits/stdc++.h>
using namespace std;

int main(){

int s;
cin>>s;
int arr[s];
for(int i=0;i<s;i++) cin>>arr[i];
sort(arr, arr+s);
int ans = 0;
for(int i=0;i<s-1;i++){
int a = arr[i];
for(int j=i+1;j<s;j++){
int b = arr[j];
int k =a|b;
k*=pow(2, j-i-1);
ans+=k;
}
}
cout<<ans;
return 0;
}``````

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.