We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidcounterspell(Spell*spell){/* Enter your code here */if(Fireball*fireball=dynamic_cast<Fireball*>(spell)){fireball->revealFirepower();}elseif(Frostbite*frostbite=dynamic_cast<Frostbite*>(spell)){frostbite->revealFrostpower();}elseif(Thunderstorm*thunderstorm=dynamic_cast<Thunderstorm*>(spell)){thunderstorm->revealThunderpower();}elseif(Waterbolt*waterbolt=dynamic_cast<Waterbolt*>(spell)){waterbolt->revealWaterpower();}else{stringscrollName=spell->revealScrollName();stringjournal=SpellJournal::journal;intm=scrollName.length();intn=journal.length();autoinit_2D_array=[](intm,intn){vector<vector<int>>arr(m+1,vector<int>(n+1,0));returnarr;};vector<vector<int>>dp=init_2D_array(m,n);for(inti=1;i<=m;i++){for(intj=1;j<=n;j++){if(scrollName[i-1]==journal[j-1]){dp[i][j]=dp[i-1][j-1]+1;}else{dp[i][j]=max(dp[i-1][j],dp[i][j-1]);}}}cout<<dp[m][n]<<endl;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Magic Spells
You are viewing a single comment's thread. Return to all comments →
Here is the optimized solution for c++