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
34 changes: 34 additions & 0 deletions findminmax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# // Time Complexity : O(n)
# // Space Complexity : O(1)
# // Did this code successfully run on GeeksForGeeks : Yes
# // Any problem you faced while coding this : No

class Solution:
def getMinMax(self, arr):
# code here
n=len(arr)
if n%2==0:
start=2
if arr[0]>arr[1]:
min_e=arr[1]
max_e=arr[0]
else:
min_e=arr[0]
max_e=arr[1]
else:
start=1
min_e=arr[0]
max_e=arr[0]

i=start
while(i<n):
if (arr[i]>arr[i+1]):
min_e=min(min_e,arr[i+1])
max_e=max(max_e,arr[i])
else:
min_e=min(min_e,arr[i])
max_e=max(max_e,arr[i+1])
i+=2


return [min_e,max_e]
25 changes: 25 additions & 0 deletions findmissing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# // Time Complexity : O(n)
# // Space Complexity : O(1)
# // Did this code successfully run on Leetcode : Yes
# // Any problem you faced while coding this : No

class Solution(object):
def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
n=len(nums)
res=[]

for i in range(n):
ind = abs(nums[i])-1
if nums[ind]>0:
nums[ind]*=-1

for i in range(n):
if nums[i]>0:
res.append(i+1)


return res
39 changes: 39 additions & 0 deletions gameOfLife.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# // Time Complexity : O(m*n)
# // Space Complexity : O(1)
# // Did this code successfully run on Leetcode : Yes
# // Any problem you faced while coding this : NA
#
class Solution(object):
def gameOfLife(self, board):
"""
:type board: List[List[int]]
:rtype: None Do not return anything, modify board in-place instead.
"""
res=board
m=len(board)
n=len(board[0])
surround=[(0,-1),(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1)]

for i in range(m):
for j in range(n):
live_around=0
for s in surround:
r=i+s[0]
c=j+s[1]

if r<m and r>=0 and c<n and c>=0 and abs(board[r][c])==1:
live_around+=1

if board[i][j]==0 and live_around==3:
board[i][j]=2

if board[i][j]==1 and (live_around>3 or live_around<2):
board[i][j]*=-1

for i in range(m):
for j in range(n):
if board[i][j]<=0:
board[i][j]=0
else:
board[i][j]=1