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

Given two integers A and B, return a string which contains A letters "a" and B letters "b" with no three consecutive letters being the same.

Spoken language:

Write a function `solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

1. Given A = 5 and B = 3, your function may return "`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

2. Given A = 3 and B = 3, your function should return "`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

3. Given A = 1 and B = 4, your function should return "`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

In your solution, focus on ** correctness**. The performance of your solution will not be the focus of the assessment.

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

Write a function `solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

1. Given A = 5 and B = 3, your function may return "`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

2. Given A = 3 and B = 3, your function should return "`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

3. Given A = 1 and B = 4, your function should return "`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

In your solution, focus on ** correctness**. The performance of your solution will not be the focus of the assessment.

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

Write a function `solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

1. Given A = 5 and B = 3, your function may return "`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

2. Given A = 3 and B = 3, your function should return "`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

3. Given A = 1 and B = 4, your function should return "`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

In your solution, focus on ** correctness**. The performance of your solution will not be the focus of the assessment.

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

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

Write a function `Solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.

`solution` that, given two integers A and B, returns a string containing exactly A letters '`a`' and exactly B letters '`b`' with no three consecutive letters being the same (in other words, neither "`aaa`" nor "`bbb`" may occur in the returned string).

**Examples:**

`aabaabab`". Note that "`abaabbaa`" would also be a correct answer. Your function may return any correct answer.

`ababab`", "`aababb`", "`abaabb`" or any of several other strings.

`bbabb`", which is the only correct answer in this case.

Assume that:

- A and B are integers within the range [0..100];
- at least one solution exists for the given A and B.

** correctness**. The performance of your solution will not be the focus of the assessment.