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 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)) |
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
# 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 |
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
# 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; |
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(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): |
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(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): |
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(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): |
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
# 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) |
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 Stack(object): | |
def __init__(self): | |
self.list = [] | |
# push | |
def push(self,data): | |
self.list.append(data) | |
# pop | |
def pop(self): |
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 Queue(object): | |
def __init__(self): | |
self.list = [] | |
#enque | |
def enqueue(self,data): | |
self.list.insert(0,data) | |
# deque | |
def dequeue(self): |
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
# 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 = [] | |
OlderNewer