If you consider the worse case where we add and remove alternatively, we perform 2 operations (one push and then one pop)
AFAIK The problem of O(n) lies with the use of ArrayList where the remove() takes O(n) to find the index.
This post was supposed to give a starting point for how the concept is done.
Can you walk through your process - maybe there's a more efficient way without adding complex logic?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A very good point.
If you consider the worse case where we add and remove alternatively, we perform 2 operations (one push and then one pop)
AFAIK The problem of O(n) lies with the use of ArrayList where the remove() takes O(n) to find the index.
This post was supposed to give a starting point for how the concept is done.
Can you walk through your process - maybe there's a more efficient way without adding complex logic?