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

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

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

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

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

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

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

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

Can you please provide us with a psuedo code or something like that ?
Thanks

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???

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

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

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

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

Only 2,3 - (- , *) are allowed, you cannot do 7+2 , since '+' is not allowed.

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

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

Can anyone provide a correct approach to solve this question?

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

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

happ

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.

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

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

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

can somebody provide me the solution for this

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

I feel for the Test Case :
5 2 10
1 2 6 7 8
2 3 // -, allowed
981

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

3 is not allowed only digits available are: 1 2 6 7 8

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

rfvb ae

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.