Welcome to HackerRank DSL (Domain Specific Language) Documentation! You can use our the DSL to generate code stubs that read test case data from standard input in hackerrank challenges.
- Datatypes Supported
- Reading Variables
- Writing Loops
- Reading 1-D Array
- Reading 2-D Array
- Putting Comments
- Generating Functions
- Invoke a Function
- Print a Variable
- DSL In Action
- Bug Report or Need help?
- Integer:
integer
- Float:
float
- String:
string
- Boolean:
boolean
- Long Integer:
long_integer
- Character:
character
Syntax | Example |
---|---|
Datatype(variable_name) |
integer(a) |
At most 4 variables per line is supported | integer(n) integer(k) |
You can use loops to read multiple test cases.
Syntax | Example |
---|---|
loop(variable_name) {code} endloop |
loop(t) integer(n) endloop |
Syntax | Example |
---|---|
Array(Datatype,name,size,single) |
Array(integer,a,n,single) |
Array(Datatype,name,size,multi) |
Array(float,b,m,multi) |
Note: Type is single
if the array elements are on the same line. Otherwise, it should be multi
.
Warning: Don't leave any extra space.
Syntax | Example |
---|---|
2DArray(Datatype,name,size1,size2) |
2DArray(integer,a,n,m) |
Syntax |
---|
#Your own comment |
A special comment is #StartCode
, this will generate the text "your code goes here" as a comment.
Syntax | Example |
---|---|
Function(return_type, function_name, param_type1 name1, param_type2 name2, …) |
function(integer_array, solve, integer x, integer_array board) |
-
Return type/Param type supported:
- integer
- long_integer
- string
- integer_array/long_integer_array/string_array
- 2d_integer_array/2d_long_integer_array/2d_string_array (param only)
- void (return type only)
Syntax | Example |
---|---|
INVOKE(return_type, variable_name,function_name, param1, param2…) |
INVOKE(integer_array, result, solve, n, board[n]) |
- If the invoked function is void, return_type and variable_name should be “void”.
- If the param is a 1-d array, format is param[size]
Syntax | Example |
---|---|
PRINT(data_type, variable_name) |
PRINT(integer, result) |
PRINT(data_type, separator) |
PRINT(integer_array, result, +) PRINT(integer_array, result, NEWLINE) PRINT(integer_array, result, COMMA) |
-
The third parameter is optional. The default separator is space. The separator can be NEWLINE, SPACE, COMMA or any character.
-
Data_type supported are single integer/long_integer/string and 1-d integer/string/long_integer array.
Challege | DSL |
---|---|
https://www.hackerrank.com/challenges/mark-and-toys | integer(n) integer(k) Array(integer,a,n,single) |
https://www.hackerrank.com/challenges/two-arrays | integer(t) loop(t) integer(n) integer(k) Array(integer,a,n,single) endloop |
https://www.hackerrank.com/challenges/breaking-best-and-worst-records | FUNCTION(INTEGER_ARRAY, getRecord, INTEGER_ARRAY s) Integer(n) Array(integer,s,n,single) INVOKE(INTEGER_ARRAY, result, getRecord, s[n]) PRINT(INTEGER_ARRAY, result) |
https://www.hackerrank.com/challenges/cavity-map | integer(n) 2DArray(character,grid,n,n+1) |
If you have any doubt, contact HackerRank support, our engineers will reach you.
Hello ! Thanks for this documentation. I've a query. Using Array(integer,a,n,single) actually declares & reads the data into a vector. Same goes for passing it as an argument to a function. Is there a way that I can get a conventional C-style array instead of vector ?