Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in this question my one test case is getting failed. JAVA 8 You are given an array S consisting of N strings.

I need help in this question my one test case is getting failed. JAVA 8

image text in transcribed

image text in transcribed

image text in transcribed

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 attay S and the positions in the strings are numbered from zero. For example, given S = ["abc", "bca", "dbe"], string 0 ("abc") and string 2 ("dbe") have the same letter 'b' in position 1. 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: classSolution{publicint[]solution(String[]s);} that, given a zero-indexed 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 [0,2,1]. Another correct answer is [2,0,1], as the order of indexes of strings does not matter. Examples: 1. Given: S=[ "abc", "bca", "dbe"], your function may return [0,2,1] as described above. 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 = [Pabc", "bca", "dbe"], as above, the result array should be represented as [0,2,1]. Another correct answer is [2,0,1], as the order of indexes of strings does not matter. Examples: 1. Given: S=[ "abc", "bca", "dbe"], your function may return [0,2,1] as described above. 2. Given: S = ["zzzz", "ferz", "zdsr", "fgtd", your function may return [0,1,3]. Both "zzzz" and "ferz" have ' z ' in position 3. The function may also return [1,3,0], which would reflect strings "ferz", "fgtd" and letter 'F. 3. Given A=[ "gr", "sd", "rg"] your function should return D. There is no pair of strings that fulfils the criteria. 4. Given A= ["bdafg", "ceagi"], your function may return [0,1,2]. Write an efficient algorithm for the following assumptions: - N is an integer within the range [1,.,30,000}h - M is an integer within the range 11,2,000k - each element of S consists only of lowercase English - NM30,000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

List the five steps in the decision-making model.

Answered: 1 week ago

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

=+What kinds of problems need to be overcome?

Answered: 1 week ago

Question

=+Describe an important trade-off you recently faced

Answered: 1 week ago