---
title: Code snippets
description: This feature is enabled for all our customers.  A code snippet is a boilerplate code that can be used without changing it. This code helps such candidates who are not familiar with the online coding e
---

[Skip to content](https://help.hackerearth.com/hc/en-us/articles/360002884553-code-snippets#main-content)

English

Show submenu for translations

![HE logo.png\]](https://help.hackerearth.com/hs-fs/hubfs/HE%20logo.png?height=40&name=HE%20logo.png)

Open main navigation

Close main navigation

- English
  
  Show submenu for translations

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Help Center](https://help.hackerearth.com/?hsLang=en)
2. [Assessments: Recruiters](https://help.hackerearth.com/assessments-recruiters?hsLang=en)
3. [Programming](https://help.hackerearth.com/assessments-recruiters?hsLang=en#programming)

# Code snippets

*This feature is enabled for all our customers.* 

A code snippet is a boilerplate code that can be used without changing it. This code helps such candidates who are not familiar with the online coding environment to focus more on the algorithm that is required to solve the question rather than understanding the STD INPUT and OUTPUT syntaxes. 

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.

![codesnip\_1.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/codesnip_1-1.png)

In HackerEarth Assessment's in-built library, code snippets can be generated for Programming questions in the following languages:

- C
- C++
- C++14
- C++17
- C#
- Java
- Java 8
- JavaScript(Node.js)
- PHP
- Python
- Python 3
- Ruby
- Go
- Kotlin
- Objective-C
- Python 3.8
- Ruby
- Scala
- Swift

These code stubs are already loaded in the code editor of a question for candidates to use when they are attempting the test.

### 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) must 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

**Example**

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

![codesnip\_2.PNG](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/codesnip_2-1.png)

Add the input and output in the form of a code snippet to this question. This becomes 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. 

![code\_snippets.png](https://help.hackerearth.com/hs-fs/hubfs/Knowledge%20Base%20Import/code_snippets-1.png?width=522&height=622&name=code_snippets-1.png)

### Generating code snippets

To generate code stubs for a Programming question, follow these steps:

1. Log in to your HackerEarth Assessment account by using your admin credentials.
2. Click **Tests**.
3. Click the name of any tests in which you want to add code stubs to its Programming questions. For example, Algorithms test.
4. In the **Test details** section, click **Questions**.
5. Navigate to the Programming questions section and click the name of the question. The modal containing different parts of the question is displayed.
6. Click **Edit question**.  
   ![mceclip0.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip0-Jan-30-2023-11-34-41-2620-AM.png)
7. In the **Edit Programming question** section, click **Languages**.  
   ![mceclip1.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip1-Jan-30-2023-11-34-48-7523-AM.png)
8. Navigate to the **Code snippets** section and click **Auto generate**.  
   ![mceclip2.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip2-Jan-30-2023-11-34-46-2883-AM.png)
9. Enter or select the following details: 
     - Name of the function, for example, **func**
     - Return type, for example, **Integer**
     - Any comments that you want to add in your code, for example, **mycode**
     - Notify whether there are multiple test cases in a single file
     - Function parameter and name of the parameter, for example, **Character** and **test**  
       **Important**: If you want to add multiple parameters, then click **Add parameters**. If any function parameter is an array, ensure that the array values in your test case files are space-separated on a single line. For more information, see Input format for arrays.
10. Click **Generate code**.  
    ![mceclip3.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip3-Jan-30-2023-11-34-40-0894-AM.png)
11. To view your generated code, navigate to the **Generated code preview** section.
12. Click the name of the supported programming languages to view the generated code snippet.  
    ![mceclip4.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip4-Jan-30-2023-11-34-47-4426-AM.png)
13. Click **Use generated code** to use all the generated code snippets in the test. A confirmation message is displayed on the screen asking your permission to replace the existing code if any with the currently-generated code. Click **Overwrite** to use the generated code. If you wish to use the existing code, then click **Don't use generated code**.  
    ![mceclip5.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip5-Jan-30-2023-11-34-45-1162-AM.png)  
    Or  
    Click **Cancel** if you do not want to save the created code snippets. A confirmation message is displayed on your screen checking whether you want to discard the code snippets that you have created. Click **Discard generated code** to reject the automatically-generated code. If you want to keep your code, then click **Cancel**.  
    ![mceclip6.png](https://help.hackerearth.com/hubfs/Knowledge%20Base%20Import/mceclip6-Jan-30-2023-11-34-38-7833-AM.png)
14. Click **Publish changes** to save your code snippets into the question.

#### Input format for arrays

By default, the auto-generator creates snippets that read array elements as space-separated values on a single line. For example, for a question whose inputs are **n** (the size of the array), **arr\[n\]** (the array), and **d** (an integer), the input file is as follows:

```
31 5 2
```

If your question requires the array elements to be on separate lines, as follows:

```
31525
```

then set up the snippet in one of these two ways:

- **Use the auto-generator with a 2D array type.** Select the corresponding 2D array data type for the parameter — for example, **Integer 2D Array** — and then enter the number of elements in the array as the number of rows and **1** as the number of columns. The generated snippet then reads one element per line.  
  ![Screenshot from 2026-08-25 15-40-16](https://help.hackerearth.com/hs-fs/hubfs/Screenshot%20from%202026-08-25%2015-40-16.png?width=670&height=540&name=Screenshot%20from%202026-08-25%2015-40-16.png)
- **Write the code snippets manually.** Instead of using the auto-generator, write the snippet yourself for each language in which candidates can attempt the question.

You have successfully generated code snippets for your Programming questions.

You need to manually write or auto-generate code snippets for each language in which you want the candidates to attempt the question. 

 

- [Assessments: Recruiters](https://help.hackerearth.com/assessments-recruiters?hsLang=en#main-content)

    - [Getting started](https://help.hackerearth.com/assessments-recruiters?hsLang=en#getting-started)
    - [Account settings](https://help.hackerearth.com/assessments-recruiters?hsLang=en#account-settings)
    - [Admin management](https://help.hackerearth.com/assessments-recruiters?hsLang=en#admin-management)
    - [Creating tests automatically](https://help.hackerearth.com/assessments-recruiters?hsLang=en#creating-tests-automatically)
    - [Creating tests manually](https://help.hackerearth.com/assessments-recruiters?hsLang=en#creating-tests-manually)
    - [Test settings](https://help.hackerearth.com/assessments-recruiters?hsLang=en#test-settings)
    - [Sections and question pooling](https://help.hackerearth.com/assessments-recruiters?hsLang=en#sections-and-question-pooling)
    - [Libraries](https://help.hackerearth.com/assessments-recruiters?hsLang=en#libraries)
    - [Multiple Choice Questions (MCQs)](https://help.hackerearth.com/assessments-recruiters?hsLang=en#multiple-choice-questions-mcqs)
    - [Programming](https://help.hackerearth.com/assessments-recruiters?hsLang=en#programming)
    - [Project](https://help.hackerearth.com/assessments-recruiters?hsLang=en#project)
    - [SQL](https://help.hackerearth.com/assessments-recruiters?hsLang=en#sql)
    - [Data science](https://help.hackerearth.com/assessments-recruiters?hsLang=en#data-science)
    - [Machine Learning (ML)](https://help.hackerearth.com/assessments-recruiters?hsLang=en#machine-learning-ml)
    - [DevOps](https://help.hackerearth.com/assessments-recruiters?hsLang=en#devops)
    - [Python project questions](https://help.hackerearth.com/assessments-recruiters?hsLang=en#python-project-questions)
    - [Automation Testing](https://help.hackerearth.com/assessments-recruiters?hsLang=en#automation-testing)
    - [Java Project](https://help.hackerearth.com/assessments-recruiters?hsLang=en#java-project)
    - [C# project questions](https://help.hackerearth.com/assessments-recruiters?hsLang=en#c-project-questions)
    - [Subjective](https://help.hackerearth.com/assessments-recruiters?hsLang=en#subjective)
    - [Approximate](https://help.hackerearth.com/assessments-recruiters?hsLang=en#approximate)
    - [Diagram](https://help.hackerearth.com/assessments-recruiters?hsLang=en#diagram)
    - [File upload](https://help.hackerearth.com/assessments-recruiters?hsLang=en#file-upload)
    - [Invites](https://help.hackerearth.com/assessments-recruiters?hsLang=en#invites)
    - [Reports](https://help.hackerearth.com/assessments-recruiters?hsLang=en#reports)
    - [Billing](https://help.hackerearth.com/assessments-recruiters?hsLang=en#billing)
    - [HackerEarth Reports: Admins, Tests, and Teams](https://help.hackerearth.com/assessments-recruiters?hsLang=en#hackerearth-reports-admins-tests-and-teams)
    - [Technical Content Updates](https://help.hackerearth.com/assessments-recruiters?hsLang=en#technical-content-updates)
- [FaceCode](https://help.hackerearth.com/facecode?hsLang=en#main-content)

    - [FaceCode and its features](https://help.hackerearth.com/facecode?hsLang=en#facecode-and-its-features)
    - [Scheduling interviews on FaceCode](https://help.hackerearth.com/facecode?hsLang=en#scheduling-interviews-on-facecode)
- [Assessments: ATS integrations](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#main-content)

    - [Integration](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#integration)
    - [iCIMS](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#icims)
    - [Zoho Recruit](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#zoho-recruit)
    - [SmartRecruiters](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#smartrecruiters)
    - [EightFold](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#eightfold)
    - [SuccessFactors](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#successfactors)
    - [Greenhouse](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#greenhouse)
    - [Lever](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#lever)
    - [Linkedin Talent Hub](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#linkedin-talent-hub)
    - [JazzHR](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#jazzhr)
    - [Workable](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#workable)
    - [Recruiterbox - Trakstar Hire](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#recruiterbox-trakstar-hire)
    - [Jobvite](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#jobvite)
    - [Ashby](https://help.hackerearth.com/assessments-ats-integrations?hsLang=en#ashby)
- [Assessments: Product updates](https://help.hackerearth.com/assessments-product-updates?hsLang=en#main-content)

    - [Release notes: HackerEarth Assessment](https://help.hackerearth.com/assessments-product-updates?hsLang=en#release-notes-hackerearth-assessment)
    - [Root Cause Analysis (RCA)](https://help.hackerearth.com/assessments-product-updates?hsLang=en#root-cause-analysis-rca)
    - [Content updates](https://help.hackerearth.com/assessments-product-updates?hsLang=en#content-updates)
- [Assessments: Best practices](https://help.hackerearth.com/assessments-best-practices?hsLang=en#main-content)

    - [Recruit](https://help.hackerearth.com/assessments-best-practices?hsLang=en#recruit)
- [SSO](https://help.hackerearth.com/sso?hsLang=en#main-content)

    - [SSO](https://help.hackerearth.com/sso?hsLang=en#sso)
- [Upskilling](https://help.hackerearth.com/upskilling?hsLang=en#main-content)

    - [Introduction: Upskilling](https://help.hackerearth.com/upskilling?hsLang=en#introduction-upskilling)
- [Assessments: Candidates](https://help.hackerearth.com/assessments-candidates?hsLang=en#main-content)

    - [Getting started](https://help.hackerearth.com/assessments-candidates?hsLang=en#getting-started)
    - [Test environment](https://help.hackerearth.com/assessments-candidates?hsLang=en#test-environment)
    - [Question types](https://help.hackerearth.com/assessments-candidates?hsLang=en#question-types)
    - [FaceCode](https://help.hackerearth.com/assessments-candidates?hsLang=en#facecode)
    - [Feedback and queries](https://help.hackerearth.com/assessments-candidates?hsLang=en#feedback-and-queries)
- [Problem setting for HackerEarth](https://help.hackerearth.com/problem-setting-for-hackerearth?hsLang=en#main-content)

    - [Rate cards](https://help.hackerearth.com/problem-setting-for-hackerearth?hsLang=en#rate-cards)
- [Campus](https://help.hackerearth.com/campus?hsLang=en#main-content)

    - [Recruiters](https://help.hackerearth.com/campus?hsLang=en#recruiters)
    - [Recruiter FAQs](https://help.hackerearth.com/campus?hsLang=en#recruiter-faqs)
    - [Candidate FAQs](https://help.hackerearth.com/campus?hsLang=en#candidate-faqs)
- [Hackathons and Hiring Challenges](https://help.hackerearth.com/hackathons-and-hiring-challenges?hsLang=en#main-content)

    - [Hackathons](https://help.hackerearth.com/hackathons-and-hiring-challenges?hsLang=en#hackathons)
    - [Hiring challenges](https://help.hackerearth.com/hackathons-and-hiring-challenges?hsLang=en#hiring-challenges)
- [Frequently Asked Questions (FAQs)](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#main-content)

    - [Assessments: Recruiters](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#assessments-recruiters)
    - [GDPR compliance (Candidates)](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#gdpr-compliance-candidates)
    - [GDPR compliance (Recruiters)](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#gdpr-compliance-recruiters)
    - [General](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#general)
    - [Assessments: Candidates](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#assessments-candidates)
    - [HackerEarth Vs ChatGPT](https://help.hackerearth.com/frequently-asked-questions-faqs?hsLang=en#hackerearth-vs-chatgpt)
- [Profiles](https://help.hackerearth.com/profiles?hsLang=en#main-content)

    - [Profiles - Recruiter](https://help.hackerearth.com/profiles?hsLang=en#profiles-recruiter)
- [OnScreen](https://help.hackerearth.com/onscreen?hsLang=en#main-content)

    - [OnScreen - Interview templates](https://help.hackerearth.com/onscreen?hsLang=en#onscreen-interview-templates)
    - [OnScreen - Sending Invites](https://help.hackerearth.com/onscreen?hsLang=en#onscreen-sending-invites)
    - [OnScreen - Download reports](https://help.hackerearth.com/onscreen?hsLang=en#onscreen-download-reports)
    - [OnScreen - Interview Analytics](https://help.hackerearth.com/onscreen?hsLang=en#onscreen-interview-analytics)
    - [OnScreen - Overview](https://help.hackerearth.com/onscreen?hsLang=en#onscreen-overview)
    - [OnScreen - Interview Proctoring Settings](https://help.hackerearth.com/onscreen?hsLang=en#onscreen-interview-proctoring-settings)

[![Chill listening crop-3](https://help.hackerearth.com/hs-fs/hubfs/HE%20Logo%20for%20sig-1.png?width=120&height=24&name=HE%20Logo%20for%20sig-1.png "Chill listening crop-3")](https://www.hackerearth.com/)

Copyright © 2026, HackerEarth