Class Solution

java.lang.Object
g0801_0900.s0899_orderly_queue.Solution

public class Solution extends Object
899 - Orderly Queue.<p>Hard</p> <p>You are given a string <code>s</code> and an integer <code>k</code>. You can choose one of the first <code>k</code> letters of <code>s</code> and append it at the end of the string..</p> <p>Return <em>the lexicographically smallest string you could have after applying the mentioned step any number of moves</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;cba&rdquo;, k = 1</p> <p><strong>Output:</strong> &ldquo;acb&rdquo;</p> <p><strong>Explanation:</strong></p> <p>In the first move, we move the 1<sup>st</sup> character &lsquo;c&rsquo; to the end, obtaining the string &ldquo;bac&rdquo;.</p> <p>In the second move, we move the 1<sup>st</sup> character &lsquo;b&rsquo; to the end, obtaining the final result &ldquo;acb&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;baaca&rdquo;, k = 3</p> <p><strong>Output:</strong> &ldquo;aaabc&rdquo;</p> <p><strong>Explanation:</strong></p> <p>In the first move, we move the 1<sup>st</sup> character &lsquo;b&rsquo; to the end, obtaining the string &ldquo;aacab&rdquo;.</p> <p>In the second move, we move the 3<sup>rd</sup> character &lsquo;c&rsquo; to the end, obtaining the final result &ldquo;aaabc&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= k <= s.length <= 1000</code></li> <li><code>s</code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • orderlyQueue

      public String orderlyQueue(String s, int k)