public static long alice(int[] arr){
long[] dp=new long[arr.length];
dp[0]=arr[0];
dp[1]=Math.max(arr[0],arr[1]);
for(int i=2;i<arr.length;i++){
dp[i]=Math.max(dp[i-2]+arr[i],dp[i-1]);
}
return dp[arr.length-1];
}
Alice and Bob// Wrong ans
Hi @Cheshtha
Your code only takes into account of excluding adjacent elements to the chosen element but the question states that all elements equal to the adjacent elements must be removed from the sequence.
Instead you can just store the frequency of each element and then looping all values from 1 to maximum values in the array, you can just take two cases whether to include a particular value or exclude it.
Hope it Helps.
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.