Can this algorithm get the least negative number
What if all number are negative
Hi @AyushKumar9032
Kadane’s Algorithm requires at least one positive number, so your all negative array is invalid input. But if you want to make your code work for negative numbers also then make a slight addition to Kadane’s algo. Take a flag, are_all_elements_negative(set to true) and an int(store the highest -ve integer) while iterating over the array, if you find a positive number, set the flag false. While the flag is true, store the highest -ve num. At the end,check the flag, if the flag is true,output the -ve integer, else output the regular Kadane’s algo output.