EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2023
  3. Preliminary Round

Codey and Hide-and-Seek

https://www.hackerrank.com/contests/codenection-2023-preliminary-round-closed-category/challenges/cn-c2

PreviousCodey and CodeNectionNextCodey and Math

Last updated 2 months ago

Question

In a world that dances with riddles, Codey has embarked on a grand game of hide-and-seek within a mysterious 2D grid of size n x m . The grid exclusively contains two elements: Codey, represented by the character #, and empty cells, marked as ..

Your mission is to uncover Codey's hiding spot by finding the coordinates where Codey is lurking. If you succeed, you will happily report back with the coordinates (row and column). However, if Codey is too tricky and you can't find it in the grid, you'll report −1-1−1 as your answer.

Input Format

The first line contains two integers, n and m, where n represents the number of rows and m represents the columns in the 2D grid.

The following n lines provide a representation of the 2D grid.

Constraints

1≤n,m≤1031 \le n, m \le 10^31≤n,m≤103

It is guaranteed that there will only be at most one # in the grid.

Output Format

Output Codey's coordinate (row and column) in a single line, separated by a space if Codey is located within the grid. Output −1-1−1 if Codey is not found in the grid.

Sample Inputs:

Input

2 3
.#.
...

Output

1 2

Explanation

Codey is present in this grid. The coordinates of Codey is printed in the output.

Input

5 10
..........
..........
..........
..........
..........

Output

-1

Explanation

Codey is not present in this grid.


Solution - Loop through grids

first, store the grid. second, find each cell if it fits the symbol. lastly, if it finds it, return the coordinates; otherwise, returns -1.

*Note that the coordinates had to +1, as the array starts from 0 0.*

Here's the solution:

m, n = map(int, input().strip().split())
grid = [list(input().strip()) for _ in range(m)]

for i, row in enumerate(grid):
    for j, cell in enumerate(row):
        if cell == '#':
            print(i+1, j+1)
            exit()
print(-1)

Note that I used enumerate function. This could be useful if you want to extract the index and values in array at the same time.

🇲🇾