Skip to content

Instantly share code, notes, and snippets.

@rahuldeepattri
Created July 7, 2017 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahuldeepattri/452dc9636dfa5d36f061b528b66e217a to your computer and use it in GitHub Desktop.
Save rahuldeepattri/452dc9636dfa5d36f061b528b66e217a to your computer and use it in GitHub Desktop.
HackerRank
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/HackerRank.iml" filepath="$PROJECT_DIR$/HackerRank.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
import java.util.Scanner;
/**
* https://www.hackerrank.com/challenges/2d-array
* Created by rahul on 7/7/17.
*/
public class ArrayDS {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a[][]=new int[6][6];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
a[i][j]=sc.nextInt();
}
}
int m,t;
m=a[0][0]+a[0][1]+a[0][2]+a[1][1]+a[2][0]+a[2][1]+a[2][2];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
t=a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2];
if(t>m)
m=t;
}
}
System.out.println(m);
}
}
import java.util.Scanner;
/**
*
* https://www.hackerrank.com/challenges/diagonal-difference
* Created by rahul on 7/7/17.
*/
public class DiagonalDifference {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int a[][]=new int[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
a[i][j]=sc.nextInt();
}
}
int r=0;
for (int i = 0; i < N; i++) {
r+=a[i][i];
}
int l=0;
for (int i = 0; i < N; i++) {
l += a[i][N - 1 - i];
}
System.out.println(Math.abs(r-l));
}
}
/**
* Created by rahul on 7/7/17.
*/
public class Main {
public static void main(String[] args) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment