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
|
997 Discussions
|
Please Login in order to post a comment
`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!
Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-bigger-is-greater-problem-solution.html