{"id":"956dd35e-bbec-4610-a5dc-cbe2b3ec14ae","name":"Word Pattern","description":"1. You are given two strings S1 and S2. S1 represents a word of length N and S2 represents N space-separated words.\r\n2. You have to find if the words in S2 follow the exact order as characters in S1.\r\n\r\nNote -> Every string consists of lower-case English letters only.","inputFormat":"Two strings S1 and S2","outputFormat":"true/false","constraints":"1 &lt;= length of strings &lt;= 1000","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<string>\n#include <bits/stdc++.h>\nusing namespace std;\nbool wordPattern(string pattern, string str) {\n //write your code here\n}\n\n\n\nint main() {\n string str1, str2;\n getline(cin, str1);\n getline(cin, str2);\n int ans = wordPattern(str1, str2);\n if (ans == 1) {\n cout << \"true\";\n }\n else {\n cout << \"false\";\n }\n\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static boolean wordPattern(String pattern, String str) {\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn false;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString pattern = scn.nextLine();\r\n\t\tString words = scn.nextLine();\r\n\t\tSystem.out.println(wordPattern(pattern,words));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"abab\r\npep coding pep coding","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/L-Kw6unCGQ4?end=90","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"e61c9f6b-81fe-4419-80bd-43f6eb6763f4","name":"Word Pattern","slug":"word-pattern","type":1}],"next":{"id":"e6bbdc8f-9ce5-4fff-ad70-ebdedb4f68ce","name":"Word Pattern MCQ","type":0,"slug":"word-pattern-mcq"},"prev":{"id":"04ae3e24-001e-49ce-b300-4673587293b1","name":"Isomorphic Strings","type":3,"slug":"isomorphic-strings"}}}

Word Pattern

1. You are given two strings S1 and S2. S1 represents a word of length N and S2 represents N space-separated words. 2. You have to find if the words in S2 follow the exact order as characters in S1. Note -> Every string consists of lower-case English letters only.

{"id":"956dd35e-bbec-4610-a5dc-cbe2b3ec14ae","name":"Word Pattern","description":"1. You are given two strings S1 and S2. S1 represents a word of length N and S2 represents N space-separated words.\r\n2. You have to find if the words in S2 follow the exact order as characters in S1.\r\n\r\nNote -> Every string consists of lower-case English letters only.","inputFormat":"Two strings S1 and S2","outputFormat":"true/false","constraints":"1 &lt;= length of strings &lt;= 1000","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<string>\n#include <bits/stdc++.h>\nusing namespace std;\nbool wordPattern(string pattern, string str) {\n //write your code here\n}\n\n\n\nint main() {\n string str1, str2;\n getline(cin, str1);\n getline(cin, str2);\n int ans = wordPattern(str1, str2);\n if (ans == 1) {\n cout << \"true\";\n }\n else {\n cout << \"false\";\n }\n\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static boolean wordPattern(String pattern, String str) {\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn false;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString pattern = scn.nextLine();\r\n\t\tString words = scn.nextLine();\r\n\t\tSystem.out.println(wordPattern(pattern,words));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"abab\r\npep coding pep coding","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/L-Kw6unCGQ4?end=90","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"e61c9f6b-81fe-4419-80bd-43f6eb6763f4","name":"Word Pattern","slug":"word-pattern","type":1}],"next":{"id":"e6bbdc8f-9ce5-4fff-ad70-ebdedb4f68ce","name":"Word Pattern MCQ","type":0,"slug":"word-pattern-mcq"},"prev":{"id":"04ae3e24-001e-49ce-b300-4673587293b1","name":"Isomorphic Strings","type":3,"slug":"isomorphic-strings"}}}
plane

Editor


Loading...

Word Pattern

easy

1. You are given two strings S1 and S2. S1 represents a word of length N and S2 represents N space-separated words. 2. You have to find if the words in S2 follow the exact order as characters in S1. Note -> Every string consists of lower-case English letters only.

Constraints

1 <= length of strings <= 1000

Format

Input

Two strings S1 and S2

Output

true/false

Example

Sample Input

abab pep coding pep coding

Sample Output

true

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode