Https://hack.codingblocks.com/app/practice/1/1323/problem

answer given in the exaple should be 4?

See the input array is:
1 -1 2 1
and target value is: 4
so three indexes that bring sum equal to 4 are 1, 2 and 3. That is value: -1, 2 & 1
Sum of these three values will result in 2. Therefore answer will be 2

The task is to return the sum of three integers in arr such that their sum is closest to target. if we select 1,2,1 then it will be 4 na?

Yes my bad, answer will be 4 only as of 1,2 & 1. Might have been mistake by problem setter.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.