![]() |
VOOZH | about |
Given an array of strings arr[] of size N and an encrypted string str, the task is to find the correct string from the given array of strings whose encryption will give str where str is encrypted using the following rules:
The length of each string in the array is at least 3 and if there is more than one correct answer, print among them.
Examples:
Input: arr[] = {"P@sswORD1", "PASS123word"}, str = "4dro6"
Output: PASS123word
Explanation: The decrypted string representing str = "4dro6" should have
4 upper case letters, sum of all digits in it as 6 and ends with "ord".
The output string satisfies all the following properties.Input: arr[] = {"Geeks", "code", "Day&Night"}, str = "1thg10"
Output: -1
Explanation: No such string exists which satisfies the encryption.
Approach: The given problem is an implementation based problem that can be solved by following the below steps:
Below is the implementation of the above approach:
PASS123word
Time Complexity: O(N * M) where M is the maximum length of a string of the array
Auxiliary Space: O(1)