- Arrays

Check if there exists a pair (a, b) such that for all the N pairs either of the element should be equal to either a or b

#include using namespace std;  string CommonPairs(int N, vector arr){    vector V = { arr[0].first, arr[0].second };      for (int x : V) {                  vector frequency(N + 1, 0);                                  int counter = 0;                  for (auto c : arr) {                                    if (c.first != x && c.second != x) {                                                  frequency[c.first]++;                frequency[c.second]++;                                  counter++;            }        }          int M = *max_element(frequency.begin(),                             frequency.end());                  if (M == counter) {            return “Yes”;        }    }          return “No”;}  int main(){        vector arr        = { { 1, 2 }, { 2, 3 }, { 3, 4 }, { 4, 5 } };    int N = arr.size();          cout