Skip to content

Commit

Permalink
Completed Sprint Design-5 - Please Review
Browse files Browse the repository at this point in the history
  • Loading branch information
manojvarmarudraraju committed Jul 23, 2021
1 parent 741f177 commit 71f4c80
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Time Complexity : O(1) for allocate,freespace anf available
# Space Complexity : O(n)
# Did this code successfully run on Leetcode : Yes
# Any problem you faced while coding this : No
from heapq import heappush as push
from heapq import heappop as pop
from heapq import heapify
class Parking:

def __init__(self,spaces,dist_map):
self.spaces = spaces
self.heap = []
self.dist_map = dist_map
heapify(self.heap)
for key in self.dist_map:
push(self.heap,(self.dist[key],key))

def allocate(self):
_,key = pop(self.heap)
return key


def freeSpace(self,key):
push(self.heap,(self.dist[key],key))


def available(self):
print(self.heap)

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

"""
# Definition for a Node.
class Node:
def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
self.val = int(x)
self.next = next
self.random = random
"""

#create a new node for every node and place it after original node then copy all the random pointers then remove the original nodes
class Solution:
def copyRandomList(self, head: 'Node') -> 'Node':
if head == None:
return head
node = head
while node != None:
dummy = Node(node.val)
nNode = node.next
node.next = dummy
dummy.next = nNode
node = nNode
node = head
while node != None:
if node.random == None:
node.next.random = None
else:
node.next.random = node.random.next
node = node.next.next
node = head.next
while node.next != None:
node.next = node.next.next
node = node.next
node = head.next


return head.next

0 comments on commit 71f4c80

Please sign in to comment.