Only trick here is reading the problem carefully. At first it sounds like they want longest non-decreasing "subsequence", but no only a "subsegment", which we are told is a continuous fragment (also known as a substring). We don't even need to store anything, just process everything as you read it in. Once you encounter a value strictly less than the last value, update your best, reset values, and continue.