Anti-Palindrome

Question

Solution

Idea

This is a pretty awesome question I think. The first thing is to break this problem into smaller problems. We may find that this problem can be solved by writing two functions below:

  1. palindrome(cahr *str, long start, long end) that judge whether a string from start to end is a palindrome or not.

  2. Iterate through all the substrings of at least length 2 from the given string.

palindrome

The implementation can be seen in Code. It is a basic recursive function that utilises wishful thinking. Here I have used some functions from <ctype.h> to simplify my life.

Iterate all the substrings of length 2

This is a key/awesome idea we can take-away from this problem. Here, I utilize two for loops as follows:

The awesome idea here is to use two loops, one stores start, the other stores end. The end is always at least 2 characters behind start and must be smaller than len. So, the start must be smaller than len-2.

Code

https://github.com/mendax1234/Coding-Problems/blob/main/kattis/antipalindrome/antipalindrome.c

Last updated