Max sum of subarray in Python and C

Jyothi
Dec 16, 2021

--

Problem is :

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Below is the C solution:

C algorithm for finding max sum value of subarray

Its a simple solution:

— take the sum of previous numbers with the current element

— compare it with the current element

— keep the max of those above 2 values

— compare it with global max value and update

Below is the Python solution:

Python solution

leetcode shows the runtime and memory taken to execute the test cases:

Lots of difference with C solution and Python solution even if the logic is same.

--

--

No responses yet