Largest String using lexicographic order (TC = O(x*n)) x= size of string ; n=total number of strings
class largeststring{
public static void main(String[] args) {
String fruits[]={"apple","Mango","banana"};
String largest=fruits[0];
for(int i=1;i<fruits.length;i++){
if(largest.compareToIgnoreCase(fruits[i]) < 0){
largest=fruits[i];
}
}
System.out.println(largest);
}
}
Time Complexity :- O(x*n) x = size of largest string n= total nuymber of strings
Comments
Post a Comment