feat. C++ Data Type and Methods
작년 11월 무려 AWS Redshft의 hiring manager로부터 LinkedIn을 통해 연락이 왔다. 그래서 나의 Resume(CV)를 보냈는데 연락이 없었다. 그래서 JobD가 맞지않나보다. 아쉽다 생각했다. 그러다 연초에 연락이 다시 왔다. 가볍게 챗을 하자고. 그래서 자기소개 겸 presentation을 했다.
아주 좋아했다. 그리고 인터뷰를 하자고 했다.
그래서 코딩인터뷰를 준비해야 되는 상황이 되었다. C++자격증 시험도 끝나고 해서 당분간은 토플 공부와 회사 업무에 집중해야지 하고 있었는데...
급하게 아는 분에게도 연락하고 LeetCode Amazon 빈출 문제를 최근 한달 이내로 검색해 리스트를 만들었다. Easy 35문제 & Medium 97문제 & Hard 24문제로 총 156문제였다. 아... 2주간 저 문제를 한번씩 다 보려면 하루에 10문제씩은 보아야겠구나. 한문제에 20분이라고 치면 200분, 즉, 3시간 20분은 걸리겠구나.
1. Data Type(C++STL Container)
a. queue: https://en.cppreference.com/w/cpp/container/queue
queue<int> q;
q.push(1); // 큐 뒤에 추가
q.push(2);
q.push(6);
q.front(); // 2
q.back(); // 6
q.pop(); // 큐 맨앞 원소 삭제
b. string:
c. vector: https://en.cppreference.com/w/cpp/container/vector
vector<int> v;
v.at(idx); // v[idx]보다 속도는 느리지만 범위 점검하므로 안전
v.front(); // 맨 안ㅍ의 원소 참조
v.back(); // 맨 뒤의 원소 참조
v.push_back(7);
v.pop_back(); // 뒤의 원소 제거
v.rbegin();
v.rend();
v.erase(iter);
d. pair:
e. unordered_map: https://en.cppreference.com/w/cpp/container/unordered_map
unordered_map<int,string> umap;
umap.insert({3, "banana"});
for (const auto& pair : umap) {
int key = pair.first;
string val = pair.second;
}
for (unordered_map::iterator iter = umap.begin(); iter != umap.end(); iter++) {
key = iter->first;
val = iter->second;
}
if (umap.find(key) != umap.end()) {
umap.erase(key);
}
f. map:
g. list: https://en.cppreference.com/w/cpp/container/list
list<int> a;
a.push_back(22);
a.push_front(11);
list<int>::iterator iter = a.begin();
for(iter = a.begin(); iter != a.end(); iter++) {
val = *iter;
}
a.pop_front(); // 리스트 맨 앞 제거
a.pop_back(); // 리스트 맨 뒤 제거
h. stack:
i. set:
j. unordered_set:
k. priority_queue: https://en.cppreference.com/w/cpp/container/priority_queue
가장 큰 값부터 출력
priority_queue<int> pq;
pq.push(4);
pq.push(10);
pq.push(7);
pq.top(); // 맨 위의 값 가져오기
pq.pop(); // 맨 위 원소 삭제
2. Function
a. sort
b.
3. 시간복잡도 관련 정리
1) map, set: 정렬되어 있음
데이터 추가 및 삭제: O(logN)
데이터 검색: O(logN)
2) unordered_map, unordered_set: hash 같은 --> 대용량 데이터에 유리
데이터 추가 및 삭제: 평균 O(1), 최악 O(N)
데이터 검색: 평균 O(1), 최악 O(N)
안녕.
끝!