Greatest789's blog

By Greatest789, history, 6 years ago, In English

Given 2-arrays "$$$A$$$" and "$$$B$$$" of length $$$n$$$ , calculate maximum possible product of all elements of array "$$$C$$$" ,

where,

$$$C[i] = A[j]*B[k] $$$

Or

$$$C[i] = A[j] + B[k] $$$,

(its your choice, what to select from both of them)

for all $$$1 \lt =i \lt =N$$$

Once an index 'j' and 'k' have been used from array A and B respectively, you can't use them ever again.

Find the maximum possible value of C[1]*C[2]*......C[N] modulo p , where p = 1000000007.

$$$1 \lt =A[i] \lt =100000 $$$

$$$1 \lt =B[i] \lt =100000 $$$

$$$1 \lt =N \lt =100000 $$$

Example :

Array A : [1,2]

Array B : [4,3]

Best possible array C :$$$ [(3+1),(4*2)] = [4,8] .$$$

Final answer = 4*8 = 32 which is the maximum possible product.

I applied the greedy approach in the test which failed all the test cases except 1.

My greedy approach was : Sort both "A" and "B", then do $$$C[i]=max(A[i]+B[i], A[i]*B[i]) $$$

Second problem of the test was : Given a graph with $$$N$$$ nodes and $$$M$$$ edges , remove any number of nodes you want to remove and calculate the maximum-sized-bipartite-graph. (Don't remember the constraints, I think N and M were small.)

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Greatest789 (previous revision, new revision, compare).

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Greatest789 (previous revision, new revision, compare).

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can you provide link for question 1

»
6 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

sorry i didn't read full article!

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone solve this 5 year old problem?

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    We want the actual max value; once found in the end we need to do Modulo

    -> Sorting both arrays fails this test-case :-> A = [1, 6, 3, 5, 9, 10] B = [3, 9, 7, 9, 9, 7] ✅ Best Permutation of B (by brute force): B = [7, 3, 9, 9, 9, 7]

    I get the point that we need to be very mindful while assigning "1" of both the arrays to some other array numbers; but still no greedy solution is working correctly for all that I tried.