#K35582. Three Sum Target

    ID: 25563 Type: Default 1000ms 256MiB

Three Sum Target

Three Sum Target

Given an array of distinct integers and an integer target, determine whether there exist exactly three numbers in the array such that their sum equals the target. In other words, check if there exist indices i, j, k (all distinct) satisfying $$nums_i + nums_j + nums_k = target$$.

An efficient solution is expected (better than an O(n3) brute-force solution). A common approach is to first sort the array and then use a two-pointer technique for each fixed element.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains space-separated integers representing the array (nums).
  2. The second line contains a single integer representing the target value.

outputFormat

The output should be written to stdout. Print True (case-sensitive) if there exists exactly three numbers in the array whose sum equals the target; otherwise, print False.## sample

1 2 3 4 5
9
True