Any tricks for dart. I pass everything except timeouts on the many horses.
Maybe the sort function for an array is too slow in dart? or am I missing something.
Any tricks for dart. I pass everything except timeouts on the many horses.
Maybe the sort function for an array is too slow in dart? or am I missing something.
Hello everyone,
I tried this exercise which is very interesting to learn some basicsā¦
I tried many ways to achieve the last test and yet, i still exceed the execution time.
I tried using arrays, then linked list but still doesnāt workā¦
Anyone can share some ideas/clues to succeed the last test.
Thanks in advance
On the cover page of the puzzle, there is a hint (I donāt mean the data structure, I mean the other one). Does your code implement that?
If your talking about finding the best complexity, iām working on it.
I was reading everything about the problem yesterday after sending my messageā¦^^
And i found that maybe iām missing this part, so iām working on it.
Thanks
It wasnāt yesterday, but 2 days ago, i had a problem posting the messageā¦^^
If you are coding in C++ on this puzzle and have issues with the test using a high number of horses, I finally found a trick! My code kept saying that it took too long, even when sorting before comparing par by pair. As it turns out, it was my debugging tests that caused issues! Using the ācerrā to display error messages adds a lot of time to the program, so if youāre using it try running the program without and it will go much quicker!
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
low = 0
for i in range(n):
pi = int(input())
st = []
st.append(pi)
print(st)
for j in range(n):
print(j)
temp = low
low = st[i] - st[j]
if temp > low:
answer = temp
print(answer)
# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
On my j loop I am getting a index out of bounds and I donāt understand why. It should only loop through n and for the first test thatās 3.
The āfor jā loop is nested inside the āfor iā loop, so the āfor jā loop tries to compare numbers when the āfor iā loop has not really read all the input numbers yet.
Thank you for the quick reply! I think I get it now. I would have to run the āfor iā loop first by its self, then send that through 2 nested for loops to check each index?
That may work for the cases with fewer input numbers. The approach may not be efficient enough for the cases with more numbers.
Hello KomiSerloot,
Thanks for your message but debugging isnāt my problem.
In fact I code on my side then i put my code into Codingame (without ācerrā so the debugging part).
My only problem must be the way i code, i donāt see any other reasonsā¦
Thanks again
Hi,
I donāt understand, the IDE donāt give me the right N (for the 1st test, N should be 4 but mine is 3)ā¦
Do you have the same problem ?
No. You may try copying out your code, resetting to the default code, and running the default code. You should be able to see the right N. Then figure out how to fix your code.
Thatās not how you spell duelsā¦
me too ,
I donāt know what is the problem!
Iām using Dart as a language
I let the first loop to save all values in a list
then I sort it
then I compare every value with its next value but this algo took me more than what proposed
How can I do better ?
A similar timeout issue occurred in another puzzle previously (https://forum.codingame.com/t/stock-exchange-losses-puzzle-discussion/40/150), but that one seems fixed. Iām not sure if this puzzle suffers from the same issue. My original solution which passed the puzzle also times out now.
Hi, Any one has completed in C, I really could not find how to optimise the solution am getting error timeout.
Please read the hint which can be found by clicking HINTS to the left of the puzzle statement. See if that helps you? If not, you may then read the cover page of the puzzle and look for another hint there
I got the solution now.I have used the merge sort and once the array is sorted in perfect time span remaining problems are resolved and all 3 Test case or passed now.
[nope]