Question: We have two arrays: String array A and integral array B both of the same size n. Array A contains various strings and array B
We have two arrays: String array A and integral array B both of the same size n. Array A contains various strings and array B has integral weight corresponding to each string(i.e. if A is [ "asd" , "qw" ] and B is [ 30 , 21 ] it implies weight of string "asd" is 30 and that of "qw" is 21). Now we want to sort the Array A in decreasing order on the basis of weights of string(i.e., if in the sorted array, an element a1 comes before element a2, it implies weight of a1 is greater than or equal to the weight of a2). If there is a tie between two elements(i.e., both of them have the same weight), then the order should be descending based on lexicographic order of the character strings. Write the pseudo code as well as java code to sort the array A as per the above-stated way. Note that time complexity of the algorithm should be O(n logn) where n is size of array A.(It is advisable to use an algorithm similar to merge sort)
For example:
if A = [ "aed" , "qw" , "turf" , "apkl" ]
B = [ 30 , 12 , 76 , 30 ]
then, sorted array A returned by algorithm should be [ "turf" , "apkl" , "aed" , "qw" ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
