Skip to main content

Accenture

Accenture OA-12 2024

Problem Description

A poet has asked for assistance in writing poems. He has given you a string S and a dictionary D. Your task is to find, from the dictionary, a word which rhymes best with S. Words are said to rhyme when the last syllables of the words are the same, like "cave" and "gave", or "typical" and "critical". The words will be deemed to rhyme best if the last few characters of the words match the most.

Your task is to find and return a string value denoting the word which rhymes best with S, from the dictionary D. If no such word is found, return the string "No Word".

Note:

  • If all the characters match, it is the same word and not a rhyming word.
  • All the given words are in lowercase.
  • If multiple rhyming words are found, then choose the word with the least index.

Input Format:

  • input1: A string value S, representing a single word.
  • input2: A string array D, representing the dictionary.
  • input3: An integer value representing the length of array D.

Output Format:

Return a string value denoting the word which rhymes best with S from the dictionary D. If no such word is found, return the string "No Word".

Constraints:

  • 1 <= |S| <= 100
  • 1 <= N <= 100
  • 1 <= |D[i]| <= 100

Example 1

Sample Input 1:

S = "happy"
D = ["happy", "sad", "mad", "glad", "bad"]

Sample Output 1:

No Word

Explanation:
In this case, all the words in the dictionary are either the same as the input word or don't rhyme. Therefore, the output is "No Word".

Example 2

Sample Input 2:

S = "playing"
D = ["singing", "flying", "crying", "dying", "lying"]

Sample Output 2:

flying

Explanation:
The word "flying" rhymes best with "playing" as they share the same last syllable "ying". Therefore, the output is "flying".