> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Divide Array Into Increasing Sequences

> Tested Python solution for LeetCode 1121 with 13 pytest cases. Generate a practice environment with lcpy.

LeetCode 1121, [Hard](/catalog/hard). Topics: [Array](/catalog/topics/array), [Greedy](/catalog/topics/greedy). [View on LeetCode](https://leetcode.com/problems/divide-array-into-increasing-sequences/description/).

Generate this problem as a practice environment: tested reference solution, 13 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1121   # by problem number
lcpy gen -s divide_array_into_increasing_sequences   # by problem name
```

## Problem

Given an integer array `nums` sorted in **non-decreasing** order and an integer `k`, return `true` if this array can be divided into one or more disjoint **increasing** subsequences of length at least `k`, or `false` otherwise.

### Examples

```
Input: nums = [1,2,2,3,3,4,4], k = 3
Output: true
Explanation: The array can be divided into two subsequences [1,2,3,4] and [2,3,4] with lengths at least 3 each.
```

```
Input: nums = [5,6,6,7,8], k = 3
Output: false
Explanation: There is no way to divide the array using the conditions required.
```

### Constraints

* 1 \<= k \<= nums.length \<= 10^5
* 1 \<= nums\[i] \<= 10^5
* nums is sorted in non-decreasing order.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_array_into_increasing_sequences/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/divide_array_into_increasing_sequences/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from itertools import groupby


class Solution:
    # Time: O(n)
    # Space: O(1)
    def can_divide_into_subsequences(self, nums: list[int], k: int) -> bool:
        max_freq = max(len(list(group)) for _, group in groupby(nums))
        return max_freq * k <= len(nums)
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.