In certain situations, there may be more efficient alternatives that require fewer operations. However, the main concept is to utilize prefix sums and hashmaps as illustrated in the earlier example. Employing effective data structures can significantly improve performance. For instance, in Java, an ArrayList in conjunction with a HashMap can be utilized for this purpose. Below is a sample Java code: void printZeroSumSubarrays ( int arr [ ] ) { HashMap < Integer , ArrayList < Integer > > map = new HashMap < > ( ) ; int sum = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; if ( sum == 0 ) { System . out . println ( "Subarray from 0 to " + i ) ; } ArrayList < Integer > al = new ArrayList < > ( ) ; if ( map . containsKey ( sum ) ) { al = map . get ( sum ) ; for ( int it = 0 ; it < al . size ( ) ; it ++ ) { System . out . println ( "Subarray from " + ( al . get ( it ) + 1 ) + " to " + + i ) ; } } al . add ( i ) ; map . put ( sum , al ) ; } } In this example, an ArrayList is paired with the HashMap, where the key represents the prefix sum and the value corresponds to the list of indices at which this prefix sum occurs. This approach has a time complexity of O(n) since we only iterate through the array once. The space complexity is also O(n) due to the additional space utilized (HashMap and ArrayList).