Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main
- {
- private static String findMaxSubString(String s,int k){
- if(s.length()==0) return "";
- char prev = s.charAt(0);
- int resLen = 1;
- int currLen = 1;
- int endingInd = 0;
- for(int i =1;i<s.length();i++){
- char curr = s.charAt(i);
- if(Math.abs(curr-prev)<=k){
- currLen+=1;
- }else{
- currLen=1;
- }
- if(currLen>resLen){
- resLen = currLen;
- endingInd=i;
- }
- prev = curr;
- }
- int startingInd = endingInd-resLen+1;
- return s.substring(startingInd,endingInd+1);
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String s = sc.nextLine();
- int k = sc.nextInt();
- System.out.println(findMaxSubString(s,k));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement