Your browser (Unknown 0) is no longer supported. Some parts of the website may not work correctly. Please update your browser.

AVAILABLE EXERCISES:

Exercise 9

Bitwise operations (bit-ops)

Exercise 8

Frontend

Exercise 7

Data Structures

Exercise 6

SQL

Exercise 5

Coding skills

Exercise 4

Algorithmic skills

Exercise 3

2017 Contest

Exercise 2

2016 Contest

Exercise 1

2015 Contest

Reduce a string containing instances of the letters "A", "B" and "C" via the following rule: remove one occurrence of "AA", "BB" or "CC".

Spoken language:

A string S containing only the letters "`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Transformation of the string is the process of removing letters from it, based on the rules described above. As long as at least one rule can be applied, the process should be repeated. If more than one rule can be used, any one of them could be chosen.

Write a function:

char * solution(char *S);

that, given a string S consisting of N characters, returns any string that can result from a sequence of transformations as described above.

For example, given string S = "`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

Also, given string S = "`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

Finally, for string S = "`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

A string S containing only the letters "`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Transformation of the string is the process of removing letters from it, based on the rules described above. As long as at least one rule can be applied, the process should be repeated. If more than one rule can be used, any one of them could be chosen.

Write a function:

string solution(string &S);

that, given a string S consisting of N characters, returns any string that can result from a sequence of transformations as described above.

For example, given string S = "`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

Also, given string S = "`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

Finally, for string S = "`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

A string S containing only the letters "`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Transformation of the string is the process of removing letters from it, based on the rules described above. As long as at least one rule can be applied, the process should be repeated. If more than one rule can be used, any one of them could be chosen.

Write a function:

class Solution { public string solution(string S); }

that, given a string S consisting of N characters, returns any string that can result from a sequence of transformations as described above.

For example, given string S = "`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

Also, given string S = "`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

Finally, for string S = "`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

String solution(String S);

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

func Solution(S string) string

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

class Solution { public String solution(String S); }

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

class Solution { public String solution(String S); }

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

function solution(S);

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

fun solution(S: String): String

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

function solution(S)

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

NSString * solution(NSString *S);

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

function solution(S: PChar): PChar;

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

function solution($S);

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

sub solution { my ($S) = @_; ... }

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

def solution(S)

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

def solution(s)

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

object Solution { def solution(s: String): String }

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

public func solution(_ S : inout String) -> String

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

function solution(S: string): string;

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.

`A`", "`B`" and "`C`" is given. The string can be transformed by removing one occurrence of "`AA`", "`BB`" or "`CC`".

Write a function:

Private Function solution(S As String) As String

`ACCAABBC`" the function may return "`AC`", because one of the possible sequences of transformations is as follows:

`ABCBBCBA`" the function may return "`", because one possible sequence of transformations is:`

`BABABA`" the function must return "`BABABA`", because no rules can be applied to string S.

Write an ** efficient** algorithm for the following assumptions:

- the length of string S is within the range [0..50,000];
- string S is made only of the following characters: '
A', 'B' and/or 'C'.