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.

- Chris May 23, 2018 | Flag Reply
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?

- MukeshGupta0315 May 25, 2018 | Flag Reply
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;
}

- Yashpal Ahlawat June 19, 2018 | Flag Reply
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;
}

- Anonymous June 26, 2018 | Flag Reply
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);
	long long answer=0;
	
	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)));
				answer+=temp;
			}//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 
		}	
	}
	
	cout<<answer<<endl;
	return 0;
}

- Namit August 20, 2018 | Flag Reply
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;
}

- Anonymous September 04, 2018 | Flag Reply
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;
}

- Anonymous September 04, 2018 | Flag Reply
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;
}

- mohiit.kmr December 26, 2018 | Flag Reply


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