-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem70.cpp
More file actions
58 lines (49 loc) · 1.14 KB
/
problem70.cpp
File metadata and controls
58 lines (49 loc) · 1.14 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
class DrugPacketNesting {
int N;
vector<int> packets;
public:
void readInput() {
cout << "Enter number of packets: ";
cin >> N;
if (N < 1 || N > 1e5) {
cout << "!! Invalid Input !!" << endl;
exit(1);
}
cout << "Enter the highness values (space-separated): ";
packets.resize(N);
for (int i = 0; i < N; i++) {
cin >> packets[i];
if (packets[i] < 1 || packets[i] > 1e4) {
cout << "!! Invalid Input !!" << endl;
exit(1);
}
}
}
int findMinPacketsToSmuggle() {
sort(packets.begin(), packets.end());
// Count frequency of each highness value
int ans = 0;
int count = 1;
for (int i = 1; i < N; i++) {
if (packets[i] == packets[i - 1]) {
count++;
} else {
ans = max(ans, count);
count = 1;
}
}
ans = max(ans, count); // check last frequency too
return ans;
}
void display() {
cout << "Minimum packets to smuggle: " << findMinPacketsToSmuggle() << endl;
}
};
int main() {
DrugPacketNesting dpn;
dpn.readInput();
dpn.display();
return 0;
}