Pairs of elements
Practice
2.6 (21 votes)
Data structures
Basics of hash tables
Hash tables
Hashmap
Problem
87% Success 10768 Attempts 30 Points 10s Time Limit 256MB Memory 1024 KB Max Code
You are given an array of length \(N\). You are required to count the number of \((i, j)\) pairs where \(1⩽i
That is the count of the number of pairs of \((i, j)\) such that it satisfies this equation (\(A[j] - A[i] = i^2 + j^2\)).
Input format
- The first line contains the length of the array \(N\). (\(1⩽N⩽10^5\))
- The second line contains \(N\) integers representing array elements. (\(1⩽A[i]⩽10^{12}\))
Output format
Print the number of pairs that satisfy the provided condition.
Explanation
Pairs at indices : (1,2), (2,4), (1,5) satisfy the above condition.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:50
43 votes
Tags:
Hard
Points:30
2 votes
Tags:
Basics of Hash TablesData StructuresHash Tables
Points:30
19 votes
Tags:
Data StructuresHash MapsHash TablesMedium
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor