diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d99f2f3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/kadone_algorithm/README.md b/kadone_algorithm/README.md new file mode 100644 index 0000000..c9f796b --- /dev/null +++ b/kadone_algorithm/README.md @@ -0,0 +1,36 @@ +Given an array Arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the maximum sum and return its sum. + + +Example 1: + +Input: +N = 5 +Arr[] = {1,2,3,-2,5} +Output: +9 +Explanation: +Max subarray sum is 9 +of elements (1, 2, 3, -2, 5) which +is a contiguous subarray. +Example 2: + +Input: +N = 4 +Arr[] = {-1,-2,-3,-4} +Output: +-1 +Explanation: +Max subarray sum is -1 +of element (-1) + +Your Task: +You don't need to read input or print anything. The task is to complete the function maxSubarraySum() which takes Arr[] and N as input parameters and returns the sum of subarray with maximum sum. + + +Expected Time Complexity: O(N) +Expected Auxiliary Space: O(1) + + +Constraints: +1 ≤ N ≤ 106 +-107 ≤ A[i] ≤ 107 \ No newline at end of file diff --git a/kadone_algorithm/ka.py b/kadone_algorithm/ka.py new file mode 100644 index 0000000..e14723e --- /dev/null +++ b/kadone_algorithm/ka.py @@ -0,0 +1,44 @@ +# User function Template for python3 + +import math + + +class Solution: + ##Complete this function + # Function to find the sum of contiguous subarray with maximum sum. + def maxSubArraySum(self, arr, N): + max = arr[0] + i = 0 + while i < N: + print("i;", i) + j = i + 1 + per = 1 + while per + j-1 < N: + localMax = 0 + marj = j + it = per + while it > 0 and marj < N: + print("mars:", marj, arr[marj]) + localMax += arr[marj] + marj += 1 + it -= 1 + if localMax > max: + max = localMax + print("max", max) + per += 1 + print("next:", per,i,j, max) + i += 1 + return max + + +def main(): + N = 5 + # N = 9 + Arr = [1, 2, 3, -2, 5] + # Arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4] + ob = Solution() + print(ob.maxSubArraySum(Arr, N)) + + +if __name__ == "__main__": + main() diff --git a/missing_number_in_array/README.md b/missing_number_in_array/README.md new file mode 100644 index 0000000..b13c486 --- /dev/null +++ b/missing_number_in_array/README.md @@ -0,0 +1,26 @@ +Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N. Find the missing element. + +Example 1: + +Input: +N = 5 +A[] = {1,2,3,5} +Output: 4 +Example 2: + +Input: +N = 10 +A[] = {6,1,2,8,3,4,7,10,5} +Output: 9 + +Your Task : +You don't need to read input or print anything. Complete the function MissingNumber() that takes array and N as input parameters and returns the value of the missing number. + + +Expected Time Complexity: O(N) +Expected Auxiliary Space: O(1) + + +Constraints: +1 ≤ N ≤ 106 +1 ≤ A[i] ≤ 106 \ No newline at end of file diff --git a/missing_number_in_array/mnia.py b/missing_number_in_array/mnia.py new file mode 100644 index 0000000..c502d80 --- /dev/null +++ b/missing_number_in_array/mnia.py @@ -0,0 +1,30 @@ +#User function Template for python3 + + +class Solution: + def missingNumber(self,array,n): + # code here + if n==2 and array[0]==1: + return 2 + if n==2 and array[0]==2: + return 1 + array.sort() + i=0 + while i