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.
- Prepare
- Java
- Strings
- Java Substring Comparisons
- Discussions
Java Substring Comparisons
Java Substring Comparisons
Sort by
recency
|
1679 Discussions
|
Please Login in order to post a comment
// Complete the function // 'smallest' must be the lexicographically smallest substring of length 'k' // 'largest' must be the lexicographically largest substring of length 'k' int num_substrings = s.length() - k + 1; if (num_substrings < 1) { System.out.println("Substring size is too large for the given string."); //return; }
import java.util.Scanner;
public class Solution {
public static String getSmallestAndLargest(String s, int k) { String smallest = ""; String largest = ""; String st[]=new String[s.length()-k+1];
}
/Adding every subStrings into Array, and then sort it back. In the end, we can retrieve the smallest and largest subStrings. Easy and efficient way to read and write./
import java.util.Arrays; import java.util.Scanner;
public class Main{
}