#K94607. Two Sum: Find a Pair with Target Sum
Two Sum: Find a Pair with Target Sum
Two Sum: Find a Pair with Target Sum
You are given an array of integers \( arr \) and an integer \( target \). Your task is to find two distinct elements in the array such that their sum equals \( target \). If a valid pair exists, output their indices (0-indexed) as a tuple; otherwise, output an empty tuple ()
.
Note: Each input is guaranteed to have exactly one solution if a valid pair exists, and you cannot use the same element twice. The order of indices in the tuple does not matter.
inputFormat
The input is provided via stdin and consists of three lines:
- The first line contains an integer \( n \), representing the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the elements of \( arr \).
- The third line contains an integer \( target \), the target sum.
outputFormat
The output should be printed to stdout. If a valid pair is found, output the two indices separated by a space. If no such pair exists, output an empty tuple: ()
.
4
2 7 11 15
9
0 1