GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 20 May 2022

[Solution] Subarrays with length CodeChef Solution | CodeChef Problem Solution 2022

You are given an array A of length N.

Determine the count of subarrays of A which contain their length as an element.

Formally, count the number of pairs (L,R) (1≤L≤R≤N) such that: (R−L+1)∈{AL,AL+1,…,AR}.

Solution Click Below:-  CLICK HERE

Input Format

  • First line will contain T, number of test cases. Then the test cases follow.

  • First line of each test case contains an integer N denoting the length of the array A.
  • Second line of each test case contains N space-separated integers A1,A2,…,AN - denoting the array A.

Output Format

For each test case, output the count of subarrays containing their lengths.

Constraints

  • 1≤T≤1000
  • 1≤N≤2⋅105
  • 1≤Ai≤N
  • Sum of N over all test cases does not exceed 5⋅105.

No comments:

Post a Comment