Write a code for "Two-pair Sum". You can find the question by searching two-pair sum in Leetcode
Kartik Ghai
1y
// https://leetcode.com/problems/two-sum/
#include<bits/stdc++.h>
using namespace std;
pair<int, int> targetSum(int arr[], int t, int n){
unordered_map<int, int> mp;
pair<int, int> ans;
for(int i=0; i<=n; i++){
if(t-arr[i]== arr[mp[t-arr[i]]] && i !=mp[t-arr[i]] ){
ans.first= mp[t- arr[i]];
ans.second= i;
return ans;
}
if(i==n)
break;
mp[arr[i]]=i;
}
return ans;
}
int main(){
int arr[]={3,3};
pair<int, int> ans= targetSum(arr, 6,2);
cout<<ans.first<<" "<<ans.second;
}
Help your peers!
Add answer anonymously...
Top Cubastion Consulting Graduate Engineer Trainee (Get) interview questions & answers
Popular interview questions of Graduate Engineer Trainee (Get)
Top HR questions asked in Cubastion Consulting Graduate Engineer Trainee (Get)
>
Cubastion Consulting Graduate Engineer Trainee (Get) Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app