-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
30 lines (29 loc) · 854 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Linq;
namespace MaximumPointsYouCanObtainFromCards
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
static int MaxScore(int[] cardPoints, int k)
{
int li = 0, hi = cardPoints.Length - k - 1;
int totalPoints = cardPoints.Sum(c => c);
int windowPoints = 0;
for (int i = 0; i <= hi; i++)
windowPoints += cardPoints[i];
int maxPoint = totalPoints - windowPoints;
int res = maxPoint;
while (hi < cardPoints.Length - 1)
{
maxPoint += cardPoints[li++];
maxPoint -= cardPoints[++hi];
res = Math.Max(res, maxPoint);
}
return res;
}
}
}