diff --git a/40130112056/Find-The-Missing-Number.py b/40130112056/Find-The-Missing-Number.py new file mode 100644 index 0000000..029ccf4 --- /dev/null +++ b/40130112056/Find-The-Missing-Number.py @@ -0,0 +1,11 @@ +def find_missing_number(Array): + n = len(Array) + sum = n * (n + 1) // 2 + sumOfElementArray = 0 + for element in Array: + sumOfElementArray = sumOfElementArray + element + missingNumber = sum - sumOfElementArray + return missingNumber + +array = [0 , 1 , 2 , 3 , 5] +print(find_missing_number(array)) \ No newline at end of file diff --git a/Answers/How To.txt b/40130112056/How To.txt similarity index 100% rename from Answers/How To.txt rename to 40130112056/How To.txt diff --git a/40130112056/Maximum Subarray Sum.py b/40130112056/Maximum Subarray Sum.py new file mode 100644 index 0000000..7683942 --- /dev/null +++ b/40130112056/Maximum Subarray Sum.py @@ -0,0 +1,19 @@ +def MaximumSubarraySum(Array): + n=len(Array) + Max=Array[0] + for i in range(0,n): + s=Array[i] + if ( s >= Max ): + Max=s + j=i+1 + while(j < n): + s = s + Array[j] + if ( s >= Max ): + Max=s + j=j+1 + + return Max + +# array = [-2, -1, -3, 4, -1, 2, 1, -5, 4] +array=[1 ,5 ,-1 , -50 , 3 , 4 ,7 , -5] +print(MaximumSubarraySum(array)) diff --git a/40130112056/Merge-Sorted-Array.py b/40130112056/Merge-Sorted-Array.py new file mode 100644 index 0000000..2ba6a59 --- /dev/null +++ b/40130112056/Merge-Sorted-Array.py @@ -0,0 +1,29 @@ +# def MergeSortedArray(Array): +def merge_sorted_arrays(array1, array2): + counter1=len(array1) - 1 + counter2=len(array2) - 1 + counterMerge =len(array1) + len(array2) - 1 + + array1.extend([0] * len(array2)) + + while counter1 >= 0 and counter2 >= 0: + + if array1[counter1] > array2[counter2]: + array1[counterMerge] = array1[counter1] + counter1 -= 1 + else: + array1[counterMerge] = array2[counter2] + counter2 -= 1 + counterMerge -= 1 + + while counter2 >= 0: + array1[counterMerge] = array2[counter2] + counter2 -= 1 + counterMerge -= 1 + + return array1 + +Array1 = [1, 2, 3] +Array2 = [2, 5, 6] +merge_sorted_arrays(Array1, Array2) +print(Array1) \ No newline at end of file diff --git a/40130112056/Remove_Duplicates.py b/40130112056/Remove_Duplicates.py new file mode 100644 index 0000000..a3f6b54 --- /dev/null +++ b/40130112056/Remove_Duplicates.py @@ -0,0 +1,9 @@ +def RemoveDuplicates(Array): + lenOfArray=0 + for i in range(0 , len(Array)): + if(Array[i]!= Array[i-1]): + lenOfArray +=1 + return lenOfArray + +array = [1 , 1, 2 , 2 , 3, 4 , 5, 5] +print(RemoveDuplicates(array)) \ No newline at end of file diff --git a/40130112056/Rotate-Array.py b/40130112056/Rotate-Array.py new file mode 100644 index 0000000..19bdb84 --- /dev/null +++ b/40130112056/Rotate-Array.py @@ -0,0 +1,20 @@ +def rotate_array(arr, k): + n = len(arr) + k = k % n + rotated_arr = [0] * n + for i in range(k): + rotated_arr[i] = arr[n-k+i] + + for i in range(k, n): + rotated_arr[i] = arr[i-k] + + return rotated_arr + +array = [1, 2, 3, 4, 5] +k = 2 +print(rotate_array(array, k)) + + + + + \ No newline at end of file diff --git a/40130112056/tempCodeRunnerFile.py b/40130112056/tempCodeRunnerFile.py new file mode 100644 index 0000000..f4686eb --- /dev/null +++ b/40130112056/tempCodeRunnerFile.py @@ -0,0 +1,16 @@ +def MaximumSubarraySum(Array): +# n=len(Array) +# Max=Array[0] +# for i in range(0 ,n): +# j=i+1 +# s=Array[i] +# while(j < n): +# if ( s >= Max ): +# Max=s +# s = s + Array[j] +# j=j+1 + +# return Max + +# array = [-2, -1, -3, 4, -1, 2, 1, -5, 4] +# print(MaximumSubarraySum(array)) \ No newline at end of file