Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Hackerrank Python Programs #435

Merged
merged 4 commits into from
Oct 31, 2021
Merged
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
26 changes: 26 additions & 0 deletions python/Array_Manipulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Complete the 'arrayManipulation' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. 2D_INTEGER_ARRAY queries
#

def arrayManipulation(n, queries):
arr = [0]*(n+1)
max_value = 0
total_sum = 0

for query in queries:
l = query[0]
h = query[1]
val = query[2]
arr[l-1] = arr[l-1] + val
arr[h] = arr[h]-val

for value in arr:
total_sum = total_sum + value
max_value = max(max_value, total_sum)

return max_value
4 changes: 4 additions & 0 deletions python/Jewels_and_stones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test = int(input())
for _ in range(test):
x,y = input().split()
print(sum([x.count(i) for i in y]))
16 changes: 16 additions & 0 deletions python/Pairs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Complete the 'pairs' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER k
# 2. INTEGER_ARRAY arr
#

def pairs(k, arr):
counter = 0
set_arr = set(arr)
for val in arr:
if val + k in set_arr:
counter += 1
return counter
18 changes: 18 additions & 0 deletions python/Sherlock_and_Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Complete the 'balancedSums' function below.
#
# The function is expected to return a STRING.
# The function accepts INTEGER_ARRAY arr as parameter.
#

def balancedSums(arr):
sum_arr = sum(arr)
l = len(arr)
lefty = 0
for i in range(len(arr)):
current = arr[i]
sum_arr -= current
if lefty == sum_arr:
return 'YES'
lefty += current
return 'NO'