From f7962756afd51f95a2c2446d065bfffcc56eff8c Mon Sep 17 00:00:00 2001 From: Instinctblaze <54744386+Instinctblaze@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:42:26 +0530 Subject: [PATCH] Create reversePairs.cpp --- Arrays/reversePairs.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Arrays/reversePairs.cpp 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<