Minimum Index Sum Of Two Lists

easy
1. You are given two arrays of Strings with N and M elements. 2. You have to find the strings which are common in both the arrays and whose index sum is the least. 3. For example, Input: arr1 = {"one", "should", "aim", "for", "peace", "and", "excellence", "in", "life"} arr2 = {"pepcoding", "helps", "you", "gain", "excellence", "and", "peace"} Output: {"peace", "and", "excellence"} Explanation: Strings which are common in both the arrays are: "peace", "and", "excellence" index sum of "peace" = 4 + 6 = 10 index sum of "and" = 5 + 5 = 10 index sum of "excellence" = 6 + 4 = 10 Therefore, the answer is "peace", "and", "excellence". Note: order of the result array does not matter. 4. display is a utility function, feel free to use it for debugging purposes. 5. main takes input from the users and creates the array. 6. This is a functional problem. 7. You have to complete the findIndexSum function. It takes as input two string arrays. It should return a string array containing the strings with least index sum. 8. Don't change the code of main and display.

Input Format

First line takes input N, the length of the first array. Second line takes input N space separated strings representing the elements of the first array. Third line takes input M, the length of the second array. Fourth line takes input M space separated strings representing the elements of the second array. Input is handled for you.

Output Format

strings with least index sum in sorted order. Output is handled for you.

Constraints

1 <= N <= 1000

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
9
one should aim for peace and excellence in life
7
pepcoding helps you gain excellence and peace
Output
and excellence peace
Previous
Repeated Dna Sequences
Next
Repeated Character

Related Questions