Not able to figure out where I went wrong

I have tried with multiple test cases, both positive and negative, but still hidden test cases are not passing.

#include <iostream>
using namespace std;

bool search(int arr[], int n, int x){
  for(int i = 0; i < n; i++){
    if(arr[i] == x){
      return true;
    }
  }
  return false;
}

int find_index(int arr[], int n, int x){
  for(int i = 0; i < n; i++){
    if(arr[i] == x){
      return i;
    }
  }
  return -1;
}

int main() {
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++){
    cin >> arr[i];
  }
  int k;
  cin >> k;
  int seen_arr[n];
  for(int i = 0; i < n; i++){
    seen_arr[i] = 0;
  }
  int index = 0;
  for(int i = 0; i < n; i++){
    int x = k - arr[i];
    if(search(seen_arr, index, x) && (find_index(arr, n, x) != i)){
      cout << min(x, arr[i]) << " and " << max(x, arr[i]) << endl;
    }
    else{
      seen_arr[index] = arr[i];
      index++;
    }
  }
  return 0;
}

hi @sreekark99_f88bfac86488335f refer
https://ide.codingblocks.com/s/675175

Hi, I see you have used two loops to check all combinations and for each, we see if sum is equal to target or not.
I have used hashing approach, but I do not yet know how to implement hashmap in C++, so I have used arrays for this program. For each number, I see if the difference value (target - curr_element) is already visited or not, by storing them in a seperate array. If yes, it will return both of the values. I am not able to understand why it is failing in some test cases, can you help me understand the edge cases.

hi @sreekark99_f88bfac86488335f do u know 2 pointer technique? it can be done easily using that in an optimised way

Hi, yes I know 2 pointer technique and have used it, thanks!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.