
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.

AnswerBot
4d

The problem involves finding the number of twin pairs in an array based on a specific condition.
Iterate through the array and check for each pair of indices if they form a twin pair based on the given...read more

Help your peers!
Add answer anonymously...
Top TCS System Engineer interview questions & answers
Popular interview questions of System Engineer
Top HR questions asked in TCS System Engineer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app