-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from Mayur-Pagote/main
Added GFG solutions
- Loading branch information
Showing
7 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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) |
This file contains 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
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 |