Skip to content

Instantly share code, notes, and snippets.

@krisys
krisys / BadNeighbors.cpp
Last active September 5, 2021 11:39
Bad Neighbors TopCoder
/* Update - Thanks to some folks who pointed out a flaw in my code.
* I have updated it. Hope it is correct now :-)
* Old version can be found here -
https://gist.github.com/krisys/4089748/262cbc10d9b9f1cb5df771e14a1e143a86d2ecc6/
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
@krisys
krisys / BalancedSmileys.cpp
Created January 30, 2013 04:45
Balanced Smileys - At any index, the number of closing brackets should be less than or equal to the number of opening brackets, if it is less, then the difference of closing brackets and opening brackets should be equal to the number of happy smileys. And a similar logic should be applied from the end considering the number of sad smileys.
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) FOR(i, 0, a)
#define all(a) a.begin(), a.end()
@krisys
krisys / BeautifulStrings.cpp
Created January 30, 2013 04:50
BeautifulStrings
#include <algorithm>
#include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) FOR(i, 0, a)
#define VI vector<int>
#define all(a) (a).begin(), (a).end()
using namespace std;
@krisys
krisys / FindTheMin.cpp
Last active June 13, 2019 06:48
FindTheMin
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) FOR(i, 0, a)
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))