This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TCP Client (Java NIO) | |
// A minimalistic Java NIO TCP client. Stays always connected. Disconnects and reconnects on any exception in the event handlers (onConnect, onDisconnect, onRead). | |
package net.bobah.nio; | |
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.net.SocketAddress; | |
import java.nio.ByteBuffer; | |
import java.nio.channels.ReadableByteChannel; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <string> | |
#include <iostream> | |
#include <cassert> | |
using namespace std; | |
/* | |
BigInt multiply. Use uchar array to store the binary representation. | |
1. It should be unsigned char (not char); | |
2. Use carry, and do multiply/add iteratively, this could avoid overflow; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://www.hackerrank.com/contests/w5/challenges/kundu-and-tree | |
*/ | |
#include <cstring> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
#define MAX_N 100010 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
from string import replace,find,lower | |
from htmllib import HTMLParser | |
from urllib import urlretrieve, urlopen | |
from urlparse import urlparse,urljoin | |
from formatter import DumbWriter,AbstractFormatter | |
from cStringIO import StringIO | |
from codecs import open | |
import re |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
from sys import argv | |
from string import replace,find,lower | |
from htmllib import HTMLParser | |
from urllib import urlretrieve, urlopen | |
from urlparse import urlparse,urljoin | |
from formatter import DumbWriter,AbstractFormatter | |
from cStringIO import StringIO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <fstream> | |
#include <iostream> | |
using namespace std; | |
struct ListNode { | |
int val; | |
ListNode *next; | |
ListNode(int _val) { | |
val = _val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://www.careercup.com/question?id=15645665 | |
Find the k'th largest element in a binary search tree. | |
*/ | |
#include <stack> | |
#include <iostream> | |
using namespace std; | |
struct Node { | |
int val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://www.careercup.com/question?id=9820788 | |
there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on.. | |
It looks something like this | |
1 | |
2 3 | |
4 5 6 | |
every cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the cups and so on. | |
Now given C and M .Find the amount of water in ith cup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://www.careercup.com/question?id=23594662 | |
Given a sequence of numbers A(1) ..A(n), find the continuous subsequenceA(i)..A(j) for which the sum of elements is maximum. | |
condition: we should not select two contiguous numbers | |
Solution: | |
Dp: F[i] = max(A[i], A[i] + F[i-2], F[i-1]) | |
*/ | |
#include <vector> | |
#include <iostream> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://www.careercup.com/question?id=12718665 | |
String Reduction | |
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this operation repeatedly? | |
Sample Input: | |
cab | |
bcab | |
ccccc |