Kadane's Algorithm GFG POTD (24 NOVEMBER 2024)

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024
  • ⭐ IN THE GIVEN KADANE'S ALGORITHM, WE NEED TO RETURN THE MAXIMUM VALUE WITH THE POSITIVE SUBARRAYS.
    ⭐FOR SOLVING THIS PROBLEM WE NEED TO TRAVERSE THE ARRAY AND STORE THE VALUES INSIDE SUM, BY ALSO ASURING THAT NO NEGATIVE NUMBER WILL BE FOUND THAT MAKES A NEGATIVE RESULT. IF IT IS THEN WE DO SUM AS COMPLETE ZERO, AND TREAVERSE AGAIN FORM THE NEXT ELEMENT.
    ⭐BY DOING THIS WE CAN SIMPLY GET MAX VALUE.
    ⭐TIME COMPLEXITY: O(n)
    ⭐SPACE COMPLEXITY: O(1)

ความคิดเห็น •