General Information

For solving filesystem-enabled CodeSignal challenges, you should edit some or all of the non-locked files (or create new ones) to implement the requirements and pass the Unit Tests specified in the locked files.

Supported testing frameworks:

  1. JUnit with Maven or Gradle
  2. Mocha
  3. unittest (python2, python3)
  4. RSpec

For solving single-file CodeSignal challenges, you should implement a function in your preferred language. When submitted, your function is wrapped in a class/closure, so some declarations may result in a Syntax (Compilation) Error. Keep the following details in mind:

  1. Your code should declare a function/method with exactly the same name that is specified in the challenge. Changing its name will result in a syntax error.
  2. You can log any data in the console for debugging purposes (e.g. console.log in JS, std::cout in C++).
  3. If the value of some input/output argument is a string that contains double quote characters (") it will be shown in the output with an additional \ symbol. E.g. inputString = hello"world"hello will be displayed in the console as "hello\"world\"hello".

Verdicts

After you submit your code for testing, the following verdicts are possible:

  1. Compilation/syntax error - This means you probably have some syntax errors in your source code. More detailed information will be given along with the verdict to help you identify the issue.
  2. Execution error - This means your code has crashed. Most likely, it crashes only for some input parameters. More detailed information will be given along with the verdict to help you identify the issue.
  3. Compilation time exceeded - This verdict happens rarely, mostly for C++ or Java. This means that your code is either too long or you overused templates, which results in very slow compilation of your code.
  4. Execution limit exceeded - This means that your code didn't finish executing within the given time limit. It either got hung up on one of the test cases, or it just works very slowly. It's likely that your solution is either not optimally efficient, or you have a bug in the code.
  5. Output limit exceeded - This verdict happens rarely. It means that either your function return value size is too big (e.g. you returned a very big array or matrix), or that you overused console outputs and essentially spammed it with a lot of data. One possible cause of such an issue is that you have a console output inside an infinite loop.
  6. Wrong answer - This verdict means that your code was compiled and ran successfully, but it returned an incorrect output for one or more test cases. More detailed information will be provided to help you diagnose the issue.
  7. All tests passed - This means that your code works correctly and passed all the tests within the given time limit.

Languages

We support a variety of compilers and languages. You can solve each challenge in your preferred language by clicking on the language switcher icon in the upper right corner of the IDE.

In the following sections, you'll find detailed information about each available language and compiler. Languages are organized alphabetically.

Bash

For DevOps challenges, you are required to write bash scripts, which should print required data to stdout.

C

The compiler used on the site is gcc 7.1 C11 enabled. You can use printf(...) to print any data for debugging purposes.
The following libraries are automatically included:

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdint.h>
#include <math.h>

C++

We support g++ 7.1.0 c++17 enabled. Feel free to use unordered_map, regex, range for, auto ... features from C++11, 14 and 17 standards.

The following libraries are automatically included:

#include <iostream>
#include <fstream>
#include <vector>
#include <cstdarg>
#include <string>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <climits>
#include <sstream>
#include <numeric>
#include <iterator>
#include <iomanip>
#include <utility>
#include <stack>
#include <functional>
#include <deque>
#include <complex>
#include <bitset>
#include <list>
#include <array>
#include <regex>
#include <random>
#include <unordered_set>
#include <unordered_map>

Some best practices for C++:

  1. When declaring global variables in C++, initializing them during declaration will result in a syntax error. Instead, perform an initialization in the function/method.
  2. Static variables are disabled in C++, so using them will lead to unexpected results.
  3. Add using namespace std; at the beginning of the function in order to use std features without std:: prefix.
  4. Please use std::cout to print any data for debugging purposes.
  5. Use C++11, 14 and 17 features, e.g. for (auto x: vec) {...}, lambda functions [](int a, int b) -> bool {...}.

C#

The compiler used on the site is Mono C# compiler version 5.0.1.1. Please use Console.Write(...) to print any data for debugging purposes.

The following libraries are automatically included:

using System;
using System.IO;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using SimpleJson.Reflection;
using System.Text.RegularExpressions;
using System.Linq;

Clojure

The Clojure version used on the site is Clojure 1.8.

  1. Please use (print ...) or (println ...) to print any data for debugging purposes.

The following libraries are automatically imported:

(:require [clojure.string :as string])
(:require [clojure.core :as core])
(:require [clojure.core.reducers :as r])
(:require [clojure.set :as set])
(:require [clojure.java.io :as io])

You can use your own requires. For example:

(require '[<some library>])
(require '[<some other library> :as <library alias>])

CoffeeScript

The CoffeeScript version used on the site is CoffeeScript 2.0.0.

  1. Please use console.log ... to print any data for debugging purposes.

Common Lisp

The Common Lisp version used on the site is CLisp 2.49.

  1. Please use (write ...) or (write ...) (terpri) to print any data for debugging purposes.

D

The compiler used on the site is DMD64 D Compiler v2.074. Please use write(...) or writeln(...) to print any data for debugging purposes.

The following libraries are automatically included:

import std.algorithm, std.array, std.format, std.range, std.regex,
  std.conv, std.stdio, std.math, std.string, std.container;

Dart

The compiler used on the site is Dart VM 1.24.2. You can use print(...), stdout.write(...) or stdout.writeln(...) to print any data for debugging purposes.

The following libraries are automatically imported:

import 'dart:core';
import 'dart:io';
import 'dart:convert';
import 'dart:math';
import 'dart:async';

Elixir

The compiler used on the site is Elixir 1.4.5. You can use IO.write(...) or IO.puts(...) to print any data for debugging purposes.
Strings are given as standard UTF-8 binaries and Chars are given as a codepoints, but both the binaries and char lists are accepted in the output.

Erlang

The compiler used on the site is Erlang/OTP 20.0. You can use io:fwrite(...) to print any data for debugging purposes.

Fortran

The compiler used on the site is GNU Fortran 7.1.0 with -ffree-form -std=f2008. You can use print *, ... to print any data for debugging purposes.

Free Pascal

The Free Pascal version used on the site is Free Pascal 3.0.0+dfsg-2. Please use write(...) or writeln(...) to print any data for debugging purposes.

The following libraries are automatically included:

uses sysutils,
     math,
     strutils,
     dateutils,
     fpjson,
     fgl;

F#

The compiler used on the site is Mono F# 4.1.

  1. Please use printf to print any data for debugging purposes.
  2. Arrays are used as input parameters instead of lists.
  3. Return type is mentioned explicitly, so you should return an object of the exact type.

The following libraries are automatically included:

open System
open System.IO
open System.IO.Text
open System.Globalization

Go

The compiler used on the site is Go 1.8.1. Please use fmt.Printf(...) to print any data for debugging purposes.

The following libraries are automatically included:

import "fmt"
import "bufio"
import "io"
import "log"
import "os"
import "strconv"
import "bytes"

Groovy

The Groovy version used on the site is Groovy 2.4.12.

  1. Please use print ... or println ... to print any data for debugging purposes.

The following libraries are automatically included:

import java.math.*;
import java.util.regex.*;
import java.util.stream.*;
import java.text.*;
import java.security.SecureRandom;
import java.util.function.*;
import java.util.concurrent.*;
import groovy.json.*;

Haskell

The compiler used on the site is GHC 7.10.3. Please use unsafePerformIO and print ... to print any
data for debugging purposes. Here's an example of the add function with debug output:

add a b = unsafePerformIO $ do
  print "test"
  print a
  return $ a + b

The following libraries are automatically included:

import Data.Array
import Data.Bits
import System.IO.Unsafe (unsafePerformIO)
import Debug.Trace (trace)

Java

The compiler used on the site is Java 10.0.2.

  1. Please use System.out.println(...) to print any data for debugging purposes.
  2. When declaring global variables in Java, initializing them during declaration will result in a syntax error. Instead, perform an initialization in the function/method.

The following libraries are automatically included:

import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.*;
import java.util.stream.*;
import java.text.*;
import java.security.SecureRandom;
import java.util.function.*;
import java.util.concurrent.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.*;
import com.fasterxml.jackson.databind.*;

Julia

The compiler used on the site is Julia 0.6.0. You can use println(...) or print(...) to print any data for debugging purposes.

Kotlin

The Kotlin version used on the site is Kotlin 1.1.3.

  1. Please use print(...) or println(...) to print any data for debugging purposes.

The following libraries are automatically included:

import kotlin.comparisons.*;
import kotlin.collections.*;
import kotlin.io.*;
import kotlin.jvm.*;
import kotlin.jvm.functions.*;
import kotlin.jvm.internal.*;
import kotlin.ranges.*;
import kotlin.sequences.*;
import kotlin.text.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.*;
import java.util.stream.*;
import java.text.*;
import java.security.SecureRandom;
import java.util.function.*;
import java.util.concurrent.*;

Lua

The Lua version used on the site is LuaJit 2.0.5.

  1. Please use print(...) to print any data for debugging purposes.

MySQL

The compiler used on the site is MySQL 14.14 Distrib 5.7.18.

Nim

The compiler used on the site is Nim Compiler Version 0.17.0. You can use echo(...), stdout.write(...) or stdout.writeLine(...) to print any data for debugging purposes.

The following libraries are automatically imported:

import system
import strutils
import sequtils

JavaScript/NodeJS

We support Node v8.1.2 compiler with almost all ES2015 features.
Some best practices for Nodejs:

  1. Please use console.log() to print any data to the console for debugging purposes.
  2. Use arrow functions () => {} and other ES2015 features to write concise and clear code.

Included NPM packages:

- sequelize
- underscore
- crypto-js
- lodash
- request
- shelljs
- http
- sys
- jquery
- async
- connect
- mysql
- mysql2
- validator
- ws
- co
- when
- forever
- debug

React

Uses development standalone versions of the following packages:

Objective-C

The compiler used on the site is Clang 3.8. You can use printf(...) or NSPrint(...) to print any data for debugging purposes.
Note that NSLog(...) won't work, but NSPrint(...) is an alternative with the same interface.
The following libraries are automatically included:

#import <objc/objc.h>
#import <objc/Object.h>
#import <Foundation/Foundation.h>
#include <stdio.h>
#include <math.h>

Octave

The compiler used on the site is GNU Octave 4.0.0. You can use disp(...) to print any data for debugging purposes.

OCaml

The compiler used on the site is OCaml version 4.02.3. Please use print_string(...) or print_endline(...) to print any data for debugging purposes.
OCaml Batteries included 2.4 is installed and can be used by adding open Batteries to the beggining of your program.

Perl

The compiler version used on the site is Perl 5.22.1. Please use print ... to print any data for debugging purposes.

The following libraries are automatically included:

use warnings;
use JSON;

PHP

The compiler version used on the site is PHP 7.1.6. Please use echo ... to print any data for debugging purposes.

PostgreSQL

The compiler used on the site is PostgreSQL 9.5.14.

Python2

The Python2 version used on the site is 2.7.15.

  1. For information about the differences between python2 and python3, consult The Python Language Wiki.
  2. Please use print ... to print any data for debugging purposes.

The following libraries are automatically imported:

import math
import string
import re
import random
import functools

Python3

The Python3 version used on the site is 3.6.6.

  1. For information about the differences between python3 and python2, consult The Python Language Wiki.
  2. Please use print ... to print any data for debugging purposes.

The following libraries are automatically imported:

import math
import string
import re
import random
import functools

R

The compiler used on the site is R 3.4.0. Please use cat(...) or print(...) to print any data for debugging purposes.
Return list for the challenges where return value is array.
Use I(x) if you want a single element list/vector x to be treated as a list and not as a scalar in the output.

The following libraries are automatically included:

library(jsonlite)
library(stringr)

Ruby

The compiler used on the site is ruby 2.4.1. Please use puts ... to print any data for debugging purposes.

The following libraries are automatically included:

require 'json'
require 'stringio'

Rust

The compiler used on the site is rustc 1.19.0. You can use print!(...) or println!(...) to print any data for debugging purposes.

The following libraries are automatically included:

use std::io::prelude::*;
use std::io::{BufReader, Lines};
use std::fs::File;

Scala

The compiler used on the site is Scala 2.11.6. Please use println(...) to print any data for debugging purposes.

Smalltalk

The compiler used on the site is GNU Smalltalk 3.2.5. You can use ... display or Transcript show: ... to print any data for debugging purposes.

Swift

The compiler used on the site is Swift 3.1. Please use print(...) to print any data for debugging purposes.

The following libraries are automatically included:

import Foundation

Tcl

The Tcl version used on the site is undefined with Tcllib installed. You can use puts to print any data for debugging purposes.

TypeScript

The TypeScript version used on the site is tsc 2.4.2. Please use console.log(...) to print any data for debugging purposes.

Visual Basic

The compiler used on the site is Mono 4.6. Please use Console.WriteLine(...) to print any data for debugging purposes.

The following libraries are automatically included:

Imports System
Imports System.IO
Imports System.CodeDom.Compiler
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Diagnostics.CodeAnalysis
Imports System.Globalization
Imports System.Reflection
Imports System.Runtime.Serialization
Imports System.Text
Imports SimpleJson.Reflection
Imports System.Text.RegularExpressions
Imports System.Linq
Did this answer your question?