nikunjsoni

899

Sep 5th, 2021
1,032
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     string orderlyQueue(string S, int K) {
  4.         if (K > 1) {
  5.             sort(S.begin(), S.end());
  6.             return S;
  7.         }
  8.         string res = S;
  9.         for (int i = 1; i < S.length(); i++)
  10.             res = min(res, S.substr(i) + S.substr(0, i));
  11.         return res;
  12.     }
  13. };
RAW Paste Data