This is what I've gotten so far. What I've tried to do is go through and find the sequence using greater or equals too in an if statement. Then when that value no longer is greater or equal to the preveious number it goes into the else statement which records that sequence number and resets it so the count can begin again. All these sequence values are saved in an arraylist so that when I'm all done I can just do a simple comparison to find the greatest sequence number and return that. I need help with my first if/else statement that gathers the sequence data because I'm pretty sure this is where my issues are happening.
public class LongestSequence {
public static int getMaxSequence(ArrayList<Integer> list) {
int sequence = 0;
ArrayList<Integer> temp = new ArrayList<Integer>();
for (int i = 0; i < list.size() - 1; i++) {
//this is where things go wrong. I think.
if (list.get(i + 1) >= list.get(i)) {
sequence++;
} else {
//record the number in your arraylist
temp.add(sequence);
//reset count to 0
sequence = 0;
}
}
int greatestnum = 0;
for (int i = 0; i < temp.size() - 1; i++) {
if (temp.get(i) < temp.get(i + 1)) {
greatestnum = temp.get(i + 1);
} else {
greatestnum = temp.get(i);
}
}
return greatestnum;
}