In Java, we can also implement an efficient solution using the prefix sum method. public boolean checkSubarraySum ( int [ ] nums , int k ) { Map < Integer , Integer > map = new HashMap < > ( ) { { put ( 0 , - 1 ) ; } } ; int runningSum = 0 ; for ( int i = 0 ; i < nums . length ; i ++ ) { runningSum += nums [ i ] ; if ( k != 0 ) runningSum %= k ; Integer prev = map . get ( runningSum ) ; if ( prev != null ) { if ( i - prev > 1 ) return true ; } else map . put ( runningSum , i ) ; } return false ; } In this Java implementation, we create a HashMap that correlates the remainders of the prefix sum (after dividing by k) with their respective indices. When a remainder is encountered again, it signifies that the numbers between the two occurrences of this remainder sum to a multiple of k. Throughout the process, we only update the HashMap if the remainder is absent, which ensures that the distance between remainders remains maximized and exceeds one.