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
4mo
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...
TCS System Engineer interview questions & answers
A System Engineer was asked 3d agoQ. What is the Singleton design pattern?
A System Engineer was asked 3d agoQ. What is normalization in Database Management Systems (DBMS)?
A System Engineer was asked 1w agoQ. Write a program to reverse a string.
Popular interview questions of System Engineer
A System Engineer was asked 4d agoQ1. What is the Singleton design pattern?
A System Engineer was asked 4d agoQ2. What is normalization in Database Management Systems (DBMS)?
A System Engineer was asked 1w agoQ3. Write a program to reverse a string.
Top HR questions asked in TCS System Engineer
A System Engineer was asked 1mo agoQ1. Are you open to the possibility of relocating?
A System Engineer was asked 1mo agoQ2. What can you explain about internships and the differences between mini and majo...read more
A System Engineer was asked 1mo agoQ3. Can you describe the project you completed at the university level?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

