-
-
Save marythought/f3567f3710bda3b0a629 to your computer and use it in GitHub Desktop.
Equi index attempts (w/fail details)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FIRST ATTEMPT | |
Code: 23:58:40 UTC, rb, final, score: 17.00 | |
def solution(a) | |
a.length.times do |index| | |
if index == 0 | |
return index if a[1..-1].reduce(:+) == 0 | |
elsif a[0...index].reduce(:+) == a[index+1..-1].reduce(:+) | |
return index | |
else | |
return -1 | |
end | |
end | |
end | |
Analysis summary | |
The following issues have been detected: wrong answers. | |
For example, for the input [] the solution returned a wrong answer (got 0, which is not valid array index). | |
Analysis | |
expand allExample tests | |
▶ example | |
Test from the task description ✔OK | |
expand allCorrectness tests | |
▶ simple ✔OK | |
▶ extreme_large_numbers | |
Sequence with extremely large numbers testing arithmetic overflow. ✔OK | |
▶ extreme_negative_numbers | |
Sequence with extremely large numbers testing arithmetic overflow. ✘WRONG ANSWER | |
got 1, which is not valid array index | |
▶ overflow_tests1 | |
arithmetic overflow tests ✔OK | |
▶ overflow_tests2 | |
arithmetic overflow tests ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 2 of A = [0, 2147483647, 2147483647, 2147483647] | |
▶ one_large | |
one large number at the end of the sequence ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 4 of A = [2, -1, -2, 1, 500] | |
1. 0.098 s OK | |
2. 0.102 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 4 of A = [2, -1, -2, 1, 500] | |
▶ sum_0 | |
sequence with sum=0 ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 3 of A = [1, 2, -3, 0] | |
1. 0.099 s OK | |
2. 0.099 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 3 of A = [1, 2, -3, 0] | |
▶ single_empty | |
single number or empty array ✘WRONG ANSWER | |
got 1, which is not valid array index | |
▶ combinations_of_two | |
multiple runs, all pairs of values: -1, 0 and 1 ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 1 of A = [0, -1] | |
1. 0.100 s OK | |
2. 0.101 s OK | |
3. 0.103 s OK | |
4. 0.100 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 1 of A = [0, -1] | |
5. 0.102 s OK | |
6. 0.100 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 1 of A = [0, 1] | |
7. 0.101 s OK | |
8. 0.101 s OK | |
9. 0.099 s OK | |
▶ combinations_of_three | |
multiple runs, all triples of values -1, 0 and 1 ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 2 of A = [-1, 1, 0] | |
▶ small_pyramid ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 42 | |
expand allCorrectness/performance tests | |
▶ extreme_max | |
Maximal size test ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 26681 | |
expand allPerformance tests | |
▶ large_long_sequence_of_ones ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 49998 | |
1. 0.145 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 49998 | |
▶ large_long_sequence_of_minus_ones ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 50001 | |
1. 0.147 s OK | |
2. 0.148 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 50001 | |
▶ medium_pyramid ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 62 | |
▶ large_pyramid | |
Large performance test, O(n^2) solutions should fail. ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 198 | |
▶ huge_pyramid | |
Large performance test, O(n^2) solutions should fail. ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 630 | |
SECOND ATTEMPT | |
Code: 00:53:01 UTC, rb, final, score: 64.00 | |
def solution(a) | |
a.length.times do |index| | |
if index == 0 | |
return index if a[1..-1].reduce(:+) == 0 | |
elsif index == a.length-1 | |
return index if a[0...index].reduce(:+) == 0 | |
elsif a[0...index].reduce(:+) == a[index+1..-1].reduce(:+) | |
return index | |
end | |
end | |
return -1 | |
end | |
Analysis summary | |
The following issues have been detected: wrong answers, timeout errors. | |
For example, for the input [0] the solution returned a wrong answer (got -1, but equilibrium point exists, for example on position 0 of A = [0]). | |
Analysis | |
Detected time complexity: | |
O(N**2) | |
expand allExample tests | |
▶ example | |
Test from the task description ✔OK | |
expand allCorrectness tests | |
▶ simple ✔OK | |
▶ extreme_large_numbers | |
Sequence with extremely large numbers testing arithmetic overflow. ✔OK | |
▶ extreme_negative_numbers | |
Sequence with extremely large numbers testing arithmetic overflow. ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 0 of A = [-2147483648] | |
1. 0.098 s WRONG ANSWER, got -1, but equilibrium point exists, for example on position 0 of A = [-2147483648] | |
2. 0.102 s OK | |
3. 0.099 s OK | |
▶ overflow_tests1 | |
arithmetic overflow tests ✔OK | |
▶ overflow_tests2 | |
arithmetic overflow tests ✔OK | |
▶ one_large | |
one large number at the end of the sequence ✔OK | |
▶ sum_0 | |
sequence with sum=0 ✔OK | |
▶ single_empty | |
single number or empty array ✘WRONG ANSWER | |
got -1, but equilibrium point exists, for example on position 0 of A = [0] | |
▶ combinations_of_two | |
multiple runs, all pairs of values: -1, 0 and 1 ✔OK | |
▶ combinations_of_three | |
multiple runs, all triples of values -1, 0 and 1 ✔OK | |
▶ small_pyramid ✔OK | |
expand allCorrectness/performance tests | |
▶ extreme_max | |
Maximal size test ✘TIMEOUT ERROR | |
running time: >6.00 sec., time limit: 0.60 sec. | |
expand allPerformance tests | |
▶ large_long_sequence_of_ones ✘TIMEOUT ERROR | |
running time: >6.00 sec., time limit: 0.60 sec. | |
▶ large_long_sequence_of_minus_ones ✘TIMEOUT ERROR | |
running time: >6.00 sec., time limit: 0.61 sec. | |
▶ medium_pyramid ✔OK | |
▶ large_pyramid | |
Large performance test, O(n^2) solutions should fail. ✔OK | |
▶ huge_pyramid | |
Large performance test, O(n^2) solutions should fail. ✘TIMEOUT ERROR | |
running time: 3.49 sec., time limit: 0.58 sec. | |
THIRD ATTEMPT | |
Code: 02:56:28 UTC, rb, final, score: 100.00 | |
def solution(a) | |
left = 0 | |
right = a.reduce(:+) | |
a.each_with_index do |value, index| | |
if index == 0 | |
right -= value | |
return index if a.length == 1 || right == 0 | |
elsif index == a.length-1 | |
left += a[index-1] | |
return index if left == 0 | |
else | |
left += a[index-1] | |
right -= value | |
return index if left == right | |
end | |
end | |
return -1 | |
end | |
Analysis summary | |
The solution obtained perfect score. | |
Analysis | |
Detected time complexity: | |
O(N) | |
expand allExample tests | |
▶ example | |
Test from the task description ✔OK | |
expand allCorrectness tests | |
▶ simple ✔OK | |
▶ extreme_large_numbers | |
Sequence with extremely large numbers testing arithmetic overflow. ✔OK | |
▶ extreme_negative_numbers | |
Sequence with extremely large numbers testing arithmetic overflow. ✔OK | |
▶ overflow_tests1 | |
arithmetic overflow tests ✔OK | |
▶ overflow_tests2 | |
arithmetic overflow tests ✔OK | |
▶ one_large | |
one large number at the end of the sequence ✔OK | |
▶ sum_0 | |
sequence with sum=0 ✔OK | |
▶ single_empty | |
single number or empty array ✔OK | |
▶ combinations_of_two | |
multiple runs, all pairs of values: -1, 0 and 1 ✔OK | |
▶ combinations_of_three | |
multiple runs, all triples of values -1, 0 and 1 ✔OK | |
▶ small_pyramid ✔OK | |
expand allCorrectness/performance tests | |
▶ extreme_max | |
Maximal size test ✔OK | |
expand allPerformance tests | |
▶ large_long_sequence_of_ones ✔OK | |
▶ large_long_sequence_of_minus_ones ✔OK | |
▶ medium_pyramid ✔OK | |
▶ large_pyramid | |
Large performance test, O(n^2) solutions should fail. ✔OK | |
▶ huge_pyramid | |
Large performance test, O(n^2) solutions should fail. ✔OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment