Skip to content

Instantly share code, notes, and snippets.

View paldepind's full-sized avatar

Simon Friis Vindum paldepind

View GitHub Profile
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int lamps, opsToDo;
@paldepind
paldepind / gist:4662669
Last active December 11, 2015 21:28
C++ solution the problem "Balanced Smileys" in the Facebook Hackecup 2013. No stacks, no recursion. Complexity is O(n).
bool isBalanced(const string message) {
int paransOpen = 0;
int maybeOpen = 0;
int maybeClosed = 0;
char prevChar = 0;
string::const_iterator iter;
for (iter = message.begin(); iter < message.end(); iter++) {
if (*iter == '(') {
if (prevChar == ':') {