File tree Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ typedef long long ll ;
6+ const ll INF=1e18 ;
7+ const ll mod1=1e9 +7 ;
8+ const ll mod2=998244353 ;
9+ // Add main code here
10+
11+ // method 1
12+ class SmallestInfiniteSet
13+ {
14+ public:
15+ set<int > s;
16+ int current;
17+ SmallestInfiniteSet ()
18+ {
19+ current=1 ;
20+ }
21+
22+ int popSmallest ()
23+ {
24+ if (s.size ()){
25+ int temp=*s.begin ();
26+ s.erase (s.begin ());
27+ return temp;
28+ }
29+ else {
30+ return current++;
31+ }
32+ }
33+
34+ void addBack (int num)
35+ {
36+ if (num<current){
37+ s.insert (num);
38+ }
39+ }
40+ };
41+
42+ // method 2
43+ // class SmallestInfiniteSet
44+ // {
45+ // public:
46+ // set<int> s;
47+ // SmallestInfiniteSet()
48+ // {
49+ // for (int i = 1; i <= 2000; i++)
50+ // {
51+ // s.insert(i);
52+ // }
53+ // }
54+
55+ // int popSmallest()
56+ // {
57+ // int temp = *s.begin();
58+ // s.erase(s.begin());
59+ // return temp;
60+ // }
61+
62+ // void addBack(int num)
63+ // {
64+ // s.insert(num);
65+ // }
66+ // };
67+
68+ /* *
69+ * Your SmallestInfiniteSet object will be instantiated and called as such:
70+ * SmallestInfiniteSet* obj = new SmallestInfiniteSet();
71+ * int param_1 = obj->popSmallest();
72+ * obj->addBack(num);
73+ */
You can’t perform that action at this time.
0 commit comments