Back to Practice Dashboard
DSA SectionEasy
Pythagorean Triplets
Learn how to solve the 'Pythagorean Triplets' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function contains_pythagorean_triplet(arr) that takes an array of positive integers arr and returns True if there are three integers a, b, and c in the array such that a^2 + b^2 = c^2, or False otherwise.
Constraints
- •3 <= len(arr) <= 1000
- •1 <= arr[i] <= 1000
Examples
Example 1
Input
arr = [3, 1, 4, 6, 5]
Output
True
Explanation
3^2 + 4^2 = 9 + 16 = 25 = 5^2.
Example 2
Input
arr = [10, 4, 6, 12, 5]
Output
False
Need a Hint?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.