New answers tagged

2

Cancellation Token Source You create a token source, and then immediately overwrite it with a new instance, disregarding the previously created instance. Surely, you did not mean to instantiate it twice? _runningSubscriberCancellationTokenSource = new CancellationTokenSource(); _runningSubscriberCancellationTokenSource = CancellationTokenSource....


6

One thing not already mentioned in the answers: When you have a member function which does not change the state of the object, then make it const: // no void peek(){ cout<< s1.top()<<"\n"; } // better void peek() const { cout<< s1.top()<<"\n"; } // even better int peek() const { return s1.top(); }


20

Algorithmic complexity for combined operations Containers are interesting elements in most programming languages: they have an internal state, namely their elements and therefore their size. This introduces an additional state compared to usual algorithmic asymptotical complexity analysis. For example, a naive implemented std::vector::push_back will yield \...


8

You might want to look at the discussion tab for why the code is timing out. Basically the code should reverse the input stack only when peek or dequeue is called and not in enqueue. The rest of answer is a review of the code as posted and it ignores the fact that HackerRank supplied some of the code, such as the includes and the using namespace std. Issues ...


2

Not a thorough review, but two things jump out at me as problematic with ImmutableQueue: Your Reverse method looks wrong: it doesn't do anything if front isn't empty, and doesn't reverse if it isn't. I would have expected: let reverse () = ImmutableQueue(rear, front) There are no tests for this method. Some of the methods of ImmutableQueue seem to ...


Top 50 recent answers are included