Git Product home page Git Product logo

flipcoin's Introduction

flipcoin

This is yet another coding challenge in the sprit of codility.

The Flip Coin problem does not use Random and algorithmically does not really have anything to do with coins.

This is a object counting problem more easily solved using Java as opposed to ANSI C or C++.

There is no build as the entire project was developed in Intellij and run @ the Intellij terminal.

Java commandline:

$ java -cp . name.davidwbrown.FlipCoin

There are N coins kept on the table, numbered from 0 to N - 1. Initially, each coin is kept tails up. You have to perform two types of operations :

  1. Flip all coins numbered between A and B inclusive. This is represented by the command "0 A B"
  2. Answer how many coins numbered between A and B inclusive are heads up. This is represented by the command "1 A B". Input : The first line contains two integers, N and Q. Each of the next Q lines are either of the form "0 A B" or "1 A B" as mentioned above. Output : Output 1 line for each of the queries of the form "1 A B" containing the required answer for the corresponding query.

All input is space delimited.

Sample Input : 4 7 1 0 3 0 1 2 1 0 1 1 0 0 0 0 3 1 0 3 1 3 3

Sample Output : 0 1 0 2 1

Constraints : N > 0 Q > 0 0 <= A <= B <= N - 1

flipcoin's People

Contributors

datamaskin 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.