hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

Šimon Tóth

Tuesday C++ common interview problem.

Implement a Max-Stack data structure that provides the following interface:
O(1) complexity methods: top() and max()
O(logn) complexity methods: push(), pop() and pop_max()

Solve it yourself: compiler-explorer.com/z/4bd3qG
Solution: compiler-explorer.com/z/8aTxGe

@simontoth Is throwing an std::vector at it a valid solution?

@Mek101 Well, yes, since you can do almost anything with a std::vector, but you will need a way to achieve O(logn).