Skip to content

Commit

Permalink
Merge pull request #178 from Mayur-Pagote/main
Browse files Browse the repository at this point in the history
Added GFG solutions
  • Loading branch information
PRIYESHSINGH24 authored Jan 15, 2025
2 parents 23850dc + 75dcd3e commit 51fa6d7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Geeks For Geeks/Alternates in an Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def getAlternates(self, arr):
l = []
for i in range(len(arr)):
if i%2==0:
l.append(arr[i])
return l
13 changes: 13 additions & 0 deletions Geeks For Geeks/Array Duplicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def findDuplicates(self, arr):

seen = set()
duplicates = []

for num in arr:
if num in seen:
duplicates.append(num)
else:
seen.add(num)

return duplicates
5 changes: 5 additions & 0 deletions Geeks For Geeks/Array Search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Solution:
def search(self,arr, x):
if x in arr:
return arr.index(x)
return -1
8 changes: 8 additions & 0 deletions Geeks For Geeks/Array Subset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def isSubset(self, a, b):
set_a = set(a)

for element in b:
if element not in set_a:
return False
return True
8 changes: 8 additions & 0 deletions Geeks For Geeks/At least two greater elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def findElements(self,arr):
for i in range(2):
val1 = max(arr)
arr.remove(val1)

arr.sort()
return arr
7 changes: 7 additions & 0 deletions Geeks For Geeks/Balanced Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def min_value_to_balance(self, arr):
x = int(len(arr) / 2)
left = arr[:x]
right = arr[x:]
res = sum(left) - sum(right)
return abs(res)
5 changes: 5 additions & 0 deletions Geeks For Geeks/Check Equal Arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Solution:
def check(self, arr1, arr2) -> bool:
arr1.sort()
arr2.sort()
return arr1==arr2

0 comments on commit 51fa6d7

Please sign in to comment.