使用C++编写代码,找到具有相同最小值和最大值的子数组的数量

使用C++编写代码,找到具有相同最小值和最大值的子数组的数量

在本文中,我们将使用C++解决寻找最大值和最小值相同的子数组数量的问题。以下是该问题的示例−

Input : array = { 2, 3, 6, 6, 2, 4, 4, 4 } Output : 12 Explanation : {2}, {3}, {6}, {6}, {2}, {4}, {4}, {4}, {6,6}, {4,4}, {4,4} and { 4,4,4 } are the subarrays which can be formed with maximum and minimum element same. Input : array = { 3,3,1,5,1,2,2 } Output : 9 Explanation : {3}, {3}, {1}, {5}, {1}, {2}, {2}, {3,3} and {2,2} are the subarrays which can be formed with minimum and maximum are the same.登录后复制