-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrank1.java
More file actions
45 lines (43 loc) · 835 Bytes
/
Hackerrank1.java
File metadata and controls
45 lines (43 loc) · 835 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package practicetime;
import java.util.Scanner;
public class Hackerrank1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,s=0,count=0;
//System.out.println(" Enter The Size Of Array - ");
int n=sc.nextInt();
int a[]=new int[n];
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
//System.out.println(" Enter D - ");
int d=sc.nextInt();
//System.out.println(" Enter M - ");
int m=sc.nextInt();
int t=m;
int j,k=1;
for(i=0;i<n;i++)
{
s=a[i];
for(j=k;j<t;j++)
{
s=s+a[j];
}
if(s==d)
{
//System.out.println(" sum - "+s);
count++;
//System.out.println(" C = "+count);
//13
//4 5 4 2 4 5 2 3 2 1 1 5 4
//15 4
}
k++;
t++;
}
System.out.println(count);
}
}