Created
May 11, 2017 12:58
-
-
Save aryapreetam/8672d402b1fb3e38ab692915556dfc49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.*; | |
| import java.util.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | |
| Scanner scan = new Scanner(System.in); | |
| int noOfTestCases = scan.nextInt(); | |
| int[][] input = new int[noOfTestCases][2]; | |
| int maxValue = 0; | |
| for(int row=0; row<input.length; row++){ | |
| for(int col=0; col<input[0].length; col++){ | |
| int scannedValue = scan.nextInt(); | |
| maxValue = Math.max(maxValue, scannedValue); | |
| input[row][col] = scannedValue; | |
| } | |
| } | |
| // construct a pTriangle | |
| int[][] pTriangle = new int[maxValue][maxValue]; | |
| for(int row=0; row<pTriangle.length; row++){ | |
| for(int col=0; col<=row; col++){ | |
| if(row - 1 == -1 || col - 1 == -1){ | |
| pTriangle[row][col] = 1; | |
| }else{ | |
| pTriangle[row][col] = pTriangle[row - 1][col - 1] + pTriangle[row - 1][col]; | |
| } | |
| } | |
| } | |
| for(int row=0; row<input.length; row++){ | |
| int rows = input[row][0]; | |
| int cols = input[row][1]; | |
| System.out.println(numberOfEntriesNotDivisibleBy7(pTriangle, rows, cols)); | |
| } | |
| } | |
| public static int numberOfEntriesNotDivisibleBy7(int[][] triangle, int rows, int cols){ | |
| int count = 0; | |
| for(int row=0; row<rows; row++){ | |
| for(int col=0; col<=row && col < cols; col++){ | |
| if(triangle[row][col] % 7 != 0){ | |
| count++; | |
| } | |
| } | |
| } | |
| return count; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment