---
# System prepended metadata

title: L16-MaxNonoverlappingSegments
tags: [Codility_lessons]

---

# L16-MaxNonoverlappingSegments
###### tags: `Codility_lessons`
## Question
https://app.codility.com/programmers/lessons/16-greedy_algorithms/max_nonoverlapping_segments/
## Key
## Reference
## Solution
```cpp=
int solution(vector<int>& A, vector<int>& B) {
    if (A.size() == 0)
        return 0;
    int count = 1;
    int prev_end = B[0];
    for (int i = 1; i < A.size(); i++)
        if (A[i] > prev_end) {
            count++;
            prev_end = B[i];
        }

    return count;
}
```
