Skip to main content

Posts

Showing posts with the label Kadane’s Algorithm

Learn how to improve communication as an IT fresher with practical tips for meetings, managers, seniors, English, updates, blockers, and workplace messages.

How to Improve Communication as an IT Fresher You can be good at Java, Python, React, SQL, testing, or whatever technology your project uses and still feel completely lost when someone says, “Can you explain what you did?” This is especially common when you are an IT fresher. You may know the answer in your head, but the moment you have to speak in a meeting, talk to a senior developer, ask your manager a question, or explain a technical problem in English, you suddenly start overthinking every sentence. If this sounds familiar, you are not alone. And you do not need perfect English, a foreign accent, or an impressive vocabulary to communicate well at work. Good workplace communication is much simpler: be clear, concise, respectful, honest, and easy to understand. The good news is that communication is a skill you can improve through everyday work. You do not have to become a completely different person. You simply need to become better at explaining what you know, asking wha...

53. Maximum Subarray | Kadane’s Algorithm

53. Maximum Subarray  Medium Topics: Array, Dynamic Programming 💬 Problem Statement: Given an integer array nums , find the subarray with the largest sum , and return its sum. 🧪 Examples: Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6. Example 2: Input: nums = [1] Output: 1 Explanation: The subarray [1] has the largest sum 1. Example 3: Input: nums = [5,4,-1,7,8] Output: 23 Explanation: The subarray [5,4,-1,7,8] has the largest sum 23. 🔒 Constraints: 1 <= nums.length <= 10⁵ -10⁴ <= nums[i] <= 10⁴ 🧠 Approach 1: Kadane's Algorithm (O(n) Time) Kadane’s Algorithm helps you find the maximum sum of a contiguous subarray in just one pass. 👉 Intuition: We move through the array and: Keep adding elements to a running sum ( maxEndingHere ) If maxEndingHere becomes negative, we reset it to 0 Track the maximum seen so far in maxSoFar   MY solution, 🪄 Java Code:   ...