
Asked in TCS
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...
Top System Engineer Interview Questions Asked at TCS
Q. What is ORM?
Q. What functions have you used in Flask to connect with PostgreSQL?
Q. What is the Singleton design pattern?
Interview Questions Asked to System Engineer at Other Companies
Top Skill-Based Questions for TCS System Engineer
Networking Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
Python Interview Questions and Answers
200 Questions
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

