question toh samajh mein aa gya bs implementation mein dikkat hora hai (bat and batman) so batman mein suffix mein bat hai ye kaise pata lagae?
String sort coding question
@tusharjha9835 refer this
int compareTo(string s1, string s2) {
int i = 0;
while (i < s1.length() && i < s2.length()) {
if (s1[i] > s2[i]) {
return 1;
} else if (s1[i] < s2[i]) {
return -1;
}
i++;
}
if (s1.length() > s2.length()) {
return -1;
} else {
return 1;
}
}
(comparator function)
not able to understand the code?
@tusharjha9835 basically we are just comparing the strings letter by letter ( so in this way we can check whose bigger and whether one is prefix of other)
dry run for sample input
shall i send you the whole code?