We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
int n = in.nextInt();
int k = in.nextInt();
String number = in.next();
long maxProduct = 0;
for (int i = 0; i <= n - k; i++) {
long product = 1;
for (int j = 0; j < k; j++) {
product *= Character.getNumericValue(number.charAt(i + j));
}
maxProduct = Math.max(maxProduct, product);
}
System.out.println(maxProduct);
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #8: Largest product in a series
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}