-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoal.java
More file actions
31 lines (31 loc) · 730 Bytes
/
Goal.java
File metadata and controls
31 lines (31 loc) · 730 Bytes
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
31
import java.util.*;
public class Goal
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter target and session details");
int t=in.nextInt();
int n=in.nextInt();
int session[]=new int[n];
for(int i=0;i<n;i++)
session[i]=in.nextInt();
int start=0,end=0,sum=0;
int minSess=Integer.MAX_VALUE;
while(end<n)
{
sum= sum+session[end];
while(sum>=t)
{
minSess=Math.min(minSess,end-start+1);
sum=sum-session[start];
start++;
}
end++;
}
if(minSess==Integer.MAX_VALUE)
System.out.println("0");
else
System.out.println(minSess);
}
}