Coding Jam Rep Profile (1) - 1
Coding Jam Rep Profile (1) - 1
⏱ Duration: 1 Hour
💻 Language: Java Only
🧩 Task:
🧑⚖️Judging Criteria:
Speed
Correctness
Efficiency
Code readability
Q&A with judges
📜 Rules:
Task:
🧑⚖️Judging Criteria:
Speed
Accuracy
Clarity
Depth of analysis
Q&A with judges
Sample Output
Enter the number of voters: 4
Solution:
import java.util.Scanner;
public class VotingSystem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] candidates = {"Alice", "Bob", "Charlie"};
int[] votes = new int[candidates.length];
int totalVoters;
System.out.print("Enter the number of voters: ");
totalVoters = sc.nextInt();
for (int i = 1; i <= totalVoters; i++) {
System.out.println("\nVoter #" + i + ", please cast your vote:");
for (int j = 0; j < candidates.length; j++) {
System.out.println((j + 1) + ". " + candidates[j]);
}
System.out.print("Enter your choice (1 to " + candidates.length + "): ");
int choice = sc.nextInt();
if (choice >= 1 && choice <= candidates.length) {
votes[choice - 1]++;
System.out.println(" Vote casted for " + candidates[choice - 1]);
} else {
System.out.println(" Invalid choice. Vote not counted.");
}
}
System.out.println("\nVoting Results:");
for (int i = 0; i < candidates.length; i++) {
System.out.println(candidates[i] + ": " + votes[i] + " votes");
}
int maxVotes = votes[0];
for (int i = 1; i < votes.length; i++) {
if (votes[i] > maxVotes) {
maxVotes = votes[i];
}
}
System.out.print("\n Winner(s): ");
boolean tie = false;
for (int i = 0; i < votes.length; i++) {
if (votes[i] == maxVotes) {
System.out.print(candidates[i] + " ");
tie = true;
}
}
if (!tie) {
System.out.println("No clear winner.");
}
sc.close();
}
}
Solution:
import java.util.Scanner;
public class SudokuValidatorInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] board = new int[9][9];
System.out.println("Enter the Sudoku board row by row (9 numbers per row,
space-separated):");
for (int i = 0; i < 9; i++) {
System.out.print("Row " + (i + 1) + ": ");
for (int j = 0; j < 9; j++) {
board[i][j] = sc.nextInt();
}
}
System.out.println("\nValidating Sudoku...");
if (isValidSudoku(board)) {
System.out.println("The Sudoku board is VALID!");
} else {
System.out.println("The Sudoku board is NOT valid.");
}
sc.close();
}
public static boolean isValidSudoku(int[][] board) {
for (int i = 0; i < 9; i++) {
boolean[] rowCheck = new boolean[9];
boolean[] colCheck = new boolean[9];
Key Notes:
Matrix Addition
Rule:
You can add two matrices only if they are of the same order, i.e. same number of rows and columns.
Steps:
Example:
Let A= B=
Then
A+B=
Matrix Multiplication
Rule:
Steps:
Example:
Let
A= B=
To find A × B:
Result:
Solution:
import java.util.Scanner;
public class MatrixOperations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
System.out.print("Enter number of columns: ");
int cols = sc.nextInt();
int[][] A = new int[rows][cols];
int[][] B = new int[rows][cols];
System.out.println("\nEnter elements for Matrix A:");
inputMatrix(A, sc);
System.out.println("\nEnter elements for Matrix B:");
inputMatrix(B, sc);
System.out.println("\nChoose an operation:");
System.out.println("1. Addition");
System.out.println("2. Transpose");
System.out.println("3. Multiplication");
System.out.print("Enter choice (1-3): ");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("\nResult of Addition:");
printMatrix(addMatrix(A, B));
break;
case 2:
System.out.println("\nTranspose of Matrix A:");
printMatrix(transposeMatrix(A));
System.out.println("Transpose of Matrix B:");
printMatrix(transposeMatrix(B));
break;
case 3:
if (cols != rows) {
System.out.println("Multiplication not possible. Columns of A must
equal rows of B.");
} else {
System.out.println("\nResult of Multiplication:");
printMatrix(multiplyMatrix(A, B));
}
break;
default:
System.out.println("Invalid choice.");
}
sc.close();
}
public static void inputMatrix(int[][] matrix, Scanner sc) {
for (int i = 0; i < matrix.length; i++) {
System.out.print("Row " + (i + 1) + ": ");
for (int j = 0; j < matrix[0].length; j++) {
matrix[i][j] = sc.nextInt();
}
}
}
public static int[][] addMatrix(int[][] A, int[][] B) {
int[][] result = new int[A.length][A[0].length];
for (int i = 0; i < A.length; i++)
for (int j = 0; j < A[0].length; j++)
result[i][j] = A[i][j] + B[i][j];
return result;
}
public static int[][] transposeMatrix(int[][] matrix) {
int[][] result = new int[matrix[0].length][matrix.length];
for (int i = 0; i < matrix.length; i++)
for (int j = 0; j < matrix[0].length; j++)
result[j][i] = matrix[i][j];
return result;
}
public static int[][] multiplyMatrix(int[][] A, int[][] B) {
int[][] result = new int[A.length][B[0].length];
for (int i = 0; i < A.length; i++)
for (int j = 0; j < B[0].length; j++)
for (int k = 0; k < A[0].length; k++)
result[i][j] += A[i][k] * B[k][j];
return result;
}
public static void printMatrix(int[][] matrix) {
for (int[] row : matrix) {
for (int val : row)
System.out.print(val + "\t");
System.out.println();
}
}
}
Program 1: Find Largest Number in an Array
Faulty Program:
java
CopyEdit
public class MaxInArray {
public static void main(String[] args) {
int[] nums = {10, 25, 3, 89, 2};
int max = nums[0];
for (int i = 0; i <= nums.length; i++) {
if (nums[i] > max) {
max = nums[i];
}
}
System.out.println("Maximum number is: " + max);
}
}
Corrections:
Analysis:
You, the official game controller (and reluctant Java programmer), have been asked to
simulate this round. Each player follows the bridge step-by-step. If a player steps on a fragile
panel, they are eliminated immediately.
Unfortunately, the current simulation is flawed:
Players are sometimes shown as surviving even after falling
The output skips players
Some steps are never evaluated
The VIPs are getting annoyed. You must fix the logic before someone gets “eliminated” from
your dev team.
Objectives:
For each player:
o Traverse the bridge (array of 'S' and 'F')
if (step == 'F') {
eliminated = true;
break;
}
}
if (eliminated)
System.out.println("=> ELIMINATED");
else
System.out.println("=> SURVIVED");
}
}
}
SOLUTION-
import java.util.Random;
if (step == 'F') {
eliminated = true;
break;
}
}
if (eliminated)
System.out.println("=> ELIMINATED");
else
System.out.println("=> SURVIVED");
}
}
}
A useful improvement would be to track and display the number of steps each player successfully crosses before
elimination.
Adds clarity to performance: not just whether a player survived, but how far they got.
Makes the simulation more engaging and informative for observers.
What to add: