Twin Pairs Problem Statement

Given an array A of size N, find the number of twin pairs in the array. A twin pair is defined as a pair of indices x and y such that x < y and A[y] - A[x] = y - x.

Input:

The first line of input contains an integer T, denoting the number of test cases.
The first line of each test case contains an integer N denoting the size of the array.
The next line contains N space-separated integers representing the array A.

Output:

For each test case, output a single integer denoting the number of twin pairs in the array.

Example:

Input:
2
5
1 2 3 4 5
4
4 3 2 1
Output:
4
0

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 10^5
  • 1 <= A[i] <= N
  • Time Limit: 1 sec

Note:

You are not required to print the expected output. It has already been taken care of. Just implement the function.

Be the first one to answer
Add answer anonymously...
TCS System Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter