diff --git a/Arrays/reversePairs.cpp b/Arrays/reversePairs.cpp new file mode 100644 index 0000000..e5ea0d6 --- /dev/null +++ b/Arrays/reversePairs.cpp @@ -0,0 +1,32 @@ +/* Problem Statement : Given an integer array nums, +return the number of reverse pairs in the array. +A reverse pair is a pair (i, j) where: +--> 0 <= i < j < nums.length and +--> nums[i] > 2 * nums[j]. */ + + +#include +using namespace std; + + int reversePairs(vector < int > & arr) { + int Pairs = 0; + for (int i = 0; i < arr.size(); i++) { + for (int j = i + 1; j < arr.size(); j++) { + if (arr[i] > 2 * arr[j]) Pairs++; + } + } + return Pairs; + } + + +int main() +{ + int n; + cin>>n; + vector arr(n); + for(int i=0;i>arr[i]; + } + cout<