Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code javascript: Given an array of strings, find a pair of strings that share the same letter at the same position. Task description You are
code javascript: Given an array of strings, find a pair of strings that share the same letter at the same position.
Task description
You are given an array S consisting of N strings. Every string is of the same length M Your task is to find a pair of strings in array S such that there exists a position in which both of the strings have the same letter. Both the index in array S and the positions in the strings are numbered from zero.
For example, given S abc "bca", "dbe" string abc and string dbe have the same letter b in position On the other hand, for strings "abc" and "bca" there does not exist a position in which they have the same letter.
Write a function:
function solutionS;
that, given a zeroindexed array S of N strings, returns an array describing a pair of strings from S which share a common letter at some index. If there is no such pair, the function should return an empty array. If there is more than one correct answer, the function can return any of them.
The result should be represented as an array containing three integers. The first two integers are the indexes in S of the strings belonging to the pair. The third integer is the position of the common letter.
For S abc "bca", "dbe" as above, the result array should be represented as Another correct answer is as the order of indexes of strings does not matter.
Examples:
Given: S abc "bca", "dbe" your function may return as described above.
Given: S zzzz "ferz", zdsrfgtd your function may return Both zzzz and "ferz" have z in position The function may also return which would reflect strings "ferz", fgtd and letter f
Given A grsdrg your function should return There is no pair of strings that fulfils the criteria.
Given A bdafg "ceagi" your function may return
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
M is an integer within the range ;
each element of S consists only of lowercase English letters az;
N M
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started