Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Naughty Luke
EASY
15 mins
5 upvotes
Matrices (2D Arrays)
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Naughty Luke

Contributed by
Kamal Pathak
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 70 %
Share
5 upvotes

Problem Statement

Luke, a naughty kid, went to a museum one day. He sees an ancient grid 'A' consisting of 'N' rows and 'N' columns. Each cell of a grid is coloured with either black or white.

Luke performs two sequential operations on the grid ‘A’. First, he twists the grid vertically around the center. After that, as the second operation, he changes the colours of all the cells. If the cell is white, it is changed to black and vice-versa.

The following drawings show the twist operation and the colour change operation, respectively :

The black colour is represented by '1' and white colour is represented by '0' here. You have to print the final grid.

Example :
'N' = 2, 'A' = { {0, 1}, {0, 0} }.

After twisting, the grid looks like :
'A' =  { {1, 0}, {0, 0} }.

After changing the colours, the grid looks like :
'A' =  { {0, 1}, {1, 1} }.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
2
3
1 1 0
0 1 1
1 0 0
1
0
Sample Output 1 :
1 0 0
0 0 1
1 1 0
1
Explanation Of Sample Input 1 :
For test 1:
After twisting the grid looks like : { {0, 1, 1}, {1, 1, 0}, {0, 0, 1} }.
After changing the colour of cells the grid looks like : { {1, 0, 0}, {0, 0, 1}, {1, 1, 0} }.

For test 2:
After twisting the grid looks like : { {0} }.
After changing the colour of cells the grid looks like : { {1} }.
Sample Input 2 :
2
3
1 1 1
1 1 1
1 1 1
4
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
Sample Output 2 :
0 0 0
0 0 0
0 0 0
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Reset Code
Full screen
Auto
copy-code
Console