Skip to content

Commit 019e824

Browse files
committed
add subsegment_partition.cpp
1 parent 2baeb7e commit 019e824

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

CPP/array-2d/subsegment_partition.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// after partitioning an array and sorting the subsegments in ascending order, concatenate them and compare to original array
2+
// find maximum contiguous subsegment in which the array can be partitioned
3+
4+
int findMaxSubsequentCount(vector<int> arr)
5+
{
6+
int maxCount = 0;
7+
int count = 0;
8+
for (int i = 0; i < arr.size(); i++)
9+
{
10+
if (arr[i] < arr[i + 1])
11+
{
12+
count++;
13+
}
14+
else
15+
{
16+
if (count > maxCount)
17+
{
18+
maxCount = count;
19+
}
20+
count = 0;
21+
}
22+
}
23+
return maxCount;
24+
}

0 commit comments

Comments
 (0)