Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.
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
26 changes: 26 additions & 0 deletions Q1/solution.py
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
## Add code below with answer clearly stated
def factorial(num):
if num < 0: #if given number is negative or zero its a invalid number
print("Not Defined!!!")
return None
elif num==1 or num== 0:
return 1
else:
var = 1
for i in range(1, num):
var *= i
return var
## The above function will be used to calculate the factorial of given number.
def sum_factorial(num):
if num < 1: #if given number is negative or zero its a invalid number
print("Invalid Value!!!")
return None
if num == 1:
return 1
else:
fact_num = factorial(n) # calculate the factorial of tgiven number
var = 0 # initiallize a veriable
for i in str(fact_num): #First convert the number to string to iteratively choose one digit from the output
var += int(i) # add that number to the Var that is initially zero
return var

print("The sum of factorial is ", sum_factorial(100))
20 changes: 20 additions & 0 deletions Q2/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,24 @@
# self.next = next
class Solution:
def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
temp = head
c = 0
while temp: #Find the length of the linked list
c+=1
temp = temp.next
a = c-n+1 #Calculate the node to be removed
i = 1
temp2 = head
prev = None
while i < a: #Traverse till the node to be removed
i+=1
prev = temp2 #Prev pointer to point the previous node of the deletion node
temp2 = temp2.next
if temp2==head:
return head.next
prev.next = temp2.next #Link the previous node to the next of the deletion node
return head


# I've done this problem already 0n 02/21/2022 17:58 at that time my submission was faster than 97% people at leetcode.
# Myprofile link : https://leetcode.com/umikhaan/
46 changes: 46 additions & 0 deletions Q3/solution.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
if len(nums1+nums2)%2!=0: # check the length of the solution
return sorted((nums1+nums2))[len(nums1+nums2)//2]/1 # Simple code to return the median if the length is odd
else:
return sum(sorted((nums1+nums2))[(len(nums1+nums2)//2)-1:(len(nums1+nums2)//2)+1])/2 # Simple code to return the median if the length is even.
#It is not efficient code. but easy to understand and simplest approach to my knowledge.


# in this case runtime increases but its memory efficient.
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
a = []
half = (len(nums1) + len(nums2))
idx = 0
idy = 0

while True:

if idx == len(nums1):
a += nums2[idy:]
break
elif idy == len(nums2):
a += nums1[idx:]
break
if nums1[idx] < nums2[idy]:
a.append(nums1[idx])
idx += 1
else:
a.append(nums2[idy])
idy += 1
return a[half // 2] if half % 2 != 0 else (a[half //2] + a[(half - 1) // 2]) / 2
# While this one is more efficient,.
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
a = []
half = (len(nums1) + len(nums2))


while nums1 and nums2:
if nums1[0] < nums2[0]:
a.append(nums1.pop(0))
else:
a.append(nums2.pop(0))

a += nums1 + nums2

return a[half // 2] if half % 2 != 0 else (a[half //2] + a[(half - 1) // 2]) / 2