Random keyboard
Practice
3.7 (3 votes)
String algorithms
Real world
Algorithms
String searching
Problem
89% Success 774 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

During your computer examination, you are given a question to find whether a given word is valid if it can be typed using only one row of the given keyboard pattern. 

You are given an integer N where N denotes the number of rows in keyboards. You are given an array of string keyboard where keyboard denotes the key sequence of each row i.e. keyboard[i] denotes the key sequence of ith row. You are given a string word that you need to validate.

Task

Return 1 if the string word is valid else 0.

Example

Assumptions

  • N = 3
  • keyboard = [asdfghjkl, qwertyuiop, zxcvbnm]
  • word = akash

Approach

All the letters of string once are present in the first row of the keyboard.

Therefore return 1.

Function description

Complete the Solve() function provided in the editor below that takes the following arguments and returns 1 if the string word is valid else return 0:

  • N: Represents the total number of rows on the keyboard.
  • keyboard: Represents the key sequence of each row of the keyboard.
  • word: Represents the string that needs to be validated.

Input format

  • The first line contains an integer N denoting the total number of rows in the keyboard
  • Next, N line contains the key sequence of the Keyboard.
  • The last line contains a string that needs to be validated.

Output format

Print 1 if the string word is valid else 0.

Constraints

\(1 \le N \le 26 \)

keyboard[i] contains lowercase English alphabets and can contain at max 26 letters without repetition.
words[i] contains lowercase English alphabets and can contain at max 10letters.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
String SearchingAlgorithmsReal worldString Algorithms
Points:20
31 votes
Tags:
MathematicsOpenApprovedEasyMathamatics
Points:20
24 votes
Tags:
ApprovedEasyString Manipulation