Skip to content

Instantly share code, notes, and snippets.

View i143code's full-sized avatar

ashish ranjan i143code

  • Boston, MA
View GitHub Profile
@i143code
i143code / Arrays: Left Rotation.py
Last active May 31, 2017 19:29
Rotate Array 3d created by i143code - https://repl.it/I0JP/33
def array_left_rotation(a, k):
array_length = len(a)
new_array = [0 for _ in range(array_length)]
# print(new_array)
for i in range(array_length):
index = (i + k) % array_length
# print(index)
new_array[i] = a[index]
return ' '.join(map(str, new_array))
@i143code
i143code / I0Oc-11.py
Created May 31, 2017 19:54
null created by i143code - https://repl.it/I0Oc/11
# Write a method that replaces all spaces in a string with 20%
#" a b c" will be "a%20b%20c"
def unique_string(s):
new_string = '';
start = False
for c in reversed(s):
if ( c != ' '):
start = True
@i143code
i143code / permutations.py
Last active May 31, 2017 21:40
Permetation created by i143code - https://repl.it/I0Zl/1
# Checking if two strings are permutations of each other in Python
def permutation(s1,s2):
if len(s1) != len(s2):return False;
return ' '.join(sorted(s1)) == ' '.join(sorted(s2))
print(permutation("ashish","shisha1"))
def permutation1(s1,s2):
if len(s1) != len(s2):return False;
@i143code
i143code / LinkedList.py
Last active June 11, 2017 16:04
null created by i143code - https://repl.it/IgUE/14
class Node(object):
def __init__(self,data,next):
self.data = data;
self.nextNode = next;
class Linked_list(object):
head = None;
tail = None;
# first in the list
def append(self,data):
@i143code
i143code / IgUE-22.py
Created June 11, 2017 16:44
null created by i143code - https://repl.it/IgUE/22
class Node(object):
def __init__(self,data,next):
self.data = data;
self.nextNode = next;
class Linked_list(object):
head = None;
tail = None;
# add at the end
def append(self,data):
@i143code
i143code / LinkedList.py
Last active June 30, 2017 21:45
null created by i143code - https://repl.it/IgUE/23
class Node(object):
def __init__(self,data,next):
self.data = data;
self.nextNode = next;
class Linked_list(object):
head = None;
tail = None;
# add at the end
def append(self,data):
@i143code
i143code / Unique String.py
Created June 16, 2017 17:06
Unique String created by i143code - https://repl.it/Iozl/4
# remove deuplicates from string
def RemoveDuplicate(s):
new_string = [];
seen = set();
for c in s:
if c not in seen:
seen.add(c)
new_string.append(c)
return ''.join(new_string)
@i143code
i143code / Stack.py
Created June 30, 2017 21:30
Stack created by i143code - https://repl.it/JJ0J/2
class Stack(object):
def __init__(self):
self.list = []
# push
def push(self,data):
self.list.append(data)
# pop
def pop(self):
@i143code
i143code / Queue.py
Created June 30, 2017 21:42
Queue created by i143code - https://repl.it/JJ0p/1
class Queue(object):
def __init__(self):
self.list = []
#enque
def enqueue(self,data):
self.list.insert(0,data)
# deque
def dequeue(self):
@i143code
i143code / Maximum Element Stack.py
Created July 1, 2017 15:24
Maximum Element Stack created by i143code - https://repl.it/JJxH/3
# 1 x -Push the element x into the stack.
# 2 -Delete the element present at the top of the stack.
# 3 -Print the maximum element in the stack.
class Stack(object):
def __init__(self):
self.list = []
self.maxima = []