import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
public class Main {
public static int maxLen(Vector<Integer> A, int n) {
int sum = 0;
int longest_length = 0;
Map
<Integer, Integer
> mpp
= new HashMap
<>(); mpp.put(0, -1);
for (int i = 0; i < A.size(); i++) {
sum += A.get(i);
if (mpp.containsKey(sum)) {
longest_length
= Math.
max(longest_length, i
- mpp.
get(sum
)); } else {
mpp.put(sum, i);
}
}
return longest_length;
}
public static void main
(String[] args
) { Vector<Integer> A = new Vector<>();
A.add(15);
A.add(-2);
A.add(2);
A.add(-8);
A.add(1);
A.add(7);
A.add(10);
A.add(23);
int N = 8;
int answer = maxLen(A, N);
System.
out.
println("Answer is " + answer
); }
}
aW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLk1hcDsKaW1wb3J0IGphdmEudXRpbC5WZWN0b3I7CiAKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyBpbnQgbWF4TGVuKFZlY3RvcjxJbnRlZ2VyPiBBLCBpbnQgbikgewogICAgICAgIGludCBzdW0gPSAwOwogICAgICAgIGludCBsb25nZXN0X2xlbmd0aCA9IDA7CiAgICAgICAgTWFwPEludGVnZXIsIEludGVnZXI+IG1wcCA9IG5ldyBIYXNoTWFwPD4oKTsKICAgICAgICBtcHAucHV0KDAsIC0xKTsKIAogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgQS5zaXplKCk7IGkrKykgewogICAgICAgICAgICBzdW0gKz0gQS5nZXQoaSk7CiAKICAgICAgICAgICAgaWYgKG1wcC5jb250YWluc0tleShzdW0pKSB7CiAgICAgICAgICAgICAgICBsb25nZXN0X2xlbmd0aCA9IE1hdGgubWF4KGxvbmdlc3RfbGVuZ3RoLCBpIC0gbXBwLmdldChzdW0pKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIG1wcC5wdXQoc3VtLCBpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KIAogICAgICAgIHJldHVybiBsb25nZXN0X2xlbmd0aDsKICAgIH0KIAogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFZlY3RvcjxJbnRlZ2VyPiBBID0gbmV3IFZlY3Rvcjw+KCk7CiAgICAgICAgQS5hZGQoMTUpOwogICAgICAgIEEuYWRkKC0yKTsKICAgICAgICBBLmFkZCgyKTsKICAgICAgICBBLmFkZCgtOCk7CiAgICAgICAgQS5hZGQoMSk7CiAgICAgICAgQS5hZGQoNyk7CiAgICAgICAgQS5hZGQoMTApOwogICAgICAgIEEuYWRkKDIzKTsKICAgICAgICBpbnQgTiA9IDg7CiAgICAgICAgaW50IGFuc3dlciA9IG1heExlbihBLCBOKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkFuc3dlciBpcyAiICsgYW5zd2VyKTsKICAgIH0KfQ==