Find Triplet with Given Sum in an Array

Find triplet with given sum in an array.

Given an array of unsorted integers and a value k. Write a code to determine whether or not there exist three elements in array whose sum is equal to k.

Return true if triplet exist else return false.

For example:

Example 1:

Input: {1, 4, 45, 6, 10, 8} k = 13 Output: true (1, 4, 8)

Example 2:

Input: {2, 7, 4, 0, 9, 5, 1, 3} k = 6
Output: true {(2, 4, 0), (5, 1, 0), (1, 2, 3)}

Remove Duplicates from Unsorted Array

Given an unsorted array of integers. Write a code to remove duplicates from unsorted array.

For example:

Input   :{5, 1, 2, 6, 4, 4, 5}
Output :{5, 1, 2, 6, 4}

In this example, 4 and 5 appear multiple times in an input array.

In the output, All the duplicates are removed and we have printed only distinct elements of an array.