Maximize count of Decreasing Consecutive Subsequences from an Array

Given an array arr[] consisting of N integers, the task is to find the maximum count of decreasing subsequences possible from an array which satisfies the following conditions:

  • Each subsequence is in its longest possible form.
  • The difference between adjacent elements of the subsequence is always 1.

Examples:

Input: arr[] = {2, 1, 5, 4, 3}
Output: 2
Explanation:
Possible decreasing subsequences are { 5, 4, 3 } and { 2, 1 }.

Input: arr[] = {4, 5, 2, 1, 4}
Output: 3
Explanation:
Possible decreasing subsequences are { 4 }, { 5, 4} and { 2, 1}.

Approach:
The idea is to use a HashMap to solve the problem. Follow the steps below: