Skip to content

Instantly share code, notes, and snippets.

View joybro's full-sized avatar

Young Lee joybro

  • Coupang.com
  • Seoul, Korea
View GitHub Profile
// http://www.geeksforgeeks.org/median-of-stream-of-integers-running-integers/
// Time complexity : O(nlogn)
// Space complexity : O(n)
#include <assert.h>
#include <queue>
class Median {
public:
// http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/
#include <assert.h>
#include <stdio.h>
#include <stack>
class Node {
public:
Node(int v)
: value(v),
// http://www.geeksforgeeks.org/print-postorder-from-given-inorder-and-preorder-traversals/
#include <assert.h>
#include <stdio.h>
int find(int *array, int n, int value) {
for (int i = 0; i < n; i++) {
if (array[i] == value) return i;
}
// http://codercareer.blogspot.kr/2013/02/no-44-maximal-stolen-values.html
#include <algorithm>
#include <assert.h>
#include <cstring>
#define MAX_CACHE 100
int maxStolenValueUtil(const int *values, int length, int idx, int *cache) {
if (idx >= length) return 0;
// http://www.geeksforgeeks.org/longest-palindromic-substring-set-2/
#include <algorithm>
#include <assert.h>
#include <string.h>
int length_pal(const char *str) {
int len = strlen(str);
int maxlen = 1;
// http://www.geeksforgeeks.org/longest-palindrome-substring-set-1/
#include <assert.h>
#include <string.h>
#define MAX_LEN 100
bool cache[MAX_LEN][MAX_LEN];
int length_pal(const char *str) {
// http://www.geeksforgeeks.org/check-if-a-given-binary-tree-is-complete-tree-or-not/
#include <assert.h>
#include <queue>
class Node {
public:
Node(int v)
: value(v),
left(0),
// http://www.geeksforgeeks.org/topological-sorting/
#include <stdio.h>
#include <vector>
class Graph {
public:
Graph(int nodes) :
nodeCount(nodes) {
edges = new std::vector<int>[nodes];
// http://www.geeksforgeeks.org/majority-element/
// It is assumed that all numbers in array are positive.
#include <assert.h>
int count(int *array, int start, int end, int num) {
int c = 0;
for (int i = start; i <= end; i++) {
if (array[i] == num) c++;
// A solution for http://codercareer.blogspot.kr/2011/09/no-03-maximum-sum-of-all-sub-arrays.html
// It is assumed that there is at least one positive number in the array.
#include <algorithm>
#include <assert.h>
#include <string.h>
#define LEN 10
int cache[LEN];