Giter Club home page Giter Club logo

big-o-challenge's Introduction

challenge

CircleCI Coverage Code Lines Of Code Technical Debit

Coverage Status

Goal

The main use case for our API is to calculate realtime statistic from the last 60 seconds. There will be two APIs, one of them is called every time a transaction is made. It is also the sole input of this rest API. The other one returns the statistic based of the transactions of the last 60 seconds.

Requirements

For the rest api, the biggest and maybe hardest requirement is to make the GET /statistics execute in constant time and space. The best solution would be O(1). It is very recommended to tackle the O(1) requirement as the last thing to do as it is not the only thing which will be rated in the code challenge.

  • The API have to be threadsafe with concurrent requests
  • The API have to function properly, with proper result
  • The project should be buildable, and tests should also complete successfully. e.g. If maven is used, then mvn clean install should complete successfully.
  • The API should be able to deal with time discrepancy, which means, at any point of time, we could receive a transaction which have a timestamp of the past
  • Make sure to send an in memory solution without database, (including no in memory database).
  • Endpoints have to execute in constant time and memory (O(1))

Build and Execute

mvn clean install
mvn spring-boot:run 

or

mvn clean install spring-boot:run

Test

Test source includes unit tests and integration tests for endpoints.

Coverage: %98 Line Coverage: 163/165

APIs

/transactions

curl -H "Content-Type: application/json" -X POST http://localhost:8080/transactions -d '
{
"amount": 3.4,
"timestamp": 1531675920000
}'

/statistics

This is the main endpoint of this task, this endpoint have to execute in constant time and memory (O(1)). It returns the statistic based on the transactions which happened in the last 60 seconds.

curl -H "Content-Type: application/json" -X GET http://localhost:8080/statistics

folder structure

├── mvnw
├── mvnw.cmd
├── pom.xml
├── README.md
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── n26
│   │   │           └── challange
│   │   │               ├── ChallangeAppConstant.java
│   │   │               ├── ChallangeApplication.java
│   │   │               ├── controller
│   │   │               │   └── ChallangeController.java
│   │   │               ├── model
│   │   │               │   ├── Statistics.java
│   │   │               │   └── Transaction.java
│   │   │               ├── service
│   │   │               │   └── TransactionService.java
│   │   │               └── util
│   │   │                   └── StatisticsUtil.java
│   │   └── resources
│   │       └── application.properties
│   └── test
│       └── java
│           └── com
│               └── n26
│                   └── challange
│                       ├── ChallangeAppConstantTest.java
│                       ├── ChallangeApplicationTests.java
│                       ├── controller
│                       │   ├── ChallageControllerIT.java
│                       │   └── ChallageControllerTest.java
│                       ├── service
│                       │   └── TransactionServiceTest.java
│                       └── util
│                           └── StatisticsUtilTest.java

big-o-challenge's People

Contributors

rslvn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.