-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.java
More file actions
29 lines (29 loc) · 1.02 KB
/
file.java
File metadata and controls
29 lines (29 loc) · 1.02 KB
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
import java.util.Scanner;
public class file {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for(int m=0;m<t;m++){
int n = input.nextInt(),k = input.nextInt();
String l = input.nextLine();
String s = input.nextLine();
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = s.charAt(i)-'0';
long req = 0;
for(int i=0;i<n-k;i++){
long num = 1;
for(int j=0;j<k;j++)
num *= a[i+j];
if(req<num)
req = num;
}
System.out.println(req);
}
}
}
/*Explanation:
As the input number is as big as 1000 digit there is no data type to store that as an integer.
So we take the whole input as string and take each character and convert it to integer.
Then two loops for finding product of adjacent k digits and finding max of them
*/