A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
char * solution(char *S, int K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
string solution(string &S, int K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
string solution(string &S, int K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
class Solution { public string solution(string S, int K); }
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
String solution(String S, int K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
func Solution(S string, K int) string
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
class Solution { public String solution(String S, int K); }
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
class Solution { public String solution(String S, int K); }
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
function solution(S, K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
fun solution(S: String, K: Int): String
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
function solution(S, K)
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
NSString * solution(NSString *S, int K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
function solution(S: PChar; K: longint): PChar;
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
function solution($S, $K);
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
sub solution { my ($S, $K) = @_; ... }
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
def solution(S, K)
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
def solution(s, k)
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
object Solution { def solution(s: String, k: Int): String }
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
public func solution(_ S : inout String, _ K : Int) -> String
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
function solution(S: string, K: number): string;
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
A string S is given. In one move, any two adjacent letters can be swapped. For example, given a string "abcd", it's possible to create "bacd", "acbd" or "abdc" in one such move. What is the lexicographically minimum string that can be achieved by at most K moves?
Write a function:
Private Function solution(S As String, K As Integer) As String
that, given a string S of length N and an integer K, returns the lexicographically minimum string that can be achieved by at most K swaps of any adjacent letters.
Examples:
1. Given S = "decade" and K = 4, your function should return "adcede". Swaps could be:
decade → dceade,
dceade → dcaede,
dcaede → dacede,
dacede → adcede.
2. Given S = "bbbabbb" and K = 2, your function should return "babbbbb". The swaps are:
bbbabbb → bbabbbb,
bbabbbb → babbbbb.
3. Given S = "abracadabra" and K = 15, your function should return "aaaaabrcdbr".
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S consists only of lowercase letters ('a'-'z');
- K is an integer within the range [0..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.