// Path: src/main/java/com/hackerrank/BiggerIsGreater.java
// static String nextPermutation(String s) {
//     int p = s.length() - 2;
//     while (p >= 0 && s.charAt(p) >= s.charAt(p + 1)) {
//         p--;
//     }
//     if (p < 0 || s.charAt(p) >= s.charAt(p + 1)) {
//         return "no answer";
//     }
// 
//     int q = s.length() - 1;
//     while (s.charAt(q) <= s.charAt(p)) {
//         q--;
//     }
// 
//     char[] a = s.toCharArray();
//     char temp = a[p];
//     a[p] = a[q];
//     a[q] = temp;
// 
//     String result = new String(a);
//     StringBuilder reversed = new StringBuilder(result.substring(p + 1, result.length()));
// 
//     return result.substring(0, p + 1) + reversed.reverse().toString();
// }


import org.junit.Test;
import static com.hackerrank.BiggerIsGreater.nextPermutation;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;



public class BiggerIsGreaterTest {

    @Test
    public void simpleRearrange() {
        assertThat(nextPermutation("ab")).isEqualTo("ba");
    }

    @Test
    public void singleLetter() {
// Path: src/main/java/com/hackerrank/BiggerIsGreater.java
// static String nextPermutation(String s) {
//     int p = s.length() - 2;
//     while (p >= 0 && s.charAt(p) >= s.charAt(p + 1)) {
//         p--;
//     }
//     if (p < 0 || s.charAt(p) >= s.charAt(p + 1)) {
//         return "no answer";
//     }
// 
//     int q = s.length() - 1;
//     while (s.charAt(q) <= s.charAt(p)) {
//         q--;
//     }
// 
//     char[] a = s.toCharArray();
//     char temp = a[p];
//     a[p] = a[q];
//     a[q] = temp;
// 
//     String result = new String(a);
//     StringBuilder reversed = new StringBuilder(result.substring(p + 1, result.length()));
// 
//     return result.substring(0, p + 1) + reversed.reverse().toString();
// }


// Path: src/test/java/com/hackerrank/BiggerIsGreaterTest.java
import org.junit.Test;
import static com.hackerrank.BiggerIsGreater.nextPermutation;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

package com.hackerrank;



public class BiggerIsGreaterTest {

    @Test
    public void simpleRearrange() {
        assertThat(nextPermutation("ab")).isEqualTo("ba");
    }

    @Test
    public void singleLetter() {
        assertThat(nextPermutation("t")).isEqualTo("no answer");