From b2c41ad6d99ff6d6be45ba1553a458e293c0dc6d Mon Sep 17 00:00:00 2001 From: sidtiwari2712 Date: Fri, 1 Oct 2021 22:04:04 +0530 Subject: [PATCH 01/22] Create sum of even number --- sum of even number | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sum of even number diff --git a/sum of even number b/sum of even number new file mode 100644 index 0000000..cfe9bd8 --- /dev/null +++ b/sum of even number @@ -0,0 +1,9 @@ +maximum = int(input(" Please Enter the Maximum Value : ")) +total = 0 + +for number in range(1, maximum+1): + if(number % 2 == 0): + print("{0}".format(number)) + total = total + number + +print("The Sum of Even Numbers from 1 to {0} = {1}".format(number, total)) From 753e27c4fab4ddc4f2e0d5253895c21405dcdcb5 Mon Sep 17 00:00:00 2001 From: Sandeep Yadav <72213528+S-andeep-Yadav@users.noreply.github.com> Date: Sat, 2 Oct 2021 01:12:14 +0530 Subject: [PATCH 02/22] sorting Your program are god --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48572c5..2350939 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ### This repo contains sorting program in Python. #### List of programs available here : - - Bubble Sort + - Bubble Sort:is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. - Insertion Sort - Heap Sort From 5822d54f78cb61718ecb589fd64bfe23424a8ea9 Mon Sep 17 00:00:00 2001 From: Technical Vandar <73782935+Technical-Vandar-885@users.noreply.github.com> Date: Sat, 2 Oct 2021 07:49:34 +0545 Subject: [PATCH 03/22] Create Merge Sort Created Merge Sort in Python --- Merge Sort | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Merge Sort diff --git a/Merge Sort b/Merge Sort new file mode 100644 index 0000000..c48ec79 --- /dev/null +++ b/Merge Sort @@ -0,0 +1,80 @@ +# Python program for implementation of MergeSort + +# Merges two subarrays of arr[]. +# First subarray is arr[l..m] +# Second subarray is arr[m+1..r] + + +def merge(arr, l, m, r): + n1 = m - l + 1 + n2 = r - m + + # create temp arrays + L = [0] * (n1) + R = [0] * (n2) + + # Copy data to temp arrays L[] and R[] + for i in range(0, n1): + L[i] = arr[l + i] + + for j in range(0, n2): + R[j] = arr[m + 1 + j] + + # Merge the temp arrays back into arr[l..r] + i = 0 # Initial index of first subarray + j = 0 # Initial index of second subarray + k = l # Initial index of merged subarray + + while i < n1 and j < n2: + if L[i] <= R[j]: + arr[k] = L[i] + i += 1 + else: + arr[k] = R[j] + j += 1 + k += 1 + + # Copy the remaining elements of L[], if there + # are any + while i < n1: + arr[k] = L[i] + i += 1 + k += 1 + + # Copy the remaining elements of R[], if there + # are any + while j < n2: + arr[k] = R[j] + j += 1 + k += 1 + +# l is for left index and r is right index of the +# sub-array of arr to be sorted + + +def mergeSort(arr, l, r): + if l < r: + + # Same as (l+r)//2, but avoids overflow for + # large l and h + m = l+(r-l)//2 + + # Sort first and second halves + mergeSort(arr, l, m) + mergeSort(arr, m+1, r) + merge(arr, l, m, r) + + +# Driver code to test above +arr = [12, 11, 13, 5, 6, 7] +n = len(arr) +print("Given array is") +for i in range(n): + print("%d" % arr[i]), + +mergeSort(arr, 0, n-1) +print("\n\nSorted array is") +for i in range(n): + print("%d" % arr[i]), + +# This code is contributed by Mohit Kumra From ee256e87661837e9339d2c5ef79825a58d989d40 Mon Sep 17 00:00:00 2001 From: Yakshu Makkar <53832153+YAKSHUMAKKAR39@users.noreply.github.com> Date: Sat, 2 Oct 2021 11:03:43 +0530 Subject: [PATCH 04/22] Create MergeSort.py --- MergeSort.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 MergeSort.py diff --git a/MergeSort.py b/MergeSort.py new file mode 100644 index 0000000..615c286 --- /dev/null +++ b/MergeSort.py @@ -0,0 +1,71 @@ +def merge(arr, l, m, r): + n1 = m - l + 1 + n2 = r - m + + # create temp arrays + L = [0] * (n1) + R = [0] * (n2) + + # Copy data to temp arrays L[] and R[] + for i in range(0, n1): + L[i] = arr[l + i] + + for j in range(0, n2): + R[j] = arr[m + 1 + j] + + # Merge the temp arrays back into arr[l..r] + i = 0 # Initial index of first subarray + j = 0 # Initial index of second subarray + k = l # Initial index of merged subarray + + while i < n1 and j < n2: + if L[i] <= R[j]: + arr[k] = L[i] + i += 1 + else: + arr[k] = R[j] + j += 1 + k += 1 + + # Copy the remaining elements of L[], if there + # are any + while i < n1: + arr[k] = L[i] + i += 1 + k += 1 + + # Copy the remaining elements of R[], if there + # are any + while j < n2: + arr[k] = R[j] + j += 1 + k += 1 + +# l is for left index and r is right index of the +# sub-array of arr to be sorted + + +def mergeSort(arr, l, r): + if l < r: + + # Same as (l+r)//2, but avoids overflow for + # large l and h + m = l+(r-l)//2 + + # Sort first and second halves + mergeSort(arr, l, m) + mergeSort(arr, m+1, r) + merge(arr, l, m, r) + + +# Driver code to test above +arr = [12, 11, 13, 5, 6, 7] +n = len(arr) +print("Given array is") +for i in range(n): + print("%d" % arr[i]), + +mergeSort(arr, 0, n-1) +print("\n\nSorted array is") +for i in range(n): + print("%d" % arr[i]) From a9f78d8737165e302b2a16ed16bb36ace0615bb3 Mon Sep 17 00:00:00 2001 From: Ahamed Sajeeth <44955852+Ahamed-Sajeeth@users.noreply.github.com> Date: Sat, 2 Oct 2021 13:46:24 +0530 Subject: [PATCH 05/22] Update README.md Added Python Framework --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6a99a99..f446fa2 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,6 @@ - Maximum of two numbers in Python - Python Program for simple interest - Python Program for factorial of a number + - Django and Flask are most Popular Python Framework + - Python use for ML Studies Also From d7c15433d9e06d5e9bf8a55e0516b1f5f35ea752 Mon Sep 17 00:00:00 2001 From: sidtiwari2712 Date: Sat, 2 Oct 2021 14:55:23 +0530 Subject: [PATCH 06/22] Create add two number --- add two number | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 add two number diff --git a/add two number b/add two number new file mode 100644 index 0000000..8fbba12 --- /dev/null +++ b/add two number @@ -0,0 +1,10 @@ +# This program adds two numbers + +num1 = 1.5 +num2 = 6.3 + +# Add two numbers +sum = num1 + num2 + +# Display the sum +print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) From 232b0f39081a483087a23699f2e2aa851e850909 Mon Sep 17 00:00:00 2001 From: sidtiwari2712 Date: Sat, 2 Oct 2021 14:56:12 +0530 Subject: [PATCH 07/22] Create add two number --- add two number | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 add two number diff --git a/add two number b/add two number new file mode 100644 index 0000000..8fbba12 --- /dev/null +++ b/add two number @@ -0,0 +1,10 @@ +# This program adds two numbers + +num1 = 1.5 +num2 = 6.3 + +# Add two numbers +sum = num1 + num2 + +# Display the sum +print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) From 4f64e60d8ac313a70206d8acab5f07236b4722bc Mon Sep 17 00:00:00 2001 From: sidtiwari2712 Date: Sat, 2 Oct 2021 14:59:16 +0530 Subject: [PATCH 08/22] Create solve quadratic --- solve quadratic | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 solve quadratic diff --git a/solve quadratic b/solve quadratic new file mode 100644 index 0000000..9304927 --- /dev/null +++ b/solve quadratic @@ -0,0 +1,17 @@ +# Solve the quadratic equation ax**2 + bx + c = 0 + +# import complex math module +import cmath + +a = 1 +b = 5 +c = 6 + +# calculate the discriminant +d = (b**2) - (4*a*c) + +# find two solutions +sol1 = (-b-cmath.sqrt(d))/(2*a) +sol2 = (-b+cmath.sqrt(d))/(2*a) + +print('The solution are {0} and {1}'.format(sol1,sol2)) From 1b3f7d2a8399f95b6739dc88283bd4c45b5f1390 Mon Sep 17 00:00:00 2001 From: sidtiwari2712 Date: Sat, 2 Oct 2021 15:19:26 +0530 Subject: [PATCH 09/22] Create swap in python --- swap in python | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 swap in python diff --git a/swap in python b/swap in python new file mode 100644 index 0000000..22a78b5 --- /dev/null +++ b/swap in python @@ -0,0 +1,16 @@ +# Python program to swap two variables + +x = 5 +y = 10 + +# To take inputs from the user +#x = input('Enter value of x: ') +#y = input('Enter value of y: ') + +# create a temporary variable and swap the values +temp = x +x = y +y = temp + +print('The value of x after swapping: {}'.format(x)) +print('The value of y after swapping: {}'.format(y)) From 576748bf4b3223ced2beeeb66e59804286fdf27b Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 18:39:20 +0530 Subject: [PATCH 10/22] Add files via upload --- calc.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 calc.py diff --git a/calc.py b/calc.py new file mode 100644 index 0000000..d335840 --- /dev/null +++ b/calc.py @@ -0,0 +1,32 @@ +opt = int(input("enter the option you want to perform : 1.addition 2.multiplication")) +if opt==1: + s=0 + n=int(input("enter how many times you want to sum up :")) + print("enter",n,"numbers : ") + for i in range(0,n): + a=int(input("enter the number")) + s=s+a + print("the result is : ",s) + +elif opt==2: + m=1 + n1=int(input("how many times you want to multiply : ")) + print("enter",n1,"numbers :") + for i in range(0,n1): + + b=int(input("enter the number :")) + m=m*b + print("the result is :",m) +elif opt==3: + n2=int(input("how many times you want to substract :")) + print("enter", n2 ,"numbers: ") + a=int(input("enter the 1st number")) + b=int(input("enter the 2nd number")) + #c=(a-b) + d=(n2-2) + print("you have to enter ", d, "numbers more") + for i in range(0,d): + c=(a-b) + e=int(input("enter the number : ")) + f=c-e + print("the result is :", f) \ No newline at end of file From 3de7b7d71590b43601f4a6f5a974414693a1750c Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 18:43:55 +0530 Subject: [PATCH 11/22] Add files via upload --- checkconnection.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 checkconnection.py diff --git a/checkconnection.py b/checkconnection.py new file mode 100644 index 0000000..88b9b16 --- /dev/null +++ b/checkconnection.py @@ -0,0 +1,11 @@ +from urllib.request import urlopen ##importing necessary library this library contains all the modules for url status checking + +name=input("enter your name:") ## entering the user name + +def status(): ## defining the function to check the status + try: + urlopen("https://www.youtube.com/",timeout=1) ## if the url is openable then user is connected + print(name,"you are connected to internet") + except: + print(name,"you are not connected to internet") ## otherwise not connected +status() ## calling the status function \ No newline at end of file From 2c8c2874691a1a51006aad0b0f822910cb946123 Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 18:47:09 +0530 Subject: [PATCH 12/22] Add files via upload From 573cb0d282689d1cbc0e5dbb35cef18e8d6c8b5f Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 18:48:45 +0530 Subject: [PATCH 13/22] Add files via upload --- bullcowgame.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bullcowgame.py diff --git a/bullcowgame.py b/bullcowgame.py new file mode 100644 index 0000000..99add60 --- /dev/null +++ b/bullcowgame.py @@ -0,0 +1,60 @@ +import random as rand +import emoji as emo + +emo_cow = emo.emojize(emo.demojize('šŸ„')) +emo_bull = emo.emojize(emo.demojize('šŸ‚')) +print('\n\033[1m' + ' --: Welcome to Cows (', emo_cow, ') and Bulls (', emo_bull, ') game :--' + '\033[0m') + +rand_num = rand.randrange(1000, 9999, 1) +rand_num_list = list(str(rand_num).replace("", "")) + +trial = 0 +error_dig = 0 +error_let = 0 + +while True: + user_num = input('Guess the 4 digit number : ') + user_num_list = list(str(user_num).replace("", "")) + + def if_contain_letter(x): + for ele in x: + if ele.isalpha(): + con = True + else: + con = False + return con + + if len(user_num_list) != 4: + print(' DIGIT no. Error : \n Your entered number does not contain 4 digits') + error_dig += 1 + if error_dig > 3: + print('*) WARNING !! What are you doing ? Too much errors ! Be careful !') + + if if_contain_letter(user_num_list): + print('DIGIT type Error :\n inputted number contains letter ') + error_let += 1 + + if not if_contain_letter(user_num_list): + if len(user_num_list) == 4: + a = [] + b = [] + + for i in range(len(user_num_list)): + if rand_num_list[i] == user_num_list[i]: + a.append(user_num_list[i]) + + if rand_num_list[i] != user_num_list[i]: + if user_num_list[i] in rand_num_list: + b.append(user_num_list[i]) + + num_of_cow = len(a) + num_of_bull = len(b) + print(num_of_cow, ' cow (', emo_cow, ')') + print(num_of_bull, ' bull (', emo_bull, ')') + trial += 1 + + if str(user_num) == str(rand_num): + print('\n\033[1m' + '### Congratulations! , Well played ###' + '\033[0m') + print('Trials = ', trial) + print('Errors = ', error_dig + error_let) + break From 344f8dc1a023f279d5ae3b4c5478155bd40ba978 Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 18:49:30 +0530 Subject: [PATCH 14/22] Add files via upload --- client-chat.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 client-chat.py diff --git a/client-chat.py b/client-chat.py new file mode 100644 index 0000000..bdfe862 --- /dev/null +++ b/client-chat.py @@ -0,0 +1,38 @@ +import socket +import select +import sys + +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +if len(sys.argv) != 3: + print ("Correct usage: script, IP address, port number") + exit() +IP_address = str(sys.argv[1]) +Port = int(sys.argv[2]) +server.connect((IP_address, Port)) + +while True: + + # maintains a list of possible input streams + sockets_list = [sys.stdin, server] + + """ There are two possible input situations. Either the + user wants to give manual input to send to other people, + or the server is sending a message to be printed on the + screen. Select returns from sockets_list, the stream that + is reader for input. So for example, if the server wants + to send a message, then the if condition will hold true + below.If the user wants to send a message, the else + condition will evaluate as true""" + read_sockets,write_socket, error_socket = select.select(sockets_list,[],[]) + + for socks in read_sockets: + if socks == server: + message = socks.recv(2048) + print (message) + else: + message = sys.stdin.readline() + server.send(message) + sys.stdout.write("") + sys.stdout.write(message) + sys.stdout.flush() +server.close() \ No newline at end of file From 30915946b4962844ae9477f94c04c030d702e029 Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 19:05:45 +0530 Subject: [PATCH 15/22] Add files via upload --- c.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 c.py diff --git a/c.py b/c.py new file mode 100644 index 0000000..85a3502 --- /dev/null +++ b/c.py @@ -0,0 +1,29 @@ +def isVowel(c): + return (c == 'A' or c == 'E' or c == 'I' or + c == 'O' or c == 'U' or c == 'a' or + c == 'e' or c == 'i' or c == 'o' or + c == 'u'); + + +def pigLatin(s): + + + length = len(s); + index = -1; + for i in range(length): + if (isVowel(s[i])): + index = i; + break; + + + if (index == -1): + return "-1"; + + + return s[index:] + s[0:index] + "ay"; + +str = pigLatin("graphic"); +if (str == "-1"): + print("No vowels found. Pig Latin not possible"); +else: + print(str); \ No newline at end of file From acff20ccf86f540f30a1c252dc7f3bd94992b0e1 Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 19:11:12 +0530 Subject: [PATCH 16/22] Add files via upload --- sum of oddno.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 sum of oddno.py diff --git a/sum of oddno.py b/sum of oddno.py new file mode 100644 index 0000000..0d9163c --- /dev/null +++ b/sum of oddno.py @@ -0,0 +1,5 @@ +n=int(input("Enter n value:")) +sum=0 +for i in range(1,n+1,2): + sum+=i +print(sum) \ No newline at end of file From 6281bdd07ac38557130567cfce2b35106b86120e Mon Sep 17 00:00:00 2001 From: Debjani12 <91781087+Debjani12@users.noreply.github.com> Date: Sat, 2 Oct 2021 19:13:34 +0530 Subject: [PATCH 17/22] Add files via upload --- multiplication.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 multiplication.py diff --git a/multiplication.py b/multiplication.py new file mode 100644 index 0000000..0b507a5 --- /dev/null +++ b/multiplication.py @@ -0,0 +1,3 @@ +n=int(input("Multiplication Table of:")) +for i in range(1,10+1): + print("{} X {} = {}".format(i,n,i*n)) \ No newline at end of file From e6e0a9ed241430c83ea5574dafd202f3327d5ad4 Mon Sep 17 00:00:00 2001 From: Ahamed Sajeeth <44955852+Ahamed-Sajeeth@users.noreply.github.com> Date: Sun, 3 Oct 2021 09:30:51 +0530 Subject: [PATCH 18/22] Update README.md Added python --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f446fa2..56568dc 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,5 @@ - Python Program for factorial of a number - Django and Flask are most Popular Python Framework - Python use for ML Studies Also + - python widely use programming Language From 191f94cd5ff7b6c736bbc0e31efc5f842bff0ab3 Mon Sep 17 00:00:00 2001 From: Yakshu Makkar <53832153+YAKSHUMAKKAR39@users.noreply.github.com> Date: Sun, 3 Oct 2021 23:07:05 +0530 Subject: [PATCH 19/22] Create Selectionsort.py --- Selectionsort.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Selectionsort.py diff --git a/Selectionsort.py b/Selectionsort.py new file mode 100644 index 0000000..d2462ff --- /dev/null +++ b/Selectionsort.py @@ -0,0 +1,21 @@ +import sys +A = [64, 25, 12, 22, 11] + +# Traverse through all array elements +for i in range(len(A)): + + # Find the minimum element in remaining + # unsorted array + min_idx = i + for j in range(i+1, len(A)): + if A[min_idx] > A[j]: + min_idx = j + + # Swap the found minimum element with + # the first element + A[i], A[min_idx] = A[min_idx], A[i] + +# Driver code to test above +print ("Sorted array") +for i in range(len(A)): + print("%d" %A[i]), From 3f19afed0d3c9ef5867f5b35c1c65d1c16891431 Mon Sep 17 00:00:00 2001 From: Thenu <64696941+ThenuSand@users.noreply.github.com> Date: Mon, 4 Oct 2021 14:19:39 +0530 Subject: [PATCH 20/22] Added a python to calculate Area of a Circle --- area.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 area.py diff --git a/area.py b/area.py new file mode 100644 index 0000000..17b6b8e --- /dev/null +++ b/area.py @@ -0,0 +1,10 @@ +#program to find area of circle using functions +import math + +#Function that calculates area of circle +def area_of_circle(r): + a = r**2 * math.pi + return a + +r = float(input("Enter the radius of the circle: ")) +print("%.2f" %area_of_circle(r)) \ No newline at end of file From 67070e5bbffd1bfe81907297e3f40cd14429c69b Mon Sep 17 00:00:00 2001 From: Ashutoshranjan31011955 <90490407+Ashutoshranjan31011955@users.noreply.github.com> Date: Tue, 5 Oct 2021 04:33:59 -0700 Subject: [PATCH 21/22] Create Sort numeric strings in a list in Python by Naive Methodby --- Sort numeric strings in a list in Python by Naive Methodby | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Sort numeric strings in a list in Python by Naive Methodby diff --git a/Sort numeric strings in a list in Python by Naive Methodby b/Sort numeric strings in a list in Python by Naive Methodby new file mode 100644 index 0000000..1496c3f --- /dev/null +++ b/Sort numeric strings in a list in Python by Naive Methodby @@ -0,0 +1,6 @@ +Naive Method + numeric string sorting +for i in range(0, len(test_list)) : + test_list[i] = int(test_list[i]) +test_list.sort() +print ("The resultant sorted list : " + str(test_list)) From b48bcbae7a5bd2d72d53c5c2205e7f8dbc4bac82 Mon Sep 17 00:00:00 2001 From: SomRawat <76642632+SomRawat@users.noreply.github.com> Date: Fri, 15 Oct 2021 11:30:41 +0530 Subject: [PATCH 22/22] Kadane's Algorithm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kadane’s algorithm is one of the famous approaches to solve the problem using dynamic programming The time complexity of kadane’s algorithm for an array containing n integer element is O(n) as only one for loop is to be executed throughout the program. Similarly, the auxiliary space complexity of the algorithm is O(1). --- Kadanes_Algorithm.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Kadanes_Algorithm.py diff --git a/Kadanes_Algorithm.py b/Kadanes_Algorithm.py new file mode 100644 index 0000000..06b8f9e --- /dev/null +++ b/Kadanes_Algorithm.py @@ -0,0 +1,18 @@ +def maxSubArraySum(arr,size): + + max_till_now = arr[0] + max_ending = 0 + + for i in range(0, size): + max_ending = max_ending + arr[i] + if max_ending < 0: + max_ending = 0 + + + elif (max_till_now < max_ending): + max_till_now = max_ending + + return max_till_now + +arr = [-2, -3, 4, -1, -2, 5, -3] +print("Maximum Sub Array Sum Is" , maxSubArraySum(arr,len(arr)))