Logo

dev-resources.site

for different kinds of informations.

Maximum Multiplication Score

Published at
10/3/2024
Categories
dp
leetcode
contest
Author
prashantrmishra
Categories
3 categories in total
dp
open
leetcode
open
contest
open
Author
15 person written this
prashantrmishra
open
Maximum Multiplication Score

Problem
TC: O(4*m) = O(m)
SC: O(4*m) = O(m) ( dp array) + O(4+m) for recursive stack space

class Solution {
    public long maxScore(int[] a, int[] b) {
        long dp[][] = new long[a.length][b.length];
        for(long d[] : dp) Arrays.fill(d,-1);
        return max(0,0,a,b,dp);
    }
    public long max(int i, int j, int a[], int b[],long dp[][]){
        //base case
        if(i ==a.length) return 0;
        if(j ==b.length) return Long.MIN_VALUE/2;
        if(dp[i][j]!=-1) return dp[i][j];

        long take = (long)a[i]*b[j] + max(i+1,j+1,a,b,dp);

        long dontTake  = (long) max(i,j+1,a,b,dp);
        return dp[i][j] =  Math.max(take,dontTake);
    }
}
Enter fullscreen mode Exit fullscreen mode
contest Article's
30 articles in total
Favicon
Minimum Division Operations to Make Array Non Decreasing
Favicon
Count Substrings With K-Frequency Characters I
Favicon
Cybersecurity Quiz Alert!
Favicon
Maximum Possible Number by Binary Concatenation
Favicon
Maximum Multiplication Score
Favicon
Find the Sequence of Strings Appeared on the Screen
Favicon
Remove Methods from project
Favicon
count-of-substrings-containing-every-vowel-and-k-consonants-i
Favicon
Participate in the SecureChain AI Thread Contest for a Chance to Win
Favicon
India DevOps League 2024
Favicon
প্রোগ্রামিং প্রতিযোগিতার নানান ধরন ।
Favicon
🎉 iPhone 15 Pro Max Giveaway! 🎉
Favicon
The brand new gaming contest is here, introducing the #GlobalGamers Challenge to build games with Flutter!
Favicon
Announcing the Brainstory Holiday Giveaway Contest: Unleash Your Creativity and Win Big! 🧠🎁
Favicon
Join the MiniScript "Advent of Code" contest!
Favicon
Announcing the Directus Panel Quest Hackathon
Favicon
InterSystems Python Programming Contest 2023
Favicon
🏆 Contest - Kintone Customization Contest 2023
Favicon
Hi DEV fellows 🥳❗
Favicon
I made a programming animation; guess the language to win art!
Favicon
InterSystems Developer Tools Contest
Favicon
InterSystems IRIS for Health Contest: FHIR for Women's Health
Favicon
InterSystems Interoperability Contest: Building Sustainable Solutions
Favicon
Contest: Share a Good Plan
Favicon
InterSystems Full Stack Contest 2022
Favicon
InterSystems Grand Prix Programming Contest 2022
Favicon
InterSystems Globals Contest
Favicon
Solving the Hash Code 2022 Practice Challenge with 70 lines of code
Favicon
Hasura Tips & Tricks Contest
Favicon
InterSystems Datasets Contest

Featured ones: