Grouped iteration in Leetcode problems

2024-04-11 12:35:10

**#**Algorithm# Scenario

If an array can be divided into multiple groups, and for each group, we can use the same logic to deal with them, then we can use Grouped Iteration to solve the problem.

- Outer loop will be responsible for
`recording the first element of the group`

plus`update the answer`

. - Inner group will be responsible for
`finding the last element of the group`

.

Note that if every group does not intersect with each other, we can use grouped iteration.

# Basic Template

1 | int n = nums.length; |