Count Number Of Teams | dynamic programming | Leetcode

Описание к видео Count Number Of Teams | dynamic programming | Leetcode

Welcome to Joey’s dynamic programming tutorial.
In this video, you will learn an awesome problem ‘Count Number of Teams’, and this video is also a part of the Leetcode series.

Count number of teams is a different type of problem and once you learn it by watching this video, you will open another dimension of solving complex DP problems in your mind.

Let’s first start with understanding the problem statement of Count Number of Teams.

N soldiers are standing in a line and each of them has been assigned a unique rating.
You need to create a team of 3 soldiers from these N soldiers such that their ratings are in either complete ascending order or descending order.

So, if the soldiers are i , j and k then the rating of i should be greater than j and the rating of j should be greater than the rating of k.
Or,

The rating of k should be greater than j and the rating of j should be greater than i.

The final ask of the problem is to find out how many such teams can be created based on the condition given in the problem statement.
As an example, if you have the array of ratings of 5 soldiers as this over here [ 2, 5, 3, 4, 1] then the teams which can be formed are

[ 5, 3, 1 ], [ 5, 4, 1 ], [2, 3, 4 ].

You can check that each of the teams is satisfying the condition discussed before.

Now, let’s solve this problem using the dynamic programming approach but before that I want you to subscribe to my channel and hit the bell icon because that way you will get notified whenever I release new videos like these in the future.

Комментарии

Информация по комментариям в разработке