class Solution {
public int bestTeamScore(int[] scores, int[] ages) {
int n=ages.length;
Player[] players= new Player[n];
for(int i=0;i<n;i++){
players[i]=new Player(ages[i],scores[i]);
Arrays.sort(players,(a,b)-> b.age==a.age? a.score-b.score : a.age-b.age);

int[] dp = new int[n];
int max= dp[0];
for(int i = 1; i<n; i++) {
for(int j =0; j<i; j++) {
if(players[j].score <= players[i].score) {
dp[i] = Math.max(dp[i],players[i].score + dp[j]);

max = Math.max(dp[i], max);

return max;

class Player{
int age;
int score;
public Player(int age, int score){




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Python) list, tuple

How to create a beautiful, reusable gradient view in Swift with IBDesignable

Branching Model: clean-up those repos

Getting Started VMware Tanzu Community Edition (Part 3)

Joining client with the back end service

How to build and publish an App on the Play Store in 14 days

A Conservative Case for Concerns

Why I joined Thinkful coding bootcamp

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinay Gupta

Abhinay Gupta

More from Medium

Understanding time and space complexity with Big O

Why coding still matters

My struggle to recreate a Pokemon ID Tracker.

ARTS Week 25