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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Print all possible words from phone digits
- Program to print the given digit in words
- Print all the non-repeating words from the two given sentences
- Given a sequence of words, print all anagrams together using STL
- Given a sequence of words, print all anagrams together | Set 1
- Given a sequence of words, print all anagrams together | Set 2
- Print all valid words that are possible using Characters of Array
- Print all possible combinations of words from Dictionary using Trie
- Print number of words, vowels and frequency of each character
- Java ArrayList to print all possible words from phone digits
- Print all words matching a pattern in CamelCase Notation Dictonary
- Reverse words in a given string
- Count words in a given string
- Check if given words are present in a string
- Reverse words in a given String in Python
- Reverse String according to the number of words
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.