Case-Insensitive Alphanumeric Palindrome & One-Mismatch Check

Difficulty: Medium · Unit 1: Core Foundations & Text · Featured in: Tough Challenge

Given an input line containing arbitrary ASCII characters, first keep only alphanumeric characters and convert them to lowercase. Determine whether the normalized string is: EXACT (already a palindrome), ONE_EDIT (becomes a palindrome by deleting at most one character), or NO.

Input & Output Format

Input: A single line string S (may contain spaces, punctuation, or be empty).

Output: Print EXACT, ONE_EDIT, or NO.

Sample 1

A man, a plan, a canal: Panama!
EXACT

Normalized string 'amanaplanacanalpanama' is already a palindrome.

Sample 2

abca
ONE_EDIT

Deleting 'b' or 'c' leaves 'aca' or 'aba'.

Free forever — sign in with email at poorvithmp.com to unlock the dry run, verified Python 3 solution, edge-case traps, and downloads.

Back to Python Notes Hub