Skip to content

Instantly share code, notes, and snippets.

@Shafaet
Forked from abhiranjankumar00/dslwiki.md
Last active October 16, 2024 14:48
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.

@vallathn
Copy link

integer(T)
loop(T)
integer(len)
Array(integer,a,len,single)
endloop

@theHurda
Copy link

Is it possible to name the looping variable? And also to use it in the print afterwards?

@ankurkumar222
Copy link

How to read a linkedlist or binary tree from input kindly suggest.

@Garmon-Parnas
Copy link

Some Hackerrank challenges do include non-editable code, e.g. this. It seems that these problems' code stub has been generated using DSL. How can this be achieved?
I mean, there are lots of problems that are intended to require the use of some framework, and you cannot enforce it if everything can be put up-down. How can we set up a challenge with a read-only head and/or tail?

@kivrakh
Copy link

kivrakh commented Apr 6, 2020

How can we set up a challenge with a read-only head and/or tail?

That's a great question! Did you find the solution? Thanks in advance.

Copy link

ghost commented Apr 28, 2020

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 ?

@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?

@gargig02
Copy link

How to declare functions with pointers as parameters?

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