[InterviewBit] Tushar`s Birthday Bombs

Tushar’s Birthday Bombs

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
vector<int> Solution::solve(int A, vector<int> &B) {
int mi = INT_MAX;
vector<int> cand;
unordered_map<int, int> mp;

for(int i = 0; i < B.size(); i++) {
if(B[i] < mi) {
mi = B[i];
cand.push_back(B[i]);
mp[B[i]] = i;
}
}

vector<int> res;
for(auto c : cand) {
while(c <= A) {
int now = A - c;
int ma = A / mi;
if(1 + now / mi == ma) {
res.push_back(mp[c]);
A -= c;
} else break;
}
}

return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/20/PS/interviewbit/tushars-birthday-bombs/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.