#Hi Im not sure I understand the question

1 messages · Page 1 of 1 (latest)

broken quiver
#

Is this what I made serving its purpose Cause I started to doubt it
/*
Given a list of integers, write a function that returns the largest sum of non-adjacent numbers.
Numbers can be 0 or negative.

    For example, [2, 4, 6, 2, 5] should return 13, since we pick 2, 6, and 5. [5, 1, 1, 5] should return 10,
    since we pick 5 and 5.

    Follow-up: Can you do this in O(N) time and constant space?

*/

winter skyBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

Hi! It seems like you're asking for help with a programming question. Could you please provide more context or clarify your question?

broken quiver
#
public static void main(String[] args) {
        int tab[] = {5, -30, -4};
        int temp1 = 0;
        int temp2 = 0;

        if(tab.length % 2 ==0){
            for (int i = (tab.length-1); i >= 1 ; i -=2) {
                temp1 += tab[i];
            }
            for (int i = (tab.length-2); i >= 0 ; i -=2) {
                temp2+= tab[i];
            }
        } else{
            for (int i = (tab.length-1); i >= 0 ; i -=2){
                temp1 += tab[i];
            }
            for (int i = (tab.length-2); i >= 1 ; i -=2) {
                temp2+= tab[i];
            }
        }
        if(temp1 > temp2) System.out.println(temp1);
        else System.out.println(temp2);
    }
}
winter skyBOT
# broken quiver ``` public static void main(String[] args) { int tab[] = {5, -30, -4}; ...

Detected code, here are some useful tools:

Formatted code
public static void main(String[] args) {
  int tab[]  = {
    5,  - 30,  - 4};
  int temp1 = 0;
  int temp2 = 0;
  if (tab.length % 2 == 0) {
    for (int i = (tab.length - 1); i >= 1; i -= 2) {
      temp1 += tab[i] ;
    }
    for (int i = (tab.length - 2); i >= 0; i -= 2) {
      temp2 += tab[i] ;
    }
  }
  else {
    for (int i = (tab.length - 1); i >= 0; i -= 2) {
      temp1 += tab[i] ;
    }
    for (int i = (tab.length - 2); i >= 1; i -= 2) {
      temp2 += tab[i] ;
    }
  }
  if (temp1 > temp2) System.out.println(temp1);
  else System.out.println(temp2);
}
}
celest vector
#

@broken quiver why they selected 5,5 in [ 5,1,1,5]
??

#

instead of [5,1]

#

5,1 is also non adjacent numbers

wide apex
#

because 5+5 is bigger than 5+1

celest vector
#

umm , got it

#
public class MaxSumNonAdjacent {
    public static int maxSumNonAdjacent(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int prevMax = 0; 
        int currMax = 0; 

        for (int num : nums) {
            int temp = currMax;
            currMax = Math.max(currMax, prevMax + num);
            prevMax = temp;
        }

        return Math.max(currMax, prevMax);
    }

    public static void main(String[] args) {
        // define arr    
    }
}```
steel trench