is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
#include <list>
- ashwinvx June 14, 2011#include <iostream>
using namespace std;
int main()
{
int intarray[]={2,4,5,3,7,8};
list<int> mylist;
list<int>::iterator it;
list<int>::reverse_iterator rit;
mylist.assign(intarray,intarray+6);//assiging the numbers from the given array.
int first=0;
int last=mylist.size()-1;
mylist.sort();//sorting the list.
cout<<"Enter the target number"<<endl;
int targetsum;
cin>>targetsum;
it=mylist.begin();
rit=mylist.rbegin();
while(first<last)
{
if((*it)+(*rit)<targetsum)
{
it++;
first++;
}
else if((*it)+(*rit)>targetsum)
{
rit++;
last--;
}
else
{
cout<<"Pair-->"<<(*it)<<":"<<(*rit)<<endl;
cout<<"Pair-->"<<(*rit)<<":"<<(*it)<<endl;
it++;
rit++;
first++;
last--;
}
}
/*for(it=mylist.begin();it!=mylist.end();it++)
{
cout<<*it<<endl;
}*/
}
------------------------------------------------------------------------------------------------------------------------------
Output:
Enter the target number
7
Pair-->2:5
Pair-->5:2
Pair-->3:4
Pair-->4:3
Sorting in the worst case takes O(nlog n)
Printing the pairs of numbers takes O(n)
Duplicate values are printed only once.