Count Increasing Quadruplets

Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.

A quadruplet (i, j, k, l) is increasing if:

  • 0 <= i < j < k < l < n
  • nums[i] < nums[k] < nums[j] < nums[l]
Example 1
Inputnums = [1,3,2,4,5]
Output2
For (i, j, k, l) = (0, 1, 2, 3) and (0, 1, 2, 4), nums[i] < nums[k] < nums[j] < nums[l], and there are no other increasing quadruplets.
Example 2
Inputnums = [1,2,3,4]
Output0
There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0.

Constraints

  • 4 <= nums.length <= 4000
  • 1 <= nums[i] <= nums.length
  • All the integers of nums are unique. nums is a permutation.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate