Samsung Interview Question for Software Engineers


Country: United States




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

I got this question today at Samsung's NCR test : I was able to figure out the approach using backtracking but there were so many constraints and i felt emergy lost. My approach was to simple create a 1d array of Numers|operators as input. Then for each set recur after checking constraints .

Before recurring use the lastOperator if present or simply append current digit to current number formed
After recurring reset current number formed

Keep updating click count in base condition

- Anonymous October 28, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please check if this code works on the given constraint or not?
Thanks!!

#include <bits/stdc++.h>
using namespace std;
bool vis[10000];
int main()
{
	int t;   cin>>t;
	while(t--)
	{
		int n,m,lim;   cin>>n>>m>>lim;
		vector<int> v,o;
		queue<pair<int,int> > q;
		for(int i=0;i<n;++i)
		{
			int x;  cin>>x;
			v.push_back(x);
			q.push(make_pair(x,1));
		}
		for(int i=0;i<m;++i)
		{
			int x;   cin>>x;
			o.push_back(x);
		}
		int y;   cin>>y;
		pair<int,int> re;
		while(!q.empty())
		{
			int x = q.front().first;
			int l = q.front().second;
			
			if(x==y)
			{
				re.first = y;
				re.second = l;
				break;
			}
			q.pop();
			
			if(!vis[x])
			{
			
			for(int i=0;i<n;++i)
			{
				q.push(make_pair(x*10 + v[i],l+1));
			}
			
			for(int i=0;i<m;++i)
			{
				for(int j=0;j<n;++j)
				{
					if(o[i]==1)
					{
						q.push(make_pair(x+v[j],l+3));
					}
					else if(o[i]==2)
					{
						q.push(make_pair(x-v[j],l+3));						
					}
					else if(o[i]==3)
					{
						q.push(make_pair(x*v[j],l+3));						
					}
					else if(o[i]==4)
					{
						q.push(make_pair(x/v[j],l+3));						
					}					
				}
			}
			
			vis[x] = true;			
		    }
		}		
		cout<<re.second<<endl;		
	}
}

- Anonymous November 08, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please check if this code work on given constraints or not ?
Thanks!!

#include <bits/stdc++.h>
using namespace std;
bool vis[10000];
int main()
{
	int t;   cin>>t;
	while(t--)
	{
		int n,m,lim;   cin>>n>>m>>lim;
		vector<int> v,o;
		queue<pair<int,int> > q;
		for(int i=0;i<n;++i)
		{
			int x;  cin>>x;
			v.push_back(x);
			q.push(make_pair(x,1));
		}
		for(int i=0;i<m;++i)
		{
			int x;   cin>>x;
			o.push_back(x);
		}
		int y;   cin>>y;
		pair<int,int> re;
		while(!q.empty())
		{
			int x = q.front().first;
			int l = q.front().second;
			
			if(x==y)
			{
				re.first = y;
				re.second = l;
				break;
			}
			q.pop();
			
			if(!vis[x])
			{
			
			for(int i=0;i<n;++i)
			{
				q.push(make_pair(x*10 + v[i],l+1));
			}
			
			for(int i=0;i<m;++i)
			{
				for(int j=0;j<n;++j)
				{
					if(o[i]==1)
					{
						q.push(make_pair(x+v[j],l+3));
					}
					else if(o[i]==2)
					{
						q.push(make_pair(x-v[j],l+3));						
					}
					else if(o[i]==3)
					{
						q.push(make_pair(x*v[j],l+3));						
					}
					else if(o[i]==4)
					{
						q.push(make_pair(x/v[j],l+3));						
					}					
				}
			}
			
			vis[x] = true;			
		    }
		}		
		cout<<re.second<<endl;		
	}
}

- Anonymous November 08, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nhi chl rha 2nd sample case 2nd test case koi ans nhi arhaa

- Anonymous July 07, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Samsung is the chutiyamost company I have ever seen till date. In IOI 3problem given for 5hour and great samsung gives 1ques for 4hour......What do samsung actually want???

- anonymous July 24, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

5 2 10
1 2 6 7 8
2 3 // -, allowed
981

Why 9//62*16-11= when we can do 7+2= & 81

- Anonymous September 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

abe chutiye kis calculator ka output tune is tarah se(7+2=&81) 981 dekha hai. it will show 81 only in this case

- Anonymous October 27, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
make a combinations of all numbers possible along with their touch count . for all these numbers using the available operands check if we can reach the answer again using recursive backtracking.
}

- Daljit Singh March 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone provide a correct approach to solve this question?

- Ashish Musani April 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Second Test Case for problem in wrong..
Correction
6 2 4 // 2nd test case
0 1 3 5 7 9
1 2 4 // +, -, / allowed here
28

Here it should be
6 3 5 // 2nd test case
0 1 3 5 7 9
1 2 4 // +, -, / allowed here
28

Try Solving it now...

If you are struck and need solution mail me on namit.pasrija@gmail.com

- Namit August 21, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

happ

- Anonymous July 07, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Namit is not providing solution dont waste time in requesting solution from him.

- Naman September 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You're right. He's not sending the solution.

- Naina April 12, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can somebody provide me the solution for this

- sonu March 26, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

rfvb ae

- Anonymous September 20, 2017 | 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