Skip to content

Commit 19aabb3

Browse files
Added solution for diagonal difference problem
1 parent 2de2836 commit 19aabb3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

HackerRank/DiagonalDifference.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.saintech.allprogtutorials.hackerrank.algos;
2+
3+
import java.util.Scanner;
4+
5+
/**
6+
* @author Sain Technology Solutions
7+
*
8+
* Solution to Problem - https://www.hackerrank.com/challenges/diagonal-difference
9+
*/
10+
public class DiagonalDifference {
11+
12+
public static void main(String[] args) {
13+
Scanner in = new Scanner(System.in);
14+
final int N = Integer.parseInt(in.nextLine());
15+
long diff = 0;
16+
for(int i=0; i < N; i++) {
17+
String[] row = in.nextLine().split(" ");
18+
diff += (Integer.parseInt(row[i]) - Integer.parseInt(row[N - 1 - i]));
19+
}
20+
21+
System.out.println(Math.abs(diff));
22+
23+
in.close();
24+
}
25+
}

0 commit comments

Comments
 (0)