Skip to content

This repository contains a solution to a palindrome algorithm challenge. The challenge involves transforming a given string into a palindrome while respecting a maximum number of allowed changes. The code is implemented in Python and includes clear explanations and variable names for easy understanding.

License

Notifications You must be signed in to change notification settings

ObedRav/Palindrome_Algorithm_Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Highest Value Palindrome 🌟

Introduction

This Python program calculates the highest value palindrome that can be obtained by changing at most k characters in a given string s. A palindrome is a string that reads the same forwards and backward. This program ensures that the resulting palindrome has the maximum possible numerical value.

Why This Exercise? 💡

I selected this exercise because it presents an intriguing challenge: transforming a string into a palindrome while maximizing its numerical value. This problem has real-world applications in data validation, error correction, and even game design. By solving this problem, I aimed to enhance my skills in string manipulation and algorithmic thinking.

How to Run 🚀

To run the "Highest Value Palindrome" program, follow these simple steps:

  1. Prerequisites:

    • Ensure you have Python 3.x installed on your system.
  2. Clone the Repository:

    • Clone this repository to your local machine using your preferred method.
  3. Navigate to the Project Directory:

    • Open a terminal or command prompt in the project directory.
  4. Run the Program:

    • Execute the following command to start the program:

      python3 palindrome.py
  5. Input:

    • Follow the on-screen prompts to input the string, its length, and the maximum number of allowed changes.
  6. Output:

    • The program will calculate and display the highest value palindrome based on your inputs.

Example Usage 📝

Here are some example usages of the program:

  1. Input string: "1231", Length: 4, Changes allowed: 3

    • Output: "9339"
  2. Input string: "12321", Length: 5, Changes allowed: 1

    • Output: "12921"
  3. Input string: "12345", Length: 5, Changes allowed: 2

    • Output: "54345"
  4. Input string: "12345", Length: 5, Changes allowed: 4

    • Output: "99399"
  5. Input string: "12345", Length: 5, Changes allowed: 5

    • Output: "99999"

Input Validation ✅

The program includes input validation to ensure that:

  • The length n of the string is at least 1.
  • The maximum number of changes allowed k is non-negative.

Here's an example of input validation in action:

Please enter a string representation of an integer (e.g., '12345'): 1
Please enter the length of the string (1 or greater): 1
Please enter the maximum number of changes allowed (0 or greater): -2

Highest Value Palindrome: Invalid input: n should be at least 1, and k should be non-negative.

Running Tests
Tests Completed

The program will reject invalid input and provide an informative error message.

Authors

About

This repository contains a solution to a palindrome algorithm challenge. The challenge involves transforming a given string into a palindrome while respecting a maximum number of allowed changes. The code is implemented in Python and includes clear explanations and variable names for easy understanding.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages