We are given a sentence. Our task is to print all funny words/strings in that sentence.
What is a funny word ?
Reverse the given string. Iterate through each character of that string, compare the absolute difference in the ASCII values of the characters at positions 0 and 1, 1 and 2, 2 and 3 and so on to the end. If the list of absolute differences is the same for both strings, they are funny otherwise not.
Input : HKMNPS Output : Yes Let r be the reverse of original string s s = "HKMNPS" r = "SPNMKH" |H-K| = 3 = |S-P| |K-M| = 2 = |P-N| |M-N| = 1 = |N-M| |N-P| = 2 = |M-K| |P-S| = 3 = |K-H| Since each comparison is equal so given string is funny Input : bdwy Output : No
NOTE : Every palindrome string is a funny string but not vice-versa.
The idea is to split string into words. For every word, traverse it from both ends and compare differences between adjacent characters.
Arora us malayalam bdwy
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print words of a string in reverse order
- Java program to print Even length words in a String
- Extract and print words separately from a given Camel Case string
- Check if the given string of words can be formed from words present in the dictionary
- Given a sequence of words, print all anagrams together using STL
- Given a sequence of words, print all anagrams together | Set 1
- Print all the non-repeating words from the two given sentences
- Given a sequence of words, print all anagrams together | Set 2
- Print all possible words from phone digits
- Program to print the given digit in words
- Print all possible combinations of words from Dictionary using Trie
- Print all valid words that are possible using Characters of Array
- Java ArrayList to print all possible words from phone digits
- Print number of words, vowels and frequency of each character
- Print all words matching a pattern in CamelCase Notation Dictonary
- Count words in a given string
- Reverse words in a given string
- Minimum Distance Between Words of a String
- Check if given words are present in a string
- Reverse words in a given String in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.