employer cover photo
employer logo
employer logo

Tata Consultancy Services

Fait partie de Tata Group

Employeur impliqué

Question d’entretien chez Tata Consultancy Services

Find the largest subarray with 0 sum answer

Réponse à la question d'entretien

Utilisateur anonyme

3 juin 2025

To find the largest subarray with sum zero, I use a prefix sum and a hash map. I keep a running sum while iterating through the array. If the sum is zero, the subarray from the start to the current index has zero sum, so I update the max length. If the sum repeats, it means the subarray between the previous index and current index sums to zero, and I update the max length accordingly. This runs in O(n) time with O(n) space.