• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 13, 2022 |360 Views
Count words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of a word
  Share   Like
Description
Discussion

Given a string str. The task is to count the words having the same length as str and each letter at the i-th position is either (i-1)-th, i-th, or (i+1)-th position letter of str.
Note: For the first letter consider i-th and (i+1)-th position letter of W. And for last letter consider (i-1)-th and i-th position letter of str.
Examples: 
 

Input : str[] = "ab"
Output : 4
Words that can be formed: aa, ab, ba, bb.

Input : str[] = "x"
Output : 1

Count words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of a word: https://www.geeksforgeeks.org/count-words-whose-th-letter-either-1-th-th-i1-th-letter-given-word/

Read More