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
51 changes: 51 additions & 0 deletions Answers/Kodify_Task_Question_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# coding: utf-8

# In[15]:


# Question 1
# Regarding factorial and the sume of individual numbers of the result gotten from the
# factorial of the number


# Program will keep running till a correct number is inputed to calculate its factorial.
result = 1
choice = True
while (choice):
user_number = int(input("Enter a number to calculate factorial -> "))

if user_number < 0:
print(" Number is negative")
elif user_number == 0:
print("1 is the factorial of 0")
else:
for i in range(1,user_number + 1):
result = result*i
print("The factorial of",user_number,"is",result)
choice = False

# We have the factorial in the result variable
# Moving to move to 2nd phase

sum = 0

while result!=0:
digit = int(result%10)
sum += digit
result = result/10

print("The sum of the factorial we got is --> " , sum)


# In[16]:





# In[ ]:




109 changes: 109 additions & 0 deletions Answers/Kodify_Task_Question_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env python
# coding: utf-8

# In[31]:


## Node Class
## A typical node in the list
class Node:
def __init__(self, value):
self.value =value
self.next = None ## this is the pointer to the next Node


# In[59]:



# Our List class with basic functions for adding and deleteing nodes.

class MyLinkedList:

def __init__(self): ## we initialzie the list with an empty head pointer as no nodes are present
self.head = None

def add(self , value): ## To add a new node to the list

next_node = Node(value) ## creating a new node with some value
next_node.next =self.head ## assigning its next pointer to point to the head of the top node of the list
self.head = next_node ## assiging the header pointer to the newly created node


def Delete(self, index): ## To delete the nTH from the end of the list.

# We will use two pointers to achiece this


first_pointer = self.head ## this pointer will be used to point to the head of the list

second_pointer = self.head ## this will be used to point to the nth node that we want to delete


for i in range(index): ## run the loop till the required index
#print("i --> " , i)
#print("first-->", first_pointer.value)
#print("second-->",second_pointer.value)

# If count of nodes in the
# given list is less than 'index (position of node for deletion)'
if(second_pointer.next == None):

# If index = n then
# delete the head node
if(i == index - 1):
self.head = self.head.next
return self.head

#print("2nd , second_pointer" , second_pointer)
second_pointer = second_pointer.next

while(second_pointer.next != None):
second_pointer = second_pointer.next
first_pointer = first_pointer.next

first_pointer.next = first_pointer.next.next

def printLinkedList(self): ## print the whole list
position = self.head
while(position):
print(" %d " % (position.value), end=" ")
position = position.next




# In[ ]:





# In[58]:


# CHECK THE WORKING OF THE CODE

#Creating and filling the list with values
llist = MyLinkedList()

llist.add(10)
llist.add(20)
llist.add(30)
llist.add(40)
llist.add(50)

print("Created Linked List: ")
llist.printLinkedList()

llist.Delete(3)

print("\nLinked List after Deletion at position 3 from end --> ")
llist.printLinkedList()


# In[ ]:




89 changes: 89 additions & 0 deletions Answers/Kodify_Task_Question_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python
# coding: utf-8

# In[11]:



## A recursive implementation of quick sort as its the go to
## algorithm for best average case time and space complexity

## Was a bit rusty about which sorting algo to use, so decided to look it up in the internet :)
## Reference https://www.programiz.com/dsa/quick-sort

def sort_array(array):

"""Sort the array by using quicksort."""

less = []
equal = []
greater = []

if len(array) > 1: ## check if the array has atleast 2 values

pivot = array[0] ## our base value for which we check the other values
for x in array:

## We basically have 3 pointers moving around determining the values to swap

if x < pivot:
less.append(x)
elif x == pivot:
equal.append(x)
elif x > pivot:
greater.append(x)

return sort_array(less)+equal+sort_array(greater) # Just use the + operator to join arrays

else: # when we have only one element in the array, just return the array.
return array


# In[21]:


#Question 3
# Return the median of the conjuntion of 2 sorted arrays


def Median(array):

size_of_array = len(array)
# check for even case
if size_of_array % 2 != 0:
return float(array[int(n/2)]) ## we can get values in decimal so we cast the result as a float

return float((array[int((size_of_array-1)/2)] + array[int(size_of_array/2)])/2.0)




array1 =[]
array2 =[]

size_array=int(input("Number of elements in first array:"))
for i in range(0 , size_array):
inp=int(input())
array1.append(inp)
print(array1)

size_array = int(input("Number of elements in second array:"))
for i in range(0,size_array):
inp=int(input())
array2.append(inp)
print(array2)

joint_array = list(set(array1 + array2)) ## remove duplicates
final_array = sort_array(joint_array)
print("joint sorted array --> " , joint_array)
Median = Median(final_array)
print("Median for the 2 sorted arrays is -->", Median)


#

# In[ ]:




4 changes: 4 additions & 0 deletions Drive Link for videos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
https://drive.google.com/drive/folders/1etNXDkl4S1qJ-Lq68_x2tN-P04BLNS85?usp=sharing

* As videos were above 100 MB so decided to upload them on google drive and share the link
** Only people with this link can access the drive