## Salesforce Interview Question for SDE-2s

Country: United States
Interview Type: Written Test

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

Input X
Player 1 - We need to backtrack to solve this.
X - Sq(Y) = 0;
i.e, X = Sq(Y) where Y is the last number chosen.
Then further backwards.

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

``````#include <bits/stdc++.h>

using namespace std;

int main() {
int x;
cin >> x;
vector<bool> dp(x + 1, false);
dp[1] = true;
for (int i = 2; i <= x; i++) {
int a = sqrt(i);
for (int j = a; j > 0; j--) {
if (!dp[i - pow(j, 2)]) {
dp[i] = true;
break;
}
}
}
for (int i = 1; i <= x; i++) {
cout << i << (dp[i] ? " true" : " false") << endl;
}
}``````

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

``````#include <bits/stdc++.h>

using namespace std;

int main() {
int x;
cin >> x;
vector<bool> dp(x + 1, false);
dp[1] = true;
for (int i = 2; i <= x; i++) {
int a = sqrt(i);
for (int j = a; j > 0; j--) {
if (!dp[i - pow(j, 2)]) {
dp[i] = true;
break;
}
}
}
for (int i = 1; i <= x; i++) {
cout << i << (dp[i] ? " true" : " false") << endl;
}
}``````

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.