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

f(Aibohphobia)^-1

https://www.hackerrank.com/contests/codenection-2021-open-category-preliminary/challenges/faibohphobia-1/

PreviousOpen Preliminary RoundNextDid they cheat?

Last updated 2 months ago

Question

Kyle has a group project this semester, and he wants to come up with a name for their group chat for the project. As he is a fan of palindromes (Strings that read the same when reversed), he searched up a random string S from the internet and now he wants to turn this string into a palindrome. Kyle can change any character of the string to any desired character in 1 move. How many moves will it take him to transform this string into a palindrome?

Input Format

S

Constraints

1≤∣S∣≤1001 \le |S| \le 1001≤∣S∣≤100

Output Format

Output a single integer, minimum moves required to turn S into a palindrome.

Sample Inputs:

Input

vvvvvv

Output

0

Input

abcdabc

Output

2

Explanation

We can make the string cbcdabc with 1 move and cbadabc with 2 moves.


Solution - Two Pointers

A classic question for 2-pointer question. All we need to do is get a 2 pointer, compare the first letter and last letter.

If first letter is not same as last letter, add 1 counter.

The comparison ends when the pointer meet each other, or passed through, aka right < left.

Here's the solution:

s = input()
mismatch_count = 0
left, right = 0, len(s) - 1

while left < right:
    if s[left] != s[right]:
        mismatch_count += 1
    left += 1
    right -= 1

print(mismatch_count)
🇲🇾