I have solved this in JavaScript fine however in Dart it is timing out in Test #5 even when running the below script to get the numbers it times out - this has to be an error with Dart?
4246 - 1073734557 = -1073730311
I think you may consider checking how you get -1073706325 and why you have skipped the expected answer by adding some code to print to the error stream.
Hi i wrote a O(n) algoritm to solve this puzzle. It pass all tests but test 5.
My code gives different result than expected.
I should be missing something but cant figure it out.
Any idea?
Is an error in test5 like Failure Found: -1071590351 Expected: -1073730311
means that there is actually a timeout happening behind the scenes or is there a hidden trap in test5’s dataset?
All the other tests are passing, and I optimized my code to run in a single loop reading the inputs with just 5 variables and zero data structures, so not too sure where to go from there optimization-wise.
(Using Java if it makes a difference)
I found this problem enjoyable. when I ran my program it passed every test case that was presented, except for the particular case where the input is [n1, n2, … 2, 2, 1] or [n1, n2, … 3, 2, 1] in which none of the test cases handled properly.
Hi Guys,
i have a problem with the last example (6), i need help.
import sys
import math
n,data,result,= int(input()),[],0
for i in input().split():
v = int(i)
data.append(v)
beforeD,maxD,minD= data[0],max(data),min(data)
if data.index(data[0]) != data.index(maxD):
if data.index(minD) > data.index(maxD):
result = (maxD-minD)*-1
print(result)
else:
newData = data[:data.index(minD)+1]
maxD = max(newData)
result = (maxD-minD)*-1
print(result)
else:
result = (maxD-minD)*-1
print(result)
In case you do not know, you may look up what the input is by clicking the button above the PLAY TESTCASE button. You should be able to debug by doing a manual calculation and comparing the calculation process with that done in your code.