#K13021. Find Triplet Sum
Find Triplet Sum
Find Triplet Sum
Given a list of integers and a target value, your task is to find any triplet (three numbers from the list) such that the sum of the triplet is equal to the target value. Formally, given an array \(nums\) of length \(n\) and an integer \(target\), find three distinct indices \(i, j, k\) (with \(i < j < k\)) such that:
[ nums[i] + nums[j] + nums[k] = target ]
If there are multiple valid triplets, you can output any one of them. If no such triplet exists, output an empty list represented as []
.
Note: You are required to read the input from standard input (stdin) and write the output to standard output (stdout).
inputFormat
The input contains three lines:
- An integer \(n\) representing the number of elements in the list.
- A single line with \(n\) space-separated integers representing the list \(nums\).
- An integer \(target\) representing the target sum.
outputFormat
If a valid triplet is found, output the three integers separated by a single space in one line. If no such triplet exists, output []
(without quotes).
5
1 2 3 4 5
9
1 3 5