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 <iostream> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
int kase; | |
cin>> kase; | |
for (int k = 1; k <= kase; k++) |
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=19300678 | |
If a=1, b=2, c=3,....z=26. Given a string, find all possible codes that string can generate. Give a count as well as print the strings. | |
For example: | |
Input: "1123". You need to general all valid alphabet codes from this string. | |
Output List | |
aabc //a = 1, a = 1, b = 2, c = 3 | |
kbc // since k is 11, b = 2, c= 3 |
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=12986664 | |
Push all the zero's of a given array to the end of the array. In place only. Ex 1,2,0,4,0,0,8 becomes 1,2,4,8,0,0,0 | |
*/ | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
void putZeroToEnd(vector<int> &vec) { | |
// i for next non-zero num index | |
// j for normal move forward index |
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 |
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=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=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
#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
#!/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
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 |
OlderNewer