FastPrepFastPrep
Problem Brief

Find Number of Different Words That Can Be Formed

OA

Given a string representing a sequence of digits, find the number of different words that can be formed by interpreting the digits as indices in the alphabet where '1' corresponds to 'a', '2' to 'b', and so on, up to '26' for 'z'.

A valid word is formed by splitting the string into one or two-digit numbers and then mapping those numbers to their corresponding letters. The number '0' does not correspond to any letter, and numbers greater than '26' do not correspond to any letter.

Function Description

Complete the function numDifferentWords in the editor.

numDifferentWords has the following parameter:

  1. String s: the string representing the sequence of digits

Returns

int: the number of different words that can be formed

1Example 1

Input
s = "1192"
Output
3
Explanation

The following different words can be formed from the string "1192":

  • 1,1,9,2 - aaib
  • 11,9,2 - kib
  • 1,19,2 - asb

Therefore, the answer is 3.

public int numDifferentWords(String s) {
  // write your code here
}
Input

s

"1192"

Output

3

Sign in to submit your solution.