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. 2024
  3. Preliminary Round

Codey and Pebbles

https://www.hackerrank.com/contests/codenection-2024-preliminary-round-closed-category/challenges/cn24-5

Question

Codey and its n friends have gathered in CodeNection Town. Each one of them brings a handful of pebbles they collected by the river. Everyone brings an even or odd number of pebbles, but one friend, by mistake, brings a number that doesn’t match the rest.

The friends line up in a row, each showing the number of pebbles they’ve brought. Help Codey identify the one friend whose pile has a different number type (odd or even) than all the others.

Input Format

The first line contains an integer n, which represents the number of Codey's friends.

The second line contains n space-separated integers, where each integer represents the number of pebbles brought by Codey's friend.

Constraints

3≤n≤1003 \le n \le 1003≤n≤100

Output Format

Output a single integer representing the index of the number that differs in evenness, assuming index starts from 1.

Sample Inputs:

Input

6
2 4 10 17 8 20

Output

4

Explanation

All numbers are even except 17. The position of 17 is 4, so the output is 4.


Solution - Binary Check

Given checking even or odd is basically modular 2, the answer should be either 1 and 0.

After that, check if it's only "1" or "0" in an array. Then, locate that odd one out, print its index+1, and done.

Here's my solution:

t = int(input().strip())
n = list(map(int, input().strip().split()))

check_binary = [i % 2 for i in n]

unique_check = 0
if (check_binary.count(1) == 1):
    unique_check = 1
    
for idx, val in enumerate(check_binary):
    if val == unique_check:
        print(idx + 1)

Note that I used the count() feature to count the number of 1s, if the count returns 1, which means the binary "1" is the only cell; otherwise, it's "0".

PreviousCodey and CodeNectionNextCodey and Spam

Last updated 2 months ago

🇲🇾