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

AVAILABLE LESSONS:

Lesson 1

Iterations

Lesson 2

Arrays

Lesson 3

Time Complexity

Lesson 4

Counting Elements

Lesson 5

Prefix Sums

Lesson 6

Sorting

Lesson 7

Stacks and Queues

Lesson 8

Leader

Lesson 9

Maximum slice problem

Lesson 10

Prime and composite numbers

Lesson 11

Sieve of Eratosthenes

Lesson 12

Euclidean algorithm

Lesson 13

Fibonacci numbers

Lesson 14

Binary search algorithm

Lesson 15

Caterpillar method

Lesson 16

Greedy algorithms

Lesson 17

Dynamic programming

Lesson 90

Tasks from Indeed Prime 2015 challenge

Lesson 91

Tasks from Indeed Prime 2016 challenge

Lesson 92

Tasks from Indeed Prime 2016 College Coders challenge

Lesson 99

Future training

Spoken language:

请给出函数，实现如下功能

int solution(char *S);

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

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

请给出函数，实现如下功能

int solution(string &S);

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

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

请给出函数，实现如下功能

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

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

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

请给出函数，实现如下功能

func Solution(S string) int

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

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

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

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

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

function solution(S);

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

fun solution(S: String): Int

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

function solution(S)

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

int solution(NSString *S);

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

function solution(S: PChar): longint;

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

function solution($S);

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

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

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

def solution(S)

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

def solution(s)

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

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

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

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

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

请给出函数，实现如下功能

Private Function solution(S As String) As Integer

输入为一个由 ( 和 ) 组成的字符串 S ， 如果 S 表示一个格式正确的括号表达式，则返回 1，否则返回 0 。

例如，给定字符串

此函数应返回 1， 而对于

此函数应返回 0.

假定:

- N 是 [0..1,000,000] 内的 整数;
- 字符串 S 只包含字符 "
(" 和/或")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

int solution(char *S);

that, given a string S consisting of N characters, returns 1 if string S is properly nested and 0 otherwise.

For example, given S = "`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

int solution(string &S);

that, given a string S consisting of N characters, returns 1 if string S is properly nested and 0 otherwise.

For example, given S = "`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

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

that, given a string S consisting of N characters, returns 1 if string S is properly nested and 0 otherwise.

For example, given S = "`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

func Solution(S string) int

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

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

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

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

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

function solution(S);

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

fun solution(S: String): Int

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

function solution(S)

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

int solution(NSString *S);

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

function solution(S: PChar): longint;

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

function solution($S);

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

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

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

def solution(S)

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

def solution(s)

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

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

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

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

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

A string S consisting of N characters is called *properly nested* if:

- S is empty;
- S has the form "
(U)" where U is a properly nested string;- S has the form "
VW" where V and W are properly nested strings.

For example, string "`(()(())())`" is properly nested but string "`())`" isn't.

Write a function:

Private Function solution(S As String) As Integer

`(()(())())`", the function should return 1 and given S = "`())`", the function should return 0, as explained above.

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

- N is an integer within the range [0..1,000,000];
- string S consists only of the characters "
(" and/or ")".

Information about upcoming challenges, solutions and lessons directly in your inbox.

© 2009–2020 Codility Ltd., registered in England and Wales (No. 7048726). VAT ID GB981191408. Registered office: 107 Cheapside, London EC2V 6DN