# Need clarification: INPUT [5 2 7 9 3 1] Answer: 12

• Hi,

One of the test cases says:

Input: 5 2 7 9 3 1

Expected: 12

That means we can rob the houses in round brackets - 5 (2) 7 (9) 3 (1) = 2 + 9 + 1 = 12

Why not the following - (5) 2 (7) 9 (3) 1 = 5 + 7 + 3 = 15

Shouldn't the answer be 15?

• In my Accepted code, the answer is 15. I guess you might see at a wrong way. There maybe 5 numbers, and they are 2 7 9 3 1, and the answer is 12..................

• Might be some bug in LeetCode. Try pasting the following (wrong) solution, I still hit the issue.

int rob(vector<int> &num) {
int result = 0;
int len = num.size();

``````    for(int i = 0; i < len; i++) {
int sum = num[i];
result = max(result, sum);
for(int j = i + 2; j < len; j++) {
result = max(result, sum + num[j]);
}
}

return result;
``````

}

Input: 5 2 7 9 3 1
Output: 11
Expected: 12

• The testcase 5 2 7 9 3 1 presented by leetcode means that the vector<int> num contains 5 integers which are 2 7 9 3 1.

• thanks for the info! This was what I was looking for :)

• Oops, this is my bad. I've just fixed it. Sorry for the confusion caused.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.