Returns a triplet in the array with sum equal to target, else (0, 0, 0). >>> triplet_sum1([13, 29, 7, 23, 5], 35) (5, 7, 23) >>> triplet_sum1([37, 9, 19, 50, 44], 65) (9, 19, 37) >>> arr = [6, 47, 27, 1, 15] >>> target = 11 >>> triplet_sum1(arr, target) (0, 0
(arr: list[int], target: int)
| 21 | |
| 22 | |
| 23 | def triplet_sum1(arr: list[int], target: int) -> tuple[int, ...]: |
| 24 | """ |
| 25 | Returns a triplet in the array with sum equal to target, |
| 26 | else (0, 0, 0). |
| 27 | >>> triplet_sum1([13, 29, 7, 23, 5], 35) |
| 28 | (5, 7, 23) |
| 29 | >>> triplet_sum1([37, 9, 19, 50, 44], 65) |
| 30 | (9, 19, 37) |
| 31 | >>> arr = [6, 47, 27, 1, 15] |
| 32 | >>> target = 11 |
| 33 | >>> triplet_sum1(arr, target) |
| 34 | (0, 0, 0) |
| 35 | """ |
| 36 | for triplet in permutations(arr, 3): |
| 37 | if sum(triplet) == target: |
| 38 | return tuple(sorted(triplet)) |
| 39 | return (0, 0, 0) |
| 40 | |
| 41 | |
| 42 | def triplet_sum2(arr: list[int], target: int) -> tuple[int, int, int]: |
nothing calls this directly
no outgoing calls
no test coverage detected