0% found this document useful (0 votes)
0 views12 pages

Coding Jam Rep Profile (1) - 1

The document outlines a two-round coding challenge focused on Java programming. Round 1 requires participants to solve 2 easy and 1 difficult problem from a set of 5 within an hour, while Round 2 involves correcting and analyzing Java programs with hidden errors. Judging criteria include speed, correctness, efficiency, and clarity, with strict rules against unfair practices.

Uploaded by

amogh.yt1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views12 pages

Coding Jam Rep Profile (1) - 1

The document outlines a two-round coding challenge focused on Java programming. Round 1 requires participants to solve 2 easy and 1 difficult problem from a set of 5 within an hour, while Round 2 involves correcting and analyzing Java programs with hidden errors. Judging criteria include speed, correctness, efficiency, and clarity, with strict rules against unfair practices.

Uploaded by

amogh.yt1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

🧠ROUND 1 – CODING CHALLENGE

⏱ Duration: 1 Hour
💻 Language: Java Only
🧩 Task:

 Solve 2 Easy + 1 Difficult programming problems from a set of 5.


 Standard Java library functions are allowed. Advanced concepts are optional.

🧑‍⚖️Judging Criteria:

 Speed
 Correctness
 Efficiency
 Code readability
 Q&A with judges

📜 Rules:

 No unfair practices – strict monitoring in place


 Devices and scratch paper will be provided

🔍ROUND 2 – CORRECTION AND ANALYSIS CHALLENGE


⏱ Duration: 1.5 Hours
📌 Qualifiers: Only _______ schools will qualify based on Round 1 performance

Task:

 Correct 2 Java Programs each containing 4 minor hidden errors


 Provide a detailed analysis of each program, including:
o ✅ Purpose of the code
o 🔁 Logic explanation
o 📚 Variable descriptions
o 💡 Suggestions for improvement (if any)

🧑‍⚖️Judging Criteria:

 Speed
 Accuracy
 Clarity
 Depth of analysis
 Q&A with judges

Easy Problem 1: Prime Factorisation


What is Prime Factorisation?
It is the process of expressing a number as a product of its prime factors.
Example:
Input: 60
Output: 2 × 2 × 3 × 5
Solution:
import java.util.Scanner;
public class PrimeFactorisation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number to factorise: ");
int num = sc.nextInt();
System.out.print("Prime factors of " + num + " are: ");
for (int i = 2; i <= num; i++) {
while (num % i == 0) {
System.out.print(i + " ");
num = num / i;
}
}
sc.close();
}
}

Easy Problem 2: Armstrong Number


What is an Armstrong Number?
An Armstrong number (also called a narcissistic number) is a number that is equal to the sum of its
own digits each raised to the power of the number of digits.
Example:
153 → 1³ + 5³ + 3³ = 153
9474 → 9⁴ + 4⁴ + 7⁴ + 4⁴ = 9474
Solution:
import java.util.Scanner;
public class ArmstrongInRange {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the starting number: ");
int start = sc.nextInt();
System.out.print("Enter the ending number: ");
int end = sc.nextInt();
System.out.println("\nArmstrong numbers between " + start + " and " + end + "
are:");
for (int i = start; i <= end; i++) {
if (isArmstrong(i)) {
System.out.println(i);
}
}
sc.close();
}
public static boolean isArmstrong(int num) {
int original = num;
int digits = countDigits(num);
int sum = 0;
while (num > 0) {
int digit = num % 10;
sum += Math.pow(digit, digits);
num /= 10;
}
return sum == original;
}
public static int countDigits(int num) {
int count = 0;
while (num > 0) {
num /= 10;
count++;
}
return count;
}
}

Easy Problem 3: Voting System


Program Features
 Lets voters cast votes for candidates
 Displays menu with options
 Validates input
 Shows vote count and winner

Sample Output
Enter the number of voters: 4

Voter #1, please cast your vote:


1. Alice
2. Bob
3. Charlie
Enter your choice (1 to 3): 2
Vote casted for Bob
Voting Results:
Alice: 1 votes
Bob: 2 votes
Charlie: 1 votes
Winner(s): Bob

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();
}
}

Difficult Problem 1: Sudoku Validator

Program checks whether the solution follows all Sudoku rules:

 Each row must have digits 1 to 9 without repetition.


 Each column must have digits 1 to 9 without repetition.
 Each of the 9 subgrids (3x3) must also contain digits 1 to 9 without repetition.

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];

for (int j = 0; j < 9; j++) {


if (!isValidNumber(board[i][j], rowCheck)) return false;
if (!isValidNumber(board[j][i], colCheck)) return false;
}
}
for (int row = 0; row < 9; row += 3) {
for (int col = 0; col < 9; col += 3) {
boolean[] gridCheck = new boolean[9];

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {
if (!isValidNumber(board[row + i][col + j], gridCheck)) return
false;
}
}
}
}
return true;
}
public static boolean isValidNumber(int num, boolean[] check) {
if (num < 1 || num > 9) return false;
if (check[num - 1]) return false;
check[num - 1] = true;
return true;
}
}
Difficult Problem 2: Next Greater Element

We'll provide a menu-driven program so the user can:

1. Input two matrices


2. Choose an operation: Add, Transpose, or Multiply
3. See the result

Key Notes:

 Matrix addition requires same dimensions.


 Matrix multiplication requires A's column count == B's row count.
 Transpose simply flips rows into columns.

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:

1. Add the elements at the same positions from both matrices.


2. That’s it. As simple as adding corresponding marks in two test papers.

Example:

Let A= B=

Then

A+B=

Matrix Multiplication
Rule:

You can multiply A × B only if the number of columns in A = number of rows in B.

Steps:

1. For each element in the result matrix:


o Take the row from Matrix A and the column from Matrix B.
o Multiply corresponding elements and sum them.
2. Repeat for every row-column pair.

Example:

Let

A= B=

To find A × B:

 Result will be a 2×2 matrix since A is 2×2 and B is 2×2.

Now calculate each element:


 Top-left (row 1 of A × col 1 of B):
1×5+2×7=5+14=191×5 + 2×7 = 5 + 14 = 191×5+2×7=5+14=19
 Top-right (row 1 × col 2):
1×6+2×8=6+16=221×6 + 2×8 = 6 + 16 = 221×6+2×8=6+16=22
 Bottom-left (row 2 × col 1):
3×5+4×7=15+28=433×5 + 4×7 = 15 + 28 = 433×5+4×7=15+28=43
 Bottom-right (row 2 × col 2):
3×6+4×8=18+32=503×6 + 4×8 = 18 + 32 = 503×6+4×8=18+32=50

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:

1. Loop condition i <= nums.length should be i < nums.length to avoid


ArrayIndexOutOfBoundsException
2. Optional: Can break into method findMax(int[]) for better modularity

Analysis:

 Purpose: To find the largest number in a fixed integer array


 Logic: Assume first number is max, then loop through all and update if greater found
 Variables:
o nums[]: array of integers
o max: stores highest number found so far
o i: index variable
 Improvement Suggestion: Make array user-input based; use method to find max for better
readability
Program 2: Squid Game Glass Bridge Simulation – Bug Fix Mission
In the Squid Game’s Glass Bridge round, each player must jump across a series of glass
panels. Each panel is either safe (S) or fragile (F). Stepping on a fragile panel eliminates the
player.

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')

o If the player hits an 'F', they are eliminated

o If they cross all panels safely, they survive

 After simulating all players, print:


Player X: SURVIVED / ELIMINATED
Program:
import java.util.Random;

public class GlassBridge {


public static void main(String[] args) {
char[][] bridge = {
{'S', 'F'},
{'F', 'S'},
{'S', 'F'},
{'F', 'S'},
{'S', 'F'},
{'F', 'S'}
};

String[] players = {"Player 1", "Player 2", "Player 3"};


Random random = new Random();

for (String player : players) {


boolean eliminated = false;

System.out.print(player + " path: ");


for (int i = 0; i < bridge.length; i++) {
int choice = 1;
char step = bridge[i][choice];
System.out.print((choice == 0 ? "L" : "R") + "-" + step + " ");

if (step == 'F') {
eliminated = true;
break;
}
}
if (eliminated)
System.out.println("=> ELIMINATED");
else
System.out.println("=> SURVIVED");
}
}
}

SOLUTION-
import java.util.Random;

public class GlassBridge {


public static void main(String[] args) {
// Bridge layout: each row has 2 panels [left, right] – 'S' or 'F'
char[][] bridge = {
{'S', 'F'},
{'F', 'S'},
{'S', 'F'},
{'F', 'S'},
{'S', 'F'},
{'F', 'S'}
};

String[] players = {"Player 1", "Player 2", "Player 3"};


Random random = new Random();

for (String player : players) {


boolean eliminated = false;

System.out.print(player + " path: ");


for (int i = 0; i < bridge.length; i++) {
int choice = random.nextInt(2); // 0 = left, 1 = right
char step = bridge[i][choice];
System.out.print((choice == 0 ? "L" : "R") + "-" + step + " ");

if (step == 'F') {
eliminated = true;
break;
}
}

if (eliminated)
System.out.println("=> ELIMINATED");
else
System.out.println("=> SURVIVED");
}
}
}

Code Analysis – Glass Bridge Simulation


The program simulates a dangerous game where each player must cross a series of glass panels, choosing between a
left and right panel at each step. Only one panel per pair is safe. The bridge is modelled using a 2D array, where each
row represents a step with two possible choices—left and right—marked as either safe ('S') or fragile ('F').
Players are looped through one at a time. At each step of the bridge, they randomly choose either the left or right
panel. If they step on a fragile panel, they are immediately marked as eliminated, and their traversal halts. If they
manage to cross all steps without stepping on any fragile panel, they are declared to have survived.
The logic ensures each player gets an independent and fair simulation, and the use of random choice closely mirrors
the unpredictability of the original "Squid Game." The result for each player is printed, along with the path they took
and whether they survived or were eliminated.
IMPROVEMENT

A useful improvement would be to track and display the number of steps each player successfully crosses before
elimination.

Why it's helpful:

 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:

 A counter that increments with each successful step.


 After each player’s turn, print:
“Player X survived Y steps before elimination.” or
“Player X completed all steps successfully!”

You might also like