├── .gitignore ├── C++ └── README.md ├── CSharp ├── README.md ├── Sample.Tests.csproj └── Sample.csproj ├── Go └── README.md ├── Java ├── README.md ├── build.gradle └── pom.xml ├── NodeJS ├── README.md └── package.json ├── Python ├── README.md └── requirements.txt ├── README.md ├── Ruby ├── Gemfile ├── README.md └── Rakefile └── sample-io ├── Family ├── BD-IO-PS1 │ ├── input1.txt │ ├── input2.txt │ ├── output1.txt │ └── output2.txt └── BD-PS1 │ ├── input1.txt │ ├── input2.txt │ ├── output1.txt │ └── output2.txt ├── Tame-of-thrones └── BD-PS5 │ ├── input1.txt │ ├── input2.txt │ ├── output1.txt │ └── output2.txt ├── Traffic └── BD-PS3 │ ├── input1.txt │ ├── input2.txt │ ├── output1.txt │ └── output2.txt └── War └── BD-PS2 ├── input1.txt ├── input2.txt ├── output1.txt └── output2.txt /.gitignore: -------------------------------------------------------------------------------- 1 | CSharp/obj/ -------------------------------------------------------------------------------- /C++/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for C++. 2 | 3 | * [Build](#build) 4 | * [Correctness](#correctness) 5 | 6 | # Supported Versions 7 | 8 | * 11 9 | * 17 10 | 11 | # Build 12 | 13 | Every C++ application that doesn't use any Windows/Mac OS specific libraries can be built using the [g++ compiler](https://gcc.gnu.org/) on a Linux/Unix environment. It is one of the most popular way to build C++ projects. So we would be leveraging `g++ compiler` for the same. 14 | 15 | We require that you name your `Main` file as `main.cpp`. The folder containing the `main.cpp` will be considered as the root of your project and all the `g++` commands to build out the final executable will be fired from there. 16 | 17 | # Correctness 18 | 19 | We want you to name your `Main` file as `main.cpp`. This is the file that will contain your main method. 20 | 21 | This file should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 22 | 23 | For e.g your `main.cpp` file will look like this 24 | 25 | ```c++ 26 | int main(int argc, char *argv[]) { 27 | /*Sample code to read from file passed as command line argument*/ 28 | string filename = argv[1]; 29 | ifstream inputFile(filename); 30 | 31 | //Parse the file and call your code 32 | //Print the output 33 | 34 | inputFile.close(); 35 | return 0; 36 | } 37 | ``` 38 | 39 | We then build and execute the solution by the following commands. 40 | 41 | ``` 42 | cd path/to/main.cpp 43 | g++ .cpp .cpp ... .cpp main.cpp -o geektrust 44 | ./geektrust 45 | ``` 46 | 47 | ## Note :- 48 | 1. Put all your unit-test files if any, under a folder named `test`. 49 | 2. Make your code OS agnostic, we will be building and running your code in Ubuntu Linux environment. 50 | 51 | ## Starter Kit 52 | * [C++](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/cpp-none-starter-kit.zip) 53 | -------------------------------------------------------------------------------- /CSharp/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for C#. 2 | 3 | * [Build](#build) 4 | * [Correctness](#correctness) 5 | * [Unit tests](#unit-tests) 6 | 7 | # Supported Versions 8 | 9 | * 2.2 10 | * 3.1 11 | * 5.0 12 | 13 | # Build 14 | 15 | The only requirement here is you should add an `AssemblyName` entry with the value `geektrust` in your `.csproj` file. 16 | 17 | Given below is a sample 18 | 19 | ``` 20 | 21 | 22 | Exe 23 | netcoreapp3.1 24 | geektrust_family_demo 25 | 26 | geektrust 27 | 28 | 29 | ``` 30 | This will ensure that the `dll` file will be created by the name `geektrust.dll`. 31 | 32 | We then build the solution by the following commands. 33 | 34 | ``` 35 | dotnet build -o geektrust 36 | ``` 37 | 38 | # Correctness 39 | 40 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 41 | 42 | We then build and execute the solution by the following commands. 43 | 44 | ``` 45 | dotnet build -o geektrust 46 | dotnet geektrust/geektrust.dll 47 | ``` 48 | 49 | # Unit tests 50 | 51 | We expect you to create a separate project for Unit testing and assume that it will import the main project. 52 | 53 | We support `xUnit` and `NUnit` for unit testing and use [`Coverlet`](https://github.com/coverlet-coverage/coverlet) for checking the test coverage. Take a look at [this page](https://docs.microsoft.com/en-us/dotnet/core/testing/) for more info on unit testing in C# 54 | 55 | Given below is a sample `.csproj` file for `xUnit` 56 | 57 | ``` 58 | 59 | 60 | 61 | netcoreapp3.1 62 | false 63 | 64 | 65 | 66 | 67 | 68 | 69 | runtime; build; native; contentfiles; analyzers; buildtransitive 70 | all 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | ``` 81 | 82 | To execute the test cases we run the command 83 | 84 | ``` 85 | dotnet test 86 | ``` 87 | 88 | For calculating the coverage we run the command 89 | 90 | ``` 91 | dotnet test --collect="XPlat Code Coverage" 92 | ``` 93 | 94 | _Note_: Please refer [this sample application](https://github.com/geektrust/geektrust-csharp-family-demo) to know how a `C#` application will be checked for build, correctness & unit tests. 95 | 96 | ## Starter Kit 97 | * [CSharp Dotnet](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/csharp-dotnet.zip) 98 | -------------------------------------------------------------------------------- /CSharp/Sample.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | all 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CSharp/Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Exe 4 | netcoreapp3.1 5 | geektrust_family_demo 6 | 7 | geektrust 8 | 9 | -------------------------------------------------------------------------------- /Go/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for Golang. 2 | 3 | * [Build](#build) 4 | * [Correctness](#correctness) 5 | * [Unit tests](#unit-tests) 6 | 7 | # Supported Versions 8 | 9 | * 1.15.7 10 | * 1.16.8 11 | * 1.17 12 | 13 | # Dependency Management 14 | 15 | We only support the management of dependencies via [Go Modules](https://blog.golang.org/using-go-modules) 16 | 17 | # Build 18 | 19 | Every Go application can be built using the [go tool](https://golang.org/cmd/go/). It is the standard way to fetch, build, and install Go packages and commands. So we would be leveraging `go tool` for the same. The go tool requires you to organize your code in a specific way. Please read this [document](https://golang.org/doc/code.html) carefully. It explains the simplest way to get up and running with your Go installation. 20 | 21 | However we expect a few things from your package and directory structure 22 | 23 | ## Package & Directory structure of your Go application 24 | 25 | All your code for one coding problem should reside inside a package named `geektrust` under your Go workspace, which is typically the `GOPATH`. The name of the package should be `geektrust` and **NOT** be anything else. 26 | 27 | Create your `geektrust` package path with the command - `mkdir $GOPATH/src/geektrust` 28 | 29 | Your directory structure should then look like this. 30 | 31 | ``` 32 | bin/ 33 | geektrust # command executable 34 | src/ 35 | geektrust # main package 36 | main.go # start program file 37 | file_1.go # another file required 38 | subpackage1 # a sub package you may write 39 | subpackage1.go # a file under that sub package 40 | ``` 41 | 42 | The tree above shows a workspace containing the code you write to solve any Geektrust coding challenge in Go. The start file is `main.go` which may use `file_1.go` and the sub package `subpackage1`. The sub package will be imported by the files `main.go` and `file_1.go` with the help of base path `geektrust`. The import statement in this case will be 43 | 44 | ``` 45 | import geektrust/subpackage1 46 | ``` 47 | 48 | # Correctness 49 | 50 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 51 | 52 | This main file, `main.go` should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 53 | 54 | For e.g your `main.go` file will look like this 55 | 56 | ```go 57 | func main() { 58 | args := os.Args[1:] // absolute path to the test file 59 | // parse the file and process the command 60 | // print the output 61 | } 62 | 63 | ``` 64 | 65 | Once you have created your solution trying executing it by these commands from the directory `$GOPATH/src/geektrust`. 66 | 67 | ``` 68 | go build . 69 | ``` 70 | 71 | This will build an executable by the name `geektrust` in the directory `$GOPATH/src/geektrust` besides the `main.go` file . 72 | 73 | Execute the file from the directory `$GOPATH/src/geektrust` using the command 74 | ```go 75 | ./geektrust 76 | ``` 77 | 78 | We recommend it this way, so that the executable can load any relative files that you may be loading inside the application. 79 | 80 | 81 | # Unit tests 82 | 83 | The unit tests are ran and the coverage is calculated using the library [gotestsum](https://github.com/gotestyourself/gotestsum). This is independent of your solution and there is no need to add any dependency. However this will work only if you use Go Modules for dependency management. 84 | 85 | We execute the unit tests by running the following command from the directory `$GOPATH/src/geektrust` 86 | 87 | ``` 88 | gotestsum --hide-summary=all ./... 89 | ``` 90 | 91 | We check for the coverage of unit tests by executing the following command. from the directory `$GOPATH/src/geektrust` 92 | 93 | ``` 94 | gotestsum --hide-summary=all -- -coverprofile=cover.out ./... 95 | ``` 96 | 97 | ## Starter Kit 98 | * [Go](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/go-gotool.zip) 99 | -------------------------------------------------------------------------------- /Java/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for Java. 2 | 3 | * [Build](#build) 4 | * [Correctness](#correctness) 5 | * [Unit tests](#unit-tests) 6 | 7 | # Supported Versions 8 | 9 | * 1.8 10 | * 1.11 11 | 12 | # Build 13 | 14 | For Java we support 2 build systems 15 | * [Maven](http://maven.apache.org/) version 3.6.3 16 | * [Gradle](https://gradle.org/) version 5.1 17 | 18 | If you are new to build systems and have not used Maven or Gradle before, please read these articles to understand how to setup a Java project with: 19 | * [Maven - How to create a Java Project with Maven](https://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/) 20 | * [Gradle - Building Java Application with Gradle](https://guides.gradle.org/building-java-applications/) 21 | 22 | These articles are just guidelines to get you started. For Geektrust coding problems you have to use the `pom.xml` and `build.gradle` files we provide. You will have to use one of them in your Java project depending on what build file you select. Please download the files from here. 23 | * [Maven - pom.xml](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Java/pom.xml) 24 | * [Gradle - build.gradle](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Java/build.gradle) 25 | 26 | 27 | ## Maven 28 | 29 | In the Maven `pom.xml` file we have provided a [maven-assembly-plugin](https://maven.apache.org/plugins/maven-assembly-plugin/) which is used to create a single jar file, aggregated with its dependencies, modules, site documentation, and other files. Please do not edit the `finalName` (*geektrust* in this case) under its `configuration` section. Make sure the 'finalName' tag is inside the maven-assembly-plugin configuration. This should generate an executable 'geektrust.jar' in the target folder. 30 | 31 | Add the fully qualified name of your Main class file in the `mainClass` section under `manifest`. You can also edit the Group ID and the Artifact ID. 32 | 33 | For e.g if fully qualified name of your Main class in the project is `com.example.Main` then your `pom.xml` will look like this 34 | ``` 35 | 37 | 4.0.0 38 | com.example 39 | geektrust-problems 40 | 1.0 41 | 42 | 1.8 43 | 1.8 44 | UTF-8 45 | 1.8 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-assembly-plugin 53 | 54 | geektrust 55 | 56 | jar-with-dependencies 57 | 58 | false 59 | 60 | 61 | true 62 | 63 | com.example.Main 64 | 65 | 66 | 67 | 68 | 69 | 70 | make-assembly 71 | package 72 | 73 | single 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | ``` 83 | 84 | 85 | We build the solution by using the following command 86 | 87 | ``` 88 | mvn clean install -DskipTests -q assembly:single 89 | 90 | ``` 91 | 92 | ## Gradle 93 | 94 | In the Gradle `build.gradle` file we have provided a [Gradle Jar Task](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html) which is used to create a build jar file. Please do not edit the `archiveBaseName` (*geektrust* in this case) under its `jar` section, and add the fully qualified name of your Main class file in the `attributes` section under `manifest`. You can also edit the Group ID. You can also add your dependencies if any to the 'dependencies' section. 95 | The required gradle version is 5.1. This should generate an executable 'geektrust.jar' in the build/libs folder. 96 | 97 | For e.g if fully qualified name of your Main class in the project is `com.example.Main` then your `build.gradle` will look like this. 98 | 99 | ``` 100 | plugins { 101 | id 'java' 102 | } 103 | 104 | group = 'com.example' 105 | version = '1.0' 106 | sourceCompatibility = 1.8 107 | targetCompatibility = 1.8 108 | 109 | 110 | jar { 111 | archiveBaseName = 'geektrust' //Please do not change this final artifact name 112 | version = null //Please do not change this final artifact version 113 | manifest { 114 | attributes 'Main-Class' : 'com.example.Main' //This is main class of your program which will be executed 115 | } 116 | 117 | // To create a single jar with all dependencies. 118 | from { 119 | configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } 120 | } { 121 | exclude "META-INF/*.SF" 122 | exclude "META-INF/*.DSA" 123 | exclude "META-INF/*.RSA" 124 | } 125 | } 126 | 127 | repositories { 128 | mavenCentral() 129 | } 130 | 131 | //Add your dependencies here 132 | dependencies { 133 | } 134 | 135 | ``` 136 | 137 | We build the solution by using the following command 138 | 139 | ``` 140 | gradle clean build 141 | 142 | ``` 143 | 144 | # Correctness 145 | 146 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 147 | ## No build 148 | 149 | If you are providing a solution without using the build file, we want you to name your `Main` class as `Geektrust.java`. This is the file that will contain your main method. 150 | 151 | This file should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 152 | 153 | For e.g your `Geektrust.java` file will look like this 154 | 155 | ```java 156 | public class Geektrust { 157 | 158 | public static void main(String[] args) { 159 | String filePath = args[0]; 160 | //Parse the file and call your code 161 | //Print the output 162 | } 163 | .... 164 | .... 165 | } 166 | ``` 167 | 168 | We compile and run the solution by using the following commands. Make sure if your have any config files, it's in the classpath. 169 | 170 | ``` 171 | javac /Geektrust.java 172 | java -cp .Geektrust 173 | ``` 174 | 175 | ## Maven 176 | 177 | Once the `maven` command to build the solution is executed, then we run the following command to execute the code. 178 | 179 | ``` 180 | java -jar /geektrust.jar 181 | ``` 182 | 183 | ## Gradle 184 | 185 | Once the `gradle` command to build the solution is executed, then we run the following command to execute the code. 186 | 187 | ``` 188 | java -jar /geektrust.jar 189 | ``` 190 | 191 | 192 | # Unit tests 193 | 194 | We support only [JUnit](https://junit.org/junit5/) as the library to execute unit tests. JUnit should be added as a dependency to the build tool you are using, if you are writing unit tests for your solution. 195 | 196 | For checking the unit test coverage we use [JaCoCo](https://www.eclemma.org/jacoco/trunk/index.html) as a plugin in Maven and Gradle. 197 | 198 | ## Maven 199 | 200 | Please take a look at the `pom.xml` [file](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Java/pom.xml) we have provided. 201 | 202 | * JUnit 203 | 204 | Please add `JUnit` as a dependency under the dependencies section. 205 | 206 | ``` 207 | 208 | 1.8 209 | 1.8 210 | UTF-8 211 | 1.8 212 | 5.2.0 213 | 1.2.0 214 | 215 | 216 | 217 | 218 | org.junit.jupiter 219 | junit-jupiter-engine 220 | ${junit.jupiter.version} 221 | test 222 | 223 | 224 | ``` 225 | 226 | * JaCoCo 227 | 228 | JaCoCo need to be configured as a plugin for code coverage. A [jacoco-maven-plugin](https://www.eclemma.org/jacoco/trunk/doc/maven.html) is added under the `plugins` section. 229 | 230 | ``` 231 | 232 | 233 | org.jacoco 234 | jacoco-maven-plugin 235 | 0.8.7 236 | 237 | 238 | 239 | prepare-agent 240 | 241 | 242 | 243 | report 244 | test 245 | 246 | report 247 | 248 | 249 | XML 250 | ./ 251 | 252 | 253 | 254 | 255 | ``` 256 | 257 | We execute the unit tests using the command 258 | 259 | ``` 260 | mvn clean test 261 | mvn jacoco:report 262 | ``` 263 | 264 | ## Gradle 265 | 266 | Please take a look at the `build.gradle` [file](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Java/build.gradle) we have provided. 267 | 268 | 269 | * JUnit 270 | 271 | Please add the JUnit dependency as given in the `build.gradle` file. Do not edit any sections of this as it helps us in capturing your unit tests and coverage. 272 | 273 | ``` 274 | test { ///Please do not change this 275 | useJUnitPlatform() 276 | testLogging { 277 | events "PASSED", "SKIPPED", "FAILED", "STANDARD_ERROR" 278 | } 279 | finalizedBy jacocoTestReport // report is always generated after tests run 280 | afterSuite { desc, result -> 281 | if (!desc.parent) 282 | println("${result.resultType} " + 283 | "(${result.testCount} tests, " + 284 | "${result.successfulTestCount} successes, " + 285 | "${result.failedTestCount} failures, " + 286 | "${result.skippedTestCount} skipped)") 287 | } 288 | } 289 | repositories { 290 | mavenCentral() 291 | } 292 | 293 | //Add your dependencies here 294 | dependencies { 295 | testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.2.0' 296 | } 297 | ``` 298 | 299 | * JaCoCo 300 | 301 | JaCoCo plugin should be added like given below. 302 | 303 | ``` 304 | plugins { 305 | id 'java' 306 | id 'jacoco' 307 | } 308 | 309 | 310 | jacoco { //Please do not change this 311 | toolVersion = "0.8.4" 312 | reportsDir = file("$buildDir/jacoco") 313 | } 314 | 315 | jacocoTestReport { //Please do not change this 316 | reports { 317 | xml.enabled true 318 | csv.enabled false 319 | html.enabled false 320 | xml.destination file("./jacoco.xml") 321 | } 322 | } 323 | ``` 324 | 325 | We execute the unit tests using the command 326 | 327 | ``` 328 | gradle clean test 329 | ``` 330 | 331 | ## Starter Kits 332 | * [Maven](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/java-maven.zip) 333 | * [Gradle](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/java-gradle.zip) 334 | -------------------------------------------------------------------------------- /Java/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'jacoco' 4 | } 5 | 6 | group = 'com.example' 7 | version = '1.0' 8 | sourceCompatibility = 1.8 9 | targetCompatibility = 1.8 10 | 11 | jacoco { //Please do not change this 12 | toolVersion = "0.8.4" 13 | reportsDir = file("$buildDir/jacoco") 14 | } 15 | 16 | jacocoTestReport { //Please do not change this 17 | reports { 18 | xml.enabled true 19 | csv.enabled false 20 | html.enabled false 21 | xml.destination file("./jacoco.xml") 22 | } 23 | } 24 | 25 | jar { 26 | archiveBaseName = 'geektrust' //Please do not change this final artifact name 27 | version = null //Please do not change this final artifact version 28 | manifest { 29 | attributes 'Main-Class' : 'com.example.ExampleMain' //Change this to the main class of your program which will be executed 30 | } 31 | // To create a single jar with all dependencies. 32 | from { 33 | configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } 34 | } { 35 | exclude "META-INF/*.SF" 36 | exclude "META-INF/*.DSA" 37 | exclude "META-INF/*.RSA" 38 | } 39 | } 40 | 41 | test { ///Please do not change this 42 | useJUnitPlatform() 43 | testLogging { 44 | events "PASSED", "SKIPPED", "FAILED", "STANDARD_ERROR" 45 | } 46 | finalizedBy jacocoTestReport // report is always generated after tests run 47 | afterSuite { desc, result -> 48 | if (!desc.parent) 49 | println("${result.resultType} " + 50 | "(${result.testCount} tests, " + 51 | "${result.successfulTestCount} successes, " + 52 | "${result.failedTestCount} failures, " + 53 | "${result.skippedTestCount} skipped)") 54 | } 55 | } 56 | 57 | 58 | repositories { 59 | mavenCentral() 60 | } 61 | 62 | //Add your dependencies here 63 | dependencies { 64 | testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.2.0' 65 | } 66 | -------------------------------------------------------------------------------- /Java/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | {{maven.group.id}} 5 | {{maven.artifact.id}} 6 | 1.0 7 | 8 | 1.8 9 | 1.8 10 | UTF-8 11 | 1.8 12 | 5.2.0 13 | 1.2.0 14 | 15 | 16 | 17 | 18 | org.junit.jupiter 19 | junit-jupiter-engine 20 | ${junit.jupiter.version} 21 | test 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-assembly-plugin 31 | 32 | geektrust 33 | 34 | jar-with-dependencies 35 | 36 | false 37 | 38 | 39 | true 40 | 41 | {{this.is.your.qualified.name.of.main.class}} 42 | 43 | 44 | 45 | 46 | 47 | 48 | make-assembly 49 | package 50 | 51 | single 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.jacoco 59 | jacoco-maven-plugin 60 | 0.8.7 61 | 62 | 63 | 64 | prepare-agent 65 | 66 | 67 | 68 | report 69 | test 70 | 71 | report 72 | 73 | 74 | XML 75 | ./ 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /NodeJS/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for NodeJS using the NPM execution environment. 2 | 3 | * [Build](#build) 4 | * [Correctness](#correctness) 5 | * [Unit tests](#unit-tests) 6 | 7 | 8 | Under the NodeJS runtime environment, we execute Javascript and [Typescript](#Typescript) code. 9 | 10 | # Supported Versions 11 | 12 | * 12.6.0 13 | * 14.15.4 14 | * 16.10.0 15 | 16 | # Build 17 | 18 | For NodeJS we support the following dependency/build system as of now 19 | 20 | * [NPM](https://www.geeksforgeeks.org/node-js-npm-node-package-manager/) 21 | * [Yarn](https://yarnpkg.com/lang/en/) 22 | 23 | If you are using `Javascript` then your main file should be named as `geektrust.js`. 24 | ## NPM 25 | 26 | NPM is the default package manager for NodeJS. NPM can install all the dependencies of a project through the package.json file. It can also update and uninstall packages. In the package.json file, each dependency can specify a range of valid versions using the semantic versioning scheme, allowing developers to auto-update their packages while at the same time avoiding unwanted breaking changes. 27 | 28 | A sample `package.json` file can be downloaded from [here](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/NodeJS/package.json) 29 | 30 | In your `package.json` file make sure you have an entry for the following: 31 | 32 | 1. Start script which points to the execution of `geektrust.js` 33 | 2. Test script to execute all the unit tests present. 34 | 35 | ```javascript 36 | "scripts": { 37 | "start": "node geektrust.js", 38 | "test": "mocha" 39 | } 40 | ``` 41 | 42 | We run the following command to build you solution. 43 | 44 | ``` 45 | npm ci --silent 46 | ``` 47 | 48 | ## Yarn 49 | 50 | We also support yarn as a build tool if you want to use it. 51 | 52 | Your project should have the `package.json` file which handles all the dependencies. In that file make sure you have an entry for the start script which points to the execution of `geektrust.js` and a test script that executes all the unit tests present. 53 | 54 | ```javascript 55 | "scripts": { 56 | "start": "node geektrust.js", 57 | "test": "mocha" 58 | } 59 | ``` 60 | 61 | We build the solution by using the following command. 62 | 63 | ```javascript 64 | yarn install --silent 65 | ``` 66 | 67 | # Correctness 68 | 69 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 70 | 71 | This main file, `geektrust.js` should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 72 | 73 | For e.g your `geektrust.js` file will look like this 74 | 75 | ```javascript 76 | const filename = process.argv[2]; 77 | // parse the file and process the command 78 | // print the output 79 | ``` 80 | 81 | ## Execution 82 | 83 | ### No build 84 | 85 | We will execute the program using the command 86 | 87 | ``` 88 | node geektrust.js 89 | ``` 90 | 91 | ### NPM 92 | 93 | Once the `npm install` from the previous build process is complete, we will execute the program using the command 94 | 95 | ```javascript 96 | npm start --silent 97 | ``` 98 | 99 | ### Yarn 100 | 101 | Once the `yarn install` from the previous build process is complete, we will execute the program using the command 102 | 103 | ```javascript 104 | yarn run --silent start 105 | ``` 106 | 107 | # Unit tests 108 | 109 | For NodeJS we support the following frameworks for unit testing 110 | 111 | * [Mocha](https://mochajs.org/) 112 | * [Jest](https://jestjs.io/) 113 | 114 | For both the frameworks we use [Istanbul](https://istanbul.js.org/) as the code coverage tool. 115 | 116 | ## Execution 117 | 118 | ### Mocha 119 | 120 | After `npm install` Mocha based test cases are executed with the following command from the root folder 121 | 122 | ```javascript 123 | mocha test 124 | ``` 125 | ### Jest 126 | 127 | After `npm install` Jest based test cases are executed with the following command from the root folder 128 | 129 | ```javascript 130 | jest 131 | ``` 132 | 133 | # Typescript 134 | 135 | **Please note that we DO NOT support TypeScript for Automated Code Evaluation for parameters Object Modeling and Readability. That will be manually reviewd by our team. These instructions are only to get check the correctness and build parameters of the code.** 136 | 137 | ## Instructions for checking Correctness/Build 138 | 139 | Your main file should be named as `geektrust.ts`. 140 | 141 | As of now we only support Typescript under the NPM build system. This will require you to compile your typescript program into javascript. 142 | 143 | We run the commands `npm install --silent`, `npm start --silent` and `npm test --silent`. 144 | 145 | Please ensure that the `npm install` commands creates the file `geektrust.js` from your `geektrust.ts` file. The `npm start` command should then execute this `geektrust.js` file. 146 | 147 | In your `package.json` file make sure you have an entry for the install, start and test script. 148 | 149 | 1. The `install` command should install the dependencies and also build the `geektrust.js` file. 150 | 2. The `start` command will execute the program. 151 | 3. The `test` command should execute all the unit tests present 152 | 153 | ```javascript 154 | "scripts": { 155 | "install" :"", 156 | "start": "node geektrust.js", 157 | "test": "mocha" 158 | } 159 | ``` 160 | 161 | Note: If you create the `geektrust.js` file in some other folder (like dist/, build/ or out/)other than the main folder, then please appropriately edit the `start` command. 162 | 163 | ## Starter Kits 164 | * [Npm](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/nodejs-npm.zip) 165 | * [Yarn](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/nodejs-yarn.zip) 166 | -------------------------------------------------------------------------------- /NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "family-problem", 3 | "version": "1.0.0", 4 | "description": "Family Problem", 5 | "main": "geektrust.js", 6 | "scripts": { 7 | "start": "node geektrust.js", 8 | "test": "mocha" 9 | }, 10 | "license": "ISC", 11 | "dependencies": { 12 | "mocha": "^6.2.0" 13 | } 14 | } -------------------------------------------------------------------------------- /Python/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for Python. 2 | 3 | * [Correctness](#correctness) 4 | * [Build](#build) 5 | * [Unit tests](#unit-tests) 6 | 7 | # Supported Versions 8 | 9 | * 3.8 10 | * 3.9 11 | 12 | # Correctness 13 | 14 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 15 | 16 | The main file should be named `geektrust.py`. To check your solution we the execute the command 17 | ``` 18 | python -m geektrust 19 | ``` 20 | 21 | # Build 22 | ## No Build 23 | 24 | If you are providing a solution without using the build file, we want you to name your `Main` file as `geektrust.py`. This is the file that will contain your main method. 25 | 26 | This file should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 27 | 28 | For e.g your `geektrust.py` file will look like this 29 | 30 | ```python 31 | def main(): 32 | input_file = sys.argv[1] 33 | # sys.argv[1] should give the absolute path to the input file 34 | # parse the file and process the command 35 | # print the output 36 | 37 | if __name__ == "__main__": 38 | main() 39 | 40 | ``` 41 | 42 | We build and run the solution by using the following command. 43 | 44 | ``` 45 | python -m geektrust 46 | ``` 47 | 48 | ## Pip 49 | 50 | For Python we support only one build tool [Pip](https://pip.pypa.io/en/stable/user_guide/) 51 | 52 | Pip is package manager for Python. That means it’s a tool that allows you to install and manage additional libraries and dependencies that are not distributed as part of the standard library. 53 | 54 | The `pip install` command always installs the latest published version of a package, but sometimes, you may want to install a specific version that you know works with your code. You want to create a specification of the dependencies and versions you used to develop and test your application, so there are no surprises when you use the application in production. 55 | 56 | Requirement files allow you to specify exactly which packages and versions should be installed. 57 | 58 | A sample `requirements.txt` file can be downloaded from [here](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Python/requirements.txt) 59 | 60 | 61 | ### Building and running the solution 62 | 63 | The `Main` file should be named as `geektrust.py`. This is the file that will contain your main method. 64 | 65 | This file should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 66 | 67 | For e.g your `geektrust.py` file will look like this 68 | 69 | ```python 70 | def main(): 71 | input_file = sys.argv[1] 72 | # parse the file and process the command 73 | # print the output 74 | 75 | if __name__ == "__main__": 76 | main() 77 | 78 | ``` 79 | 80 | We build and run the solution by using the following commands 81 | 82 | ``` 83 | pip install -r requirements.txt 84 | python -m geektrust 85 | ``` 86 | 87 | 88 | # Unit tests 89 | 90 | For Python we currently support only the inbuilt [unittest](https://docs.python.org/3/library/unittest.html) framework. For test coverage we use [Coverage](https://coverage.readthedocs.io/en/coverage-5.5/) framework. 91 | 92 | The unit tests are checked by the command - 93 | 94 | ``` 95 | python -m unittest discover 96 | ``` 97 | 98 | The unit test coverage is found by the command - 99 | 100 | ``` 101 | coverage run -m unittest discover 102 | ``` 103 | 104 | ## Starter Kit 105 | * [Python Pip](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/python-pip.zip) 106 | -------------------------------------------------------------------------------- /Python/requirements.txt: -------------------------------------------------------------------------------- 1 | certifi>=2018.11.29 2 | chardet>=3.0.4 3 | idna>=2.8 4 | requests>=2.21.0 5 | urllib3>=1.24.1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Coding Problem Artefacts 2 | 3 | This is a repository which includes the instructions and artefacts required for solving the Backend [Geektrust coding problems](https://www.geektrust.in/coding-problem). Please only submit source files while submitting the solution. 4 | 5 | This document covers following aspects of code evaluation. 6 | 7 | * Correctness 8 | * Unit tests 9 | * Build 10 | 11 | ## Languages we support 12 | 13 | If you are solving the coding problem in any one of the languages given below, then follow the instructions from their respective ReadMe files by clicking on the link 14 | 15 | * [Java](Java/README.md) 16 | * [Python](Python/README.md) 17 | * [C#](CSharp/README.md) 18 | * [Ruby](Ruby/README.md) 19 | * [Go](Go/README.md) 20 | * [NodeJS/JavaScript/Typescript](NodeJS/README.md) 21 | * [C++](C++/README.md) 22 | 23 | 24 | ## Correctness 25 | 26 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 27 | 28 | Please see the read me files of the language you have choosen for more details. 29 | 30 | ## Unit tests 31 | 32 | Unit tests are written to ensure that your public methods are working correctly. We recommend you to write unit tests. Please see the read me files of the language you have choosen for more details. 33 | 34 | You can also submit your solution without unit tests. 35 | 36 | ## Build 37 | 38 | Build files help in automating the execution and testing for the solution. When you are writing your solution in a programming language that supports build & dependency management, we want you to add a build file to your solution, so that we can build, execute and test it. 39 | 40 | You are also free to write code without any build file too, but that will affect your evaluation. 41 | 42 | ## Support for other languages 43 | 44 | Apart from these we also support `Clojure`, `Erlang`, `Groovy`, `Kotlin`, `PHP` & `Scala` for our coding problems. However these do not have automated code correctness checks. If you language of choice is one of these, please make sure: 45 | 46 | * Your application is a command line application. 47 | * Your main file to execute is named as `geektrust.` 48 | * It takes in a command line argument which is the location of the text file containing the commands that needs to be executed by your program. 49 | * After processing, it should print only the output related to each command in the file. 50 | 51 | For e.g, if you re solving in **PHP**, and your input file is `/tmp/input1.txt` then the command for executing your code should be: 52 | 53 | ```php geektrust.php /tmp/input1.txt``` 54 | 55 | 56 | For e.g , in case of family problem, if the input file passed in has these commands 57 | 58 | ``` 59 | ADD_CHILD Chitra Aria Female 60 | GET_RELATIONSHIP Lavnya Maternal-Aunt 61 | GET_RELATIONSHIP Aria Siblings 62 | ``` 63 | 64 | then your solution should print. 65 | ``` 66 | CHILD_ADDITION_SUCCEEDED 67 | Aria 68 | Jnki Ahit 69 | ``` -------------------------------------------------------------------------------- /Ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rspec' 4 | gem 'rake' -------------------------------------------------------------------------------- /Ruby/README.md: -------------------------------------------------------------------------------- 1 | This document covers following aspects of code evaluation for Ruby. 2 | 3 | * [Build](#build) 4 | * [Correctness](#correctness) 5 | * [Unit tests](#unit-tests) 6 | 7 | # Supported Versions 8 | 9 | * 2.7.4 10 | * 3.0.2 11 | # Build 12 | 13 | We support the use of these build tools for Ruby 14 | 15 | * [Bundler](https://bundler.io/v2.0/man/bundle-install.1.html) 16 | * [Rake] (https://github.com/ruby/rake) 17 | * Bundler-Rake 18 | 19 | ## Bundler 20 | Create a Gemfile to add your dependencies, if any. Name your `Main` file as `geektrust.rb`. This is the file that will contain your main method. 21 | 22 | The `geektrust.rb` file should read the file path from the `ARGV` variable and then execute the program. This file should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 23 | 24 | For e.g your `geektrust.rb` file will look like this 25 | 26 | ```ruby 27 | def main 28 | input_file = ARGV[0] 29 | # parse the file and process the command 30 | # print the output 31 | end 32 | 33 | main 34 | ``` 35 | 36 | We will install the dependencies and then build the solution by using the following command. 37 | 38 | ```ruby 39 | bundle install 40 | ``` 41 | 42 | ## Rake 43 | 44 | Create a Rakefile with a default task like given in the sample file. The rake file should import the main ruby file, which is the starting point of your application and the call the main method within the default task. The main file should read the file path from the ARGV variable and then execute the program. 45 | 46 | For e.g your main.rb file will look like this 47 | ``` 48 | def main 49 | input_file = ARGV[1] 50 | # parse the file and process the command 51 | # print the output 52 | end 53 | ``` 54 | We build and run the solution by using the following command 55 | ``` 56 | rake default 57 | ``` 58 | ## Bundler-Rake 59 | 60 | This is the case where both `Gemfile` and `Rakefile` are used to manage the dependencies and build the solution. 61 | 62 | Create a Rakefile with a `default` task like given in the [sample file](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Ruby/Rakefile). The rake file should import the main ruby file, which is the starting point of your application and the call the `main` method within the `default` task. Also create a Gemfile to add your dependencies, if any. The main file should read the file path from the `ARGV` variable and then execute the program. 63 | 64 | For e.g your `main.rb` file will look like this 65 | 66 | ```ruby 67 | def main 68 | input_file = ARGV[1] 69 | # parse the file and process the command 70 | # print the output 71 | end 72 | ``` 73 | 74 | We build the solution by using the following command. 75 | 76 | ``` 77 | bundle install 78 | ``` 79 | 80 | # Correctness 81 | 82 | We expect your program to take the location to the text file as parameter. Input needs to be read from a text file, and output should be printed to the console. The text file will contain only commands in the format prescribed by the respective problem. 83 | 84 | ## Execution 85 | ### No build 86 | 87 | If you are providing a solution without using the build file, we want you to name your `Main` file as `geektrust.rb`. This is the file that will contain your main method. 88 | 89 | This file should receive in the command line argument and parse the file passed in. Once the file is parsed and the application processes the commands, it should only print the output. 90 | 91 | For e.g your `geektrust.rb` file will look like this 92 | 93 | ```ruby 94 | def main 95 | input_file = ARGV[0] 96 | # parse the file and process the command 97 | # print the output 98 | end 99 | 100 | main 101 | ``` 102 | 103 | We run the solution by using the following command. 104 | 105 | ```ruby 106 | ruby -W0 geektrust.rb 107 | ``` 108 | 109 | ### Bundler 110 | 111 | Once the `bundle install` command from the previous build process is complete, we will execute the program using the command 112 | 113 | ```ruby 114 | ruby -W0 geektrust.rb 115 | ``` 116 | 117 | ### Rake 118 | 119 | Once the `bundle install` command from the previous build process is complete, we will execute the program using the command 120 | 121 | ```ruby 122 | rake default 123 | ``` 124 | ### Bundler-Rake 125 | 126 | We will execute the program using the command 127 | 128 | ```ruby 129 | rake default 130 | ``` 131 | 132 | # Unit tests 133 | 134 | We support only [RSpec](https://rspec.info/) library for unit testing your Ruby code. We also use the code coverage tool [simple-cov](https://github.com/simplecov-ruby/simplecov) to calculate the unit test coverage. You are not expected to add the `simple-cov` library to your Gemfile, as it will be taken care by us. 135 | 136 | We expect the unit tests to be in either of these four folders: 137 | * spec 138 | * specs 139 | * test 140 | * tests 141 | 142 | ## Bundler 143 | 144 | We run the unit tests and calculate the coverage executing the command 145 | 146 | ```ruby 147 | rspec 148 | ``` 149 | 150 | ## Rake 151 | 152 | In your `Rakefile` add the `RSpec` task. 153 | 154 | ``` 155 | RSpec::Core::RakeTask.new(:spec) 156 | ``` 157 | 158 | Please see the [sample file](https://raw.githubusercontent.com/geektrust/coding-problem-artefacts/master/Ruby/Rakefile) provided. 159 | 160 | 161 | We run the unit tests and calculate the coverage executing the command 162 | 163 | ```ruby 164 | rspec 165 | ``` 166 | 167 | ## Bundler-Rake 168 | 169 | We run the unit tests and calculate the coverage executing the command 170 | 171 | ```ruby 172 | rspec 173 | ``` 174 | 175 | ## Starter Kit 176 | * [Rake](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/ruby-rake.zip) 177 | * [Bundler](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/ruby-bundler.zip) 178 | * [Bundler-Rake](https://geektrust.s3.ap-southeast-1.amazonaws.com/starter-kit/ruby-bundler-rake.zip) 179 | -------------------------------------------------------------------------------- /Ruby/Rakefile: -------------------------------------------------------------------------------- 1 | require './main.rb' 2 | task :default do |t, args| 3 | main 4 | end 5 | 6 | RSpec::Core::RakeTask.new(:spec) -------------------------------------------------------------------------------- /sample-io/Family/BD-IO-PS1/input1.txt: -------------------------------------------------------------------------------- 1 | ADD_CHILD Ginerva John Male 2 | GET_RELATIONSHIP Ginny Paternal-Uncle 3 | GET_RELATIONSHIP Darcy Brother-In-Law -------------------------------------------------------------------------------- /sample-io/Family/BD-IO-PS1/input2.txt: -------------------------------------------------------------------------------- 1 | GET_RELATIONSHIP Darcy Sister-In-Law 2 | GET_RELATIONSHIP Charlie Son 3 | GET_RELATIONSHIP Daniel Daughter -------------------------------------------------------------------------------- /sample-io/Family/BD-IO-PS1/output1.txt: -------------------------------------------------------------------------------- 1 | CHILD_ADDITION_SUCCEEDED 2 | James John 3 | Albus John -------------------------------------------------------------------------------- /sample-io/Family/BD-IO-PS1/output2.txt: -------------------------------------------------------------------------------- 1 | Lily 2 | NONE 3 | PERSON_NOT_FOUND -------------------------------------------------------------------------------- /sample-io/Family/BD-PS1/input1.txt: -------------------------------------------------------------------------------- 1 | ADD_CHILD Satya Ketu Male 2 | GET_RELATIONSHIP Kriya Paternal-Uncle 3 | GET_RELATIONSHIP Satvy Brother-In-Law 4 | 5 | -------------------------------------------------------------------------------- /sample-io/Family/BD-PS1/input2.txt: -------------------------------------------------------------------------------- 1 | GET_RELATIONSHIP Satvy Sister-In-Law 2 | GET_RELATIONSHIP Ish Son 3 | GET_RELATIONSHIP Misha Daughter -------------------------------------------------------------------------------- /sample-io/Family/BD-PS1/output1.txt: -------------------------------------------------------------------------------- 1 | CHILD_ADDITION_SUCCEEDED 2 | Asva Ketu 3 | Vyas Ketu 4 | -------------------------------------------------------------------------------- /sample-io/Family/BD-PS1/output2.txt: -------------------------------------------------------------------------------- 1 | Atya 2 | NONE 3 | PERSON_NOT_FOUND -------------------------------------------------------------------------------- /sample-io/Tame-of-thrones/BD-PS5/input1.txt: -------------------------------------------------------------------------------- 1 | AIR ROZO 2 | LAND FAIJWJSOOFAMAU 3 | ICE STHSTSTVSASOS -------------------------------------------------------------------------------- /sample-io/Tame-of-thrones/BD-PS5/input2.txt: -------------------------------------------------------------------------------- 1 | AIR OWLAOWLBOWLC 2 | LAND OFBBMUFDICCSO 3 | ICE VTBTBHTBBBOBAB 4 | WATER SUMMER IS COMING -------------------------------------------------------------------------------- /sample-io/Tame-of-thrones/BD-PS5/output1.txt: -------------------------------------------------------------------------------- 1 | SPACE AIR LAND ICE -------------------------------------------------------------------------------- /sample-io/Tame-of-thrones/BD-PS5/output2.txt: -------------------------------------------------------------------------------- 1 | NONE -------------------------------------------------------------------------------- /sample-io/Traffic/BD-PS3/input1.txt: -------------------------------------------------------------------------------- 1 | RAINY 40 25 -------------------------------------------------------------------------------- /sample-io/Traffic/BD-PS3/input2.txt: -------------------------------------------------------------------------------- 1 | SUNNY 12 10 -------------------------------------------------------------------------------- /sample-io/Traffic/BD-PS3/output1.txt: -------------------------------------------------------------------------------- 1 | CAR ORBIT2 -------------------------------------------------------------------------------- /sample-io/Traffic/BD-PS3/output2.txt: -------------------------------------------------------------------------------- 1 | TUKTUK ORBIT1 2 | -------------------------------------------------------------------------------- /sample-io/War/BD-PS2/input1.txt: -------------------------------------------------------------------------------- 1 | FALICORNIA_ATTACK 150H 96E 26AT 8SG -------------------------------------------------------------------------------- /sample-io/War/BD-PS2/input2.txt: -------------------------------------------------------------------------------- 1 | FALICORNIA_ATTACK 250H 50E 20AT 15SG -------------------------------------------------------------------------------- /sample-io/War/BD-PS2/output1.txt: -------------------------------------------------------------------------------- 1 | WINS 75H 50E 10AT 5SG -------------------------------------------------------------------------------- /sample-io/War/BD-PS2/output2.txt: -------------------------------------------------------------------------------- 1 | LOSES 100H 38E 10AT 5SG --------------------------------------------------------------------------------