- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum product of a triplet (subsequence of size 3) in array in C++
In this tutorial, we will be discussing a program to find maximum product of a triplet (subsequence of size 3) in array.
For this we will be provided with an array of integers. Our task is to find the triplet of elements in that array with the maximum product
Example
#include <bits/stdc++.h> using namespace std; //finding the maximum product int maxProduct(int arr[], int n){ if (n < 3) return -1; int max_product = INT_MIN; for (int i = 0; i < n - 2; i++) for (int j = i + 1; j < n - 1; j++) for (int k = j + 1; k < n; k++) max_product = max(max_product, arr[i] * arr[j] * arr[k]); return max_product; } int main() { int arr[] = { 10, 3, 5, 6, 20 }; int n = sizeof(arr) / sizeof(arr[0]); int max = maxProduct(arr, n); if (max == -1) cout << "No Triplet Exists"; else cout << "Maximum product is " << max; return 0; }
Output
Maximum product is 1200
- Related Articles
- Maximum product of a triplet (subsequence of size 3) in array in C++ Program.
- Maximum product of an increasing subsequence of size 3 in C++
- Maximum product of an increasing subsequence of size 3 in C++ program
- Maximum product of subsequence of size k in C++
- Maximum product of an increasing subsequence in C++
- Maximum product of an increasing subsequence in C++ Program
- Maximum product quadruple (sub-sequence of size 4) in array in C++
- Maximum triplet sum in array in C++
- Maximum product subset of an array in C++
- Increasing Triplet Subsequence in Python
- Find a sorted subsequence of size 3 in linear time in Python
- Maximum product subset of an array in C++ program
- Find a pair with maximum product in array of Integers in C++
- Find Maximum XOR value of a sub-array of size k in C++
- Maximum number of trailing zeros in the product of the subsets of size k in C++

Advertisements