Skip to content

Commit

Permalink
Merge pull request #335 from Mayur-Pagote/main
Browse files Browse the repository at this point in the history
Added GFG solutions
  • Loading branch information
PRIYESHSINGH24 authored Jan 19, 2025
2 parents bbd4e92 + ca99305 commit f9490e2
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Geeks For Geeks/Palindromic Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def PalinArray(arr):
for i in arr:
s = str(i)
rev = s[::-1]
if s != rev:
return False
return True
7 changes: 7 additions & 0 deletions Geeks For Geeks/Play With OR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def game_with_number (self, arr, n):
l = []
for i in range(n-1):
l.append(arr[i] | arr[i+1])
l.append(arr[-1])
return l
6 changes: 6 additions & 0 deletions Geeks For Geeks/Prime Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution:
def isPrime(self, n):
for i in range(2, n):
if n % i == 0:
return False
return True
4 changes: 4 additions & 0 deletions Geeks For Geeks/Print Elements of Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Solution:
def printArray(self, arr):
for i in arr:
print(i, end=" ")
7 changes: 7 additions & 0 deletions Geeks For Geeks/Repeated IDs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def uniqueId(self, arr):
l = []
for i in arr:
if i not in l:
l.append(i)
return l
10 changes: 10 additions & 0 deletions Geeks For Geeks/Replace all 0's with 5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def convertFive(self, n):
num = ""
s = str(n)
for i in s:
if i == "0":
num = num+"5"
else:
num=num+i
return int(num)
3 changes: 3 additions & 0 deletions Geeks For Geeks/Reverse a String.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution:
def reverseString(self, s: str) -> str:
return s[::-1]
5 changes: 5 additions & 0 deletions Geeks For Geeks/Rotate Array by One.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Solution:
def rotate(self, arr):
value = arr.pop()
arr.insert(0,value)
return arr
6 changes: 6 additions & 0 deletions Geeks For Geeks/Rotating an Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution:
def leftRotate(self, arr, d):
n = len(arr)
d = d % n
arr[:] = arr[d:] + arr[:d]
return arr
7 changes: 7 additions & 0 deletions Geeks For Geeks/Searching a number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import List
class Solution:
def search(self, k: int, arr: List[int]) -> int:
if k in arr:
return arr.index(k)+1
else:
return -1
6 changes: 6 additions & 0 deletions Geeks For Geeks/Sum of Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution:
def arraySum(self, arr):
value = 0
for i in arr:
value += i
return value
9 changes: 9 additions & 0 deletions Geeks For Geeks/Third largest element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution:
def thirdLargest(self,arr):
arr.sort()
if len(arr) == 2:
return arr[-1]
elif len(arr) == 1:
return arr[0]
elif len(arr)>=3:
return arr[-3]
4 changes: 4 additions & 0 deletions Geeks For Geeks/Union of Two Arrays with Distinct Elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Solution:
def findUnion(self, a, b):
union_set = set(a) | set(b)
return sorted(union_set)
7 changes: 7 additions & 0 deletions Geeks For Geeks/Value equal to index value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def valueEqualToIndex(self, arr):
l=[]
for i in range(len(arr)):
if i+1 == arr[i]:
l.append(i+1)
return l

0 comments on commit f9490e2

Please sign in to comment.