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.
Bigger is Greater
Bigger is Greater
Sort by
recency
|
998 Discussions
|
Please Login in order to post a comment
import java.io.; import java.util.; import java.util.stream.*;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
}
`string biggerIsGreater(string w) { int index = 0; int decStart = -1; int swapIndex = -1; while (index < w.length()) { // Increasing if (index + 1 < w.length() && w[index] < w[index + 1]) { decStart = index + 1; swapIndex = index; } // Decreasing, we found a new minimum that is smaller else if (decStart != -1 && w[index] <= w[decStart] && w[index] > w[swapIndex]) { // If the new character is greater than the character to be swapping decStart = index; } index++; }
}
solution in scala
Here is my Python solution!