+ 5
how to improve time period in our codes?
I was solving some challenges of hackerank. they have some time limits for the input? my first question is what is time limit for the input? and what are the ways in which we can improve it? // they give me results as runtime error as my codes usually exceed the time limit edit: sry! I dunno why there are too much tags I entered only four
11 Answers
+ 3
You can visit the following links, and read books and data on Competitive Programming in the language of your choice :
https://www.geeksforgeeks.org/writing-cc-code-efficiently-in-competitive-programming/
https://www.thegeekstuff.com/2015/01/c-cpp-code-optimization
https://stackoverflow.com/questions/6852670/how-to-write-fast-low-level-code
Also, you may try learning built-in functions, as they are usually handy when your implmentation is slower than expected.
+ 4
The time limit error usually occurs when your code is quite long, or uses multiple iterations or reserves a large amount of memory.
At the compiler level, even extra iterations in inplemented algorithms may create a large difference, especially when the time constraints are usually 1s or 2s.
So the best thing to do is review the challenge discussions and the highest rated codes posted in these challenges, and learn from them. Find how they tackled the same challenge and what was the factor that improved their code to the next level. In the beginning, it may be difficult to understand codes directly, so learning the basic algorithms may help as well. Eventually, you will be able to see improvement.
The most important factor though is participating in more and more challenges so that you eventually get the hang of what is to be done.
+ 3
what can I do for this in order to get my submission accepted in hackerank?
+ 3
thnx sirđ„đ„
+ 3
https://code.sololearn.com/c5OFTn4rVR7C/?ref=app
here's the code
can u tell me what cud be the possible reasons?
+ 3
@kinshuk vasisht
now i m getting it
its the problem with my algo.
i have to create a new one i think
one more question
how can we know about the stuffs which makes our program slow
and such similar questions
is there any link to know about such types of problems
thnx in advance
+ 3
@kinshuk thnx man!!!
you helped me a lot!!!
+ 2
thnx
and yes i think my code uses large amount of memory thats why it shows
Runtime Error - SIGSEGV
+ 1
@Saurabh Tiwari
The SIGSEGV error is not just due to a large amount of memory. Its more probably raised during a memory leak or accessing invalid memory locations.
+ 1
The code runs for me on GCC 4.9.2, but it seems the error occured as you simply initialized the array with a variable instead of a constant and that is no longer allowed without use of pointers. Also, you shouldn't declare variables inside loops as that can make programs slow.