We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
List<List<Integer>> arr = new ArrayList<>();
IntStream.range(0, 6).forEach(i -> {
try {
arr.add(
Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList())
);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
int answer = Integer.MIN_VALUE;
for (int i = 0; i <= 3; i++) {
for (int j = 0; j <= 3; j++) {
int sum = 0;
sum += arr.get(i).get(j);
sum += arr.get(i).get(j + 1);
sum += arr.get(i).get(j + 2);
sum += arr.get(i + 1).get(j + 1);
sum += arr.get(i + 2).get(j);
sum += arr.get(i + 2).get(j + 1);
sum += arr.get(i + 2).get(j + 2);
answer = Math.max(sum, answer);
}
}
System.out.println(answer);
bufferedReader.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 11: 2D Arrays
You are viewing a single comment's thread. Return to all comments →
FOR JAVA
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}