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
""" | |
Delete Node at a given position in a linked list | |
Node is defined as | |
class Node(object): | |
def __init__(self, data=None, next_node=None): | |
self.data = data | |
self.next = next_node |
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
""" | |
Insert Node at a specific position in a linked list | |
head input could be None as well for empty list | |
Node is defined as | |
class Node(object): | |
def __init__(self, data=None, next_node=None): | |
self.data = data | |
self.next = next_node |
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
C = raw_input() | |
M = raw_input() | |
C1 = int(C.split(' ')[0]) | |
C2 = int(C.split(' ')[1]) | |
ways = [1]+[0] * C1 | |
for coin in M.split(' ')[:C2]: | |
coin = int(coin) | |
for i in range(coin, C1+1): |
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
def factorial(n): | |
if n == 0: | |
return 1 | |
else: | |
return n * factorial(n-1) | |
def main(): | |
i = raw_input() | |
try: |
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
N = int(raw_input()) | |
for i in range(1, N + 1): | |
str = '' | |
if i % 3 == 0: | |
str = 'Fizz' | |
if i % 5 == 0: | |
str += 'Buzz' | |
if str == '': | |
str = i | |
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
open_symbols = ['(', '{', '['] | |
close_symbols = [')', '}', ']'] | |
def main(): | |
symbols = raw_input() | |
opened_once = False | |
open_list = [] | |
close_list = [] |
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
def main(): | |
values = map(int, raw_input().split(',')) | |
return reduce(lambda x, y: x ^ y, values) | |
print main() | |
# Because ^ (XOR) returns 0 for each pair and there is only one unpaired item in the input. | |
# E.g. | |
# 1 ^ 1 = 0 |
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
def fib(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b | |
def main(i=0): | |
if i is 0: | |
return 0 |
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
class Node: | |
def __init__(self, data): | |
self.data = data | |
self.next = None | |
self.prev = None | |
class LinkedList: | |
def __init__(self): | |
self.root = None |
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
def fib(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b | |
def main(): | |
i = int(raw_input()) | |
if i is 0: |