06. Happiest Triplet
β GFG solution to the Happiest Triplet problem: find the triplet with minimum difference across three arrays using three-pointer technique. π
π§© Problem Description
π Examples
Example 1
Input: a[] = [5, 2, 8], b[] = [10, 7, 12], c[] = [9, 14, 6]
Output: [7, 6, 5]
Explanation: The triplet [5, 7, 6] has difference (maximum - minimum) = (7 - 5) = 2
which is minimum of all triplets.Example 2
Input: a[] = [15, 12, 18, 9], b[] = [10, 17, 13, 8], c[] = [14, 16, 11, 5]
Output: [11, 10, 9]
Explanation: Multiple triplets have the same minimum difference, and among them
[11, 10, 9] has the smallest sum, so it is chosen.π Constraints
β
My Approach
Three Pointers Algorithm
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated