Quantcast
Channel: Programming Archives - SysTutorials
Viewing all articles
Browse latest Browse all 130

A StoneWall Solution in C++

$
0
0

StoneWall is an interesting problem that requires some brain cycles yet not too complex. It is good software engineer interview question. Here is a C++ solution whose complexity is O(N). #include <stack> int solution(std::vector<int> &H) { int stones = 0; std::stack<int> heights; for (auto h: H) { while (!heights.empty() && h < heights.top()) { heights.pop(); […]

The post A StoneWall Solution in C++ is from SysTutorials.


Viewing all articles
Browse latest Browse all 130

Trending Articles