programming_challenges

所属分类:编程语言基础
开发工具:kotlin
文件大小:0KB
下载次数:0
上传日期:2020-04-28 23:57:41
上 传 者sh-1993
说明:  编程挑战库,
(Programming challenges repository,)

文件列表:
.idea/ (0, 2020-04-28)
.idea/codeStyles/ (0, 2020-04-28)
.idea/codeStyles/Project.xml (381, 2020-04-28)
.idea/codeStyles/codeStyleConfig.xml (142, 2020-04-28)
.idea/kotlinc.xml (179, 2020-04-28)
.idea/misc.xml (273, 2020-04-28)
.idea/modules.xml (250, 2020-04-28)
.idea/vcs.xml (180, 2020-04-28)
src/ (0, 2020-04-28)
src/MainApplication.kt (562, 2020-04-28)
src/algorithms/ (0, 2020-04-28)
src/algorithms/C1XorAlgorithm.kt (712, 2020-04-28)
src/algorithms/C2HashAlgorithm.kt (747, 2020-04-28)
st-kt.iml (498, 2020-04-28)

Challenge 1

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.
For example, in array A such that:
`A[0] = 9 A[1] = 3 A[2] = 9`
`A[3] = 3 A[4] = 9 A[5] = 7`
`A[6] = 9` - the elements at indexes 0 and 2 have value 9, - the elements at indexes 1 and 3 have value 3, - the elements at indexes 4 and 6 have value 9, - the element at index 5 has value 7 and is unpaired.

Write a function

Given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.
For example, given array A such that:
`A[0] = 9 A[1] = 3 A[2] = 9`
`A[3] = 3 A[4] = 9 A[5] = 7`
`A[6] = 9` - The function should return 7, as explained in the example above. - Write an efficient algorithm for the following assumptions: * Space complexity O(1)
* Time complexity O(n)

Challenge 2

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one or more elements that is left unpaired.

Write a function

Given an array A consisting of N integers fulfilling the above conditions, returns the values of the unpaired elements.
For example, in array A such that:
`A[0] = 9 A[1] = 3 A[2] = 9`
`A[3] = 3 A[4] = 9 A[5] = 7`
`A[6] = 9 A[7] = 8 A[8] = 1`
- the function should return 7, 8, 1, as explained in the example above. - Write an efficient algorithm for the following assumptions: * Time complexity O(n)

近期下载者

相关文件


收藏者