leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit285ad319ff62d64c3a600b92b6e8fda8ff569ba1
parent302f7016844ad2070113f4bf23dcd44fdebff7b1
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateMon, 23 Dec 2024 12:07:17 +0100

1 Random Problem

Diffstat:
AProblems/0895.cpp|+++++++++++++++++++
MREADME.md|+

2 files changed, 20 insertions(+), 0 deletions(-)


diff --git a/Problems/0895.cpp b/Problems/0895.cpp

@@ -0,0 +1,19 @@

class FreqStack {
unordered_map<int, int> count;
vector<int> track[20001];
int maxi = 0;
public:
void push(int val) {
const int cnt = ++count[val];
track[cnt].push_back(val);
maxi = max(maxi, cnt);
}
int pop() {
const int res = track[maxi].back();
track[maxi].pop_back();
if (track[count[res]--].empty()) maxi--;
return res;
}
};

diff --git a/README.md b/README.md

@@ -649,6 +649,7 @@ reference and a base for solving problems.

| 0890 | Medium | [Find and Replace Pattern](Problems/0890.cpp) |
| 0893 | Medium | [Groups of Special-Equivalent Strings](Problems/0893.cpp) |
| 0894 | Medium | [All Possible Full Binary Trees](Problems/0894.cpp) |
| 0895 | Hard | [Maximum Frequency Stack](Problems/0895.cpp) |
| 0896 | Easy | [Monotonic Array](Problems/0896.cpp) |
| 0897 | Easy | [Increasing Order Search Tree](Problems/0897.cpp) |
| 0900 | Medium | [RLE Iterator](Problems/0900.cpp) |