A code snippet is boilerplate code which is code that can be used without changing it.
When a candidate writes code, it is evaluated using input (STDIN) and output (STDOUT).
- STDIN: The default source of providing input to any computer program.
- STDOUT: The default channel where the output of the program is written.
In HackerEarth Recruit's in-built library, code snippets are available in programming questions for the following languages:
- Java 8
- Python 3
These are pre-loaded in the code editor for candidates to use in their tests.
Use of code snippets
Candidates who take online coding tests are usually not familiar with the online coding process. There may not be enough time for a candidate to understand HackerEarth’s evaluation process—specifically how the input (STDIN) and output (STDOUT) should be written to ensure that the evaluation process runs correctly.
If the code snippet is already available, then the candidate can do the following:
- Focus on writing the logic that is required to solve the problem
- Not spend time figuring out the input (STDIN) and output (STDOUT) that needs to be used
A candidate must write the code to add N numbers (1, 2, 3…N). The code will be as follows:
Note: The code has been written in different colors only for clarity. In this code the colors mean the following:
- blue = input
- orange = logic
- green = output.
Add the input and output in the form of a code snippet to this question. This will be visible to the candidates when they are attempting this question. The candidates can then focus only on writing the logic required to calculate the sum of N numbers.