Super one
Simple Explanation of the Program
1. Read Inputs
o First, we take input values N (rows) and M
(columns).
o Then, we read the N x M matrix, storing it in a 2D
array.
2. Check Each 1 in the Matrix
o We go through each element in the matrix.
o If we find a 1, we check its 8 surrounding cells.
o If all surrounding cells contain 0, then this 1 is a
Super One.
3. Print the Result
o If we find at least one Super One, print "Yes" and
stop.
o If no Super One is found after checking the entire
matrix, print "No".
4* 4
1000
0001
0100
0000
Step-by-Step Check:
1. We find a 1 at position (2,1).
2. We check its 8 surrounding cells:
? ? ?
? 1 ?
? ? ?
All surrounding ? positions contain 0.
So, this 1 is a Super One.
Sparse matrix
Sparse Matrix a matrix of size N x M, print whether it is
a sparse matrix or not. Please note that if a matrix
contains 0 in more than half of its cells, then it is called
a sparse matrix. Input Format The first line of input
contains N, M - the size of the matrix, followed by N
lines each containing M integers - elements of the
matrix.
Output Format Print "Yes" if the given matrix
is a sparse matrix, otherwise print "No".
Example Input 2 *3
500
080
Read the dimensions N and M.
Initialize zero_count to keep track of the
number of zeros.
Read N lines of input and count the zeros in
each row.
Check if zero_count is more than half of
the total elements.
Print "Yes" if it is sparse, otherwise print
"No".
2* 3
500
080
Total elements = 2×3=62 \times 3 = 62×3=6
Zero count = 4
Since 4 > 6/2, it is a sparse matrix.
Image Flip
Image Flip are given an N x M binary matrix called
"image". You need to perform the following
operations on the matrix (in order) and return the
resulting image:Flip the image horizontally: This
involves reversing the order of elements in each
row of the matrix. For example, [1,0,1,0,0,0]
becomes [0,0,0,1,0,1]Invert the image: This
involves replacing 0s with 1s and 1s with 0s in the
entire matrix. For example, [0,0,0,1,0,1] becomes
[1,1,1,0,1,0]Input Format Line of input contains N
- number of rows and M - number of columns.
The next N lines contains M integers each
denoting the elements of the matrix image.
INPUT
3 *4
1001
0110
1100
Step 1: Flip Horizontally
1001 → 1001
0110 → 0110
1100 → 0011
Step 2: Invert the Image
1001 → 0110
0110 → 1001
0011 → 1100
OUTPUT
0110
1001
1100
Alternative Approach
1. Flip Horizontally → Reverse each
row.
2. Invert the Image → Replace 0
with 1 and 1 with 0.
3. Print the Final Matrix.
How This Works
1. Reading Input → The matrix is
stored in a 2D array.
2. Flipping Horizontally → Swaps
elements in each row (left ↔
right).
3. Inverting → Uses a simple if
condition to replace 0 with 1 and 1
with 0.
4. Printing Output → The transformed
matrix is printed.