Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions python_implemented/kadanes_algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from sys import maxsize

def maxSubArraySum(a, size):
max_so_far = -maxsize - 1
max_ending_here = 0
start = 0
end = 0
s = 0

for i in range(0, size):

max_ending_here += a[i]

if max_so_far < max_ending_here:
max_so_far = max_ending_here
start = s
end = i

if max_ending_here < 0:
max_ending_here = 0
s = i + 1

print ("Maximum contiguous sum is %d" % (max_so_far))
print ("Starting Index %d" % (start))
print ("Ending Index %d" % (end))


# Driver program to test maxSubArraySum
a = [-2, -3, 4, -1, -2, 1, 5, -3]
maxSubArraySum(a, len(a))
46 changes: 46 additions & 0 deletions python_implemented/remove_duplicates_from_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Python program to remove duplicate characters from an
# input string
NO_OF_CHARS = 256


# Since strings in Python are immutable and cannot be changed
# This utility function will convert the string to list
def toMutable(string):
List = []
for i in string:
List.append(i)
return List


# Utility function that changes list to string
def toString(List):
return ''.join(List)


# Function removes duplicate characters from the string
# This function work in-place and fills null characters
# in the extra space left
def removeDups(string):
bin_hash = [0] * NO_OF_CHARS
ip_ind = 0
res_ind = 0
temp = ''
mutableString = toMutable(string)

# In place removal of duplicate characters
while ip_ind != len(mutableString):
temp = mutableString[ip_ind]
if bin_hash[ord(temp)] == 0:
bin_hash[ord(temp)] = 1
mutableString[res_ind] = mutableString[ip_ind]
res_ind += 1
ip_ind += 1

# After above step string is stringiittg.
# Removing extra iittg after string
return toString(mutableString[0:res_ind])


# Driver program to test the above functions
string = "amulyasahoo"
print removeDups(string)