Giter VIP home page Giter VIP logo

periscopedataproblem's Introduction

Periscope Data Problem

Coding challenge for Periscope Data

Language: Python 2.7

Running the program

This is a regular Python program which can be run either using the command line

python roomba.py 

or

by using the Python shell.

Prerequisite:
The input.txt file should be present in the same folder as the program.

Tests
The code has it's own test cases which can be run is the same way as the code.

python roomba_test.py

The tests modify input.txt to check for different cases.

Approach

The interesting thing about this problem was to decide on a data structure to represent the dirty patches. The 2 options were to have a 2*2 array with 1 for dirty patch and a 0 for a clean patch. The advantage of this approach is that the access time for checking if a block is dirty or not will be O(1). The disadvantage of this approach is that space complexity is O(n2).

Another approach, the one I took, was to optimize the data structure for a sparse matrix. If the number of dirt patches is much less than the number of clean patches, this approach has a better performance. I represented the dirt patches on each row as a list which is stored as the value in a dictionay with the key as the row number. This saves a lot of space while not having considerable impact on access time.

periscopedataproblem's People

Contributors

juhidesai avatar

Watchers

James Cloos avatar  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.