Close
Topic list
Ninja Ant
MEDIUM
30 mins
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
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
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.

# Ninja Ant

Contributed by
Ankush Gupta
Medium
0/80
Avg time to solve 30 mins
Success Rate 70 %
Share

## Problem Statement

#### Note:

``````The ant initially faces toward the east side. Every time an ant moves from a block, it inverts it, i.e., changes 0 to 1 and 1 to 0.

If the ant exits the matrix just return -1,-1.
``````

#### For example,

``````If ‘N’ = 2
mat[2][2] = {{1, 1},
{0, 0}}
startingRow = 0 , startingColumn = 0
moves = 1
The ant is initially facing the east side, it will take a right turn and move 1 stop in the south.
The output will be 1 0.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )

#### Sample Input 1 :

``````2
2 0 0 1
1 1
0 0
2 0 0 2
1 1
0 1
``````

#### Sample Output 1 :

``````1 0
1 1
``````

#### Explanation of the Sample Input 1:

``````For the first test case:
The ant is initially facing the east side, will take a right turn, and move 1 stop in the south. Therefore output will be 1 0.

For the second test case:
The ant first takes a right turn and lands at (1,0). The ant takes a right turn and moves forward, coming to 1,1. Therefore the output is 1 1
``````

#### Sample Input 2 :

``````2
3 1 1 2
1 0 1
0 1 0
1 0 1
3 1 1 3
1 0 1
0 1 0
1 0 1
``````

#### Sample Output 2 :

``````2 2
-1 -1
``````
Auto
Console