HackerRank : RookieRank 3 – Find the Bug

By | May 6, 2017
Find the Bug : Hackerrank

Consider an n X n grid where the top-left coordinate is (0,0)  and the bottom-right coordinate is (n-1, n-1) . We define the contents of the grid as an array of n  strings of length n, where the index r of a string corresponds to a row in the grid and the index c  of a character in a string corresponds to a column. Each string consists of the characters O and/or X, where an O denotes an empty cell and an X denotes a cell containing a bug.

image

Given an array of strings defining a grid with bug in it, print the bug’s location in the format r,c (where is the row and is the column).

Input Format

The first line contains an integer denoting (the length and width of the grid).
Each line of the subsequent lines contains a string of characters describing row in the grid.

Constraints

Output Format

Print the bug’s location in the format r,c, where is its row and is its column.

Note: If using the code stubs in the editor, return an array of two integers where index contains the value of and index contains the value of .

Sample Input 0

5
OOOOO
OXOOO
OOOOO
OOOOO
OOOOO

Sample Output 0

1,1

Explanation 0

The diagram below depicts the array and grid:

image

The bug is located at the intersection of row and column , so we print 1,1.

Solution

Solution is pretty simple. Traverse the array and find the bug.
Hint: saving array is waste of memory here.