Hackerrank - Strange Grid Again Solution
1 min read

Hackerrank - Strange Grid Again Solution

Hackerrank - Strange Grid Again Solution

A strange grid has been recovered from an old book. It has  columns and infinite number of rows. The bottom row is considered as the first row. First few rows of the grid are like this:



20 22 24 26 28

11 13 15 17 19

10 12 14 16 18

 1  3  5  7  9

 0  2  4  6  8

The grid grows upwards forever!

Your task is to find the integer in th column in th row of the grid.

Input Format

There will be two integers r and c separated by a single space.


Rows are indexed from bottom to top and columns are indexed from left to right.

Output Format

Output the answer in a single line.

Sample Input

6 3

Sample Output



The number in the 6th row and 3rd column is 25.

def strangeGrid(r, c):
    d,m = divmod(r-1,2)
    a = d*10+2*c
    a -= 1 if m else 2
    return a

r,c = map(int,input().split())
print(strangeGrid(r, c))

Enjoying these posts? Subscribe for more

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.