#include <stdio.h> #include <bits/stdc++.h> #include <vector> #include <unordered_map> using namespace std; vector<int> twoSum(vector<int>& nums, int target) { unordered_map <int, int> mymap; vector <int> result; for(int i=0; i<nums.size(); i++){ if(mymap.find(target-nums[i])==mymap.end()) mymap[nums[i]]=i; if(mymap.find(target-nums[i])!=mymap.end()){ if(mymap[target-nums[i]]!=i){ result.push_back(mymap[target-nums[i]]); result.push_back(i); } } } return result; } int main() { int n; cin>>n; vector<int>array1; int target; cin>>target; for(int i=0; i<n; i++){ int num; cin>>num; array1.push_back(num); } vector<int>result; result=twoSum(array1, target); for(auto g: result) cout<<g<<" "; return 0; } Final answer Output of the program : 4 10 4 6 11 16 01