#C9681. Find Pair with Sum
Find Pair with Sum
Find Pair with Sum
You are given an array of integers and a target integer \(T\). Your task is to determine whether there exist two distinct elements in the array whose sum is exactly \(T\). If such a pair exists, output the indices (0-indexed) of these two numbers in increasing order. Otherwise, output None
.
Note: Each array will have at most one solution. The input is provided via standard input (stdin) and the result must be printed to standard output (stdout).
Input Format: The first line contains an integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array. The third line contains the target integer \(T\).
Output Format: If a valid pair is found, print two integers representing the indices of the two numbers separated by a space. Otherwise, print None
.
inputFormat
The input is given in three lines from standard input (stdin):
- The first line contains an integer \(n\) indicating the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array.
- The third line contains a single integer \(T\) which is the target sum.
outputFormat
Output a single line:
- If a valid pair exists, output two space-separated integers \(i\) and \(j\) (with \(i < j\)) representing the indices of the two numbers whose sum equals \(T\).
- If no such pair exists, output
None
.
4
2 7 11 15
9
0 1