- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Divide Array Into Increasing Sequences in Python

Suppose we have a non-decreasing array of positive integers called nums and an integer K, we have to find out if this array can be divided into one or more number of disjoint increasing subsequences of length at least K.

So, if the input is like nums = [1,2,2,3,3,4,4], K = 3, then the output will be true, as this array can be divided into the two subsequences like [1,2,3,4] and [2,3,4] with lengths at least 3 each.

To solve this, we will follow these steps −

d := a new map

req := 0

for each i in nums, do

if i not in d is non-zero, then

d[i]:= 1

otherwise,

d[i] := d[i] + 1

req := maximum of req, d[i]

return true when req*K <= size of nums

Let us see the following implementation to get better understanding −

## Example

class Solution(object): def canDivideIntoSubsequences(self, nums, K): d = {} req = 0 for i in nums: if i not in d: d[i]=1 else: d[i]+=1 req = max(req,d[i]) return req*K<=len(nums) ob = Solution() print(ob.canDivideIntoSubsequences([1,2,2,3,3,4,4],3))

## Input

[1,2,2,3,3,4,4]. 3

## Output

True

- Related Questions & Answers
- Making two sequences increasing in JavaScript
- Converting array into increasing sequence in JavaScript
- Minimum Swaps To Make Sequences Increasing in C++
- Total number of longest increasing sequences in JavaScript
- How to divide an array into half in java?
- Program to find number of strictly increasing colorful candle sequences are there in Python
- All ways to divide array of strings into parts in JavaScript
- Divide a scalar value into every element of a masked Array in NumPy
- Print all increasing sequences of length k from first n natural numbers in C++
- How to generate sequences in Python?
- Removing least number of elements to convert array into increasing sequence using JavaScript
- Divide a number into two parts in C++ Program
- Divide a string into n equal parts - JavaScript
- Make Array Strictly Increasing in C++
- Divide a scalar value into every element of a masked Array with __truediv__() in NumPy

Advertisements