Skip to content

Instantly share code, notes, and snippets.

@Shafaet
Forked from abhiranjankumar00/dslwiki.md
Last active October 29, 2023 16:22
Show Gist options
  • Save Shafaet/86afa48a54ae1d5dc46fa80542d7b10a to your computer and use it in GitHub Desktop.
Save Shafaet/86afa48a54ae1d5dc46fa80542d7b10a to your computer and use it in GitHub Desktop.
DSL Documentation

image

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

  • Integer: integer
  • Float: float
  • String: string
  • Boolean: boolean
  • Long Integer: long_integer
  • Character: character

Reading variables

Syntax Example
Datatype(variable_name) integer(a)
At most 4 variables per line is supported integer(n) integer(k)

Writing Loops

You can use loops to read multiple test cases.

Syntax Example
loop(variable_name)
{code}
endloop
loop(t)
integer(n)
endloop

Reading 1-D Array

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.

Reading 2-D Array

Syntax Example
2DArray(Datatype,name,size1,size2) 2DArray(integer,a,n,m)

Putting Comments

Syntax
#Your own comment

A special comment is #StartCode, this will generate the text "your code goes here" as a comment.

Generating Functions

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)

Invoke a Function

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]

Print a variable

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.

DSL In Action

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)

Support

If you have any doubt, contact HackerRank support, our engineers will reach you.

@SudhanshuBlaze
Copy link

How can we write a DSL for reading queue, such that the function invoked has Queue as a parameter?

@dbc2201
Copy link

dbc2201 commented Mar 22, 2023

Is it possible to specify the return type as a complex type like Map in Java?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment