Giter Site home page Giter Site logo

arrayhopper's Introduction

ArrayHopper

A java program to solve Array Hopper coding challenge from White Pages

Problem Description

You are given an array of integers with values greater than or equal to 0, for example:

[5, 6, 0, 4, 2, 4, 1, 0, 0, 4]

You will develop and implement an algorithm to traverse the array in the shortest number of “hops” starting at index 0, where traversal is defined as follows:

  • Start at the first (0th) index of the array, look at the array value there, and you can hop forward to any array index that is no farther than that value away. So in this example, you start at index 0 containing the value 5 and can now consider hopping to any of indices 1 through 5 inclusive.
  • If you choose to hop to index 3, it contains the value 4 and you can next hop up to 4 more spots from your current index (3)—so you now consider indices 4 through 7 as next steps in your sequence.
  • Once you can legally hop beyond the last array element, you have successfully traversed the array.

Your job is to compute the minimum-length sequence of hops that successfully traverses the array starting from index 0, or determine that there is no such sequence.

Your algorithm must identify a minimum-hops solution, but can choose arbitrarily among solutions with the same number of hops.

Your program will implement the algorithm and write a solution to the standard output stream on a single line identifying the array indices that comprise a solution path, with the indices separated by commas.

For this example, the following would be valid output:

0, 5, 9, out

(Note that your output is a sequence of array indices, not a sequence of hop lengths.)

  • Your program may be written in the language of your choice.
  • It must accept a single command-line argument, which is the path to a file containing the input data (the array of integers). Your program must not read that path from STDIN or the console.
  • The input file will contain the array for a single problem.
    • One integer per line, with no brackets or commas.
    • The input array will likely be large in our testing, so performance is important.
  • If there is no solution, the program should write the string “failure” to the standard output stream, followed by a newline character.

File Structure

Filename Description
ArrayHopperApp.java The main class for ArrayHopper application which locations of minimum hops to jump through an array
IOUtils.java Class for some basic IO involved with ArrayHopper
ArrayHopperAppTest.java Tests to run through various input sets

Note:

This solution assumes that the cost in hopping from one array index to another is constant through all array indices and will not dependent upon the difference between indices.

##Dependencies This project depends on the following:

  1. Maven
  2. Junit

##How to use On command line

java -cp array-hopper-1.0-BETA.jar com.rohitsinha.codingchallenge.ArrayHopperApp input_filepath

Testing

The program has been tested on following operating systems:

  1. Mac OSX 10.9.2

##Version 1.0 beta

##Contact Information Please report any bugs or issues to: [email protected]

##License MIT License

arrayhopper's People

Contributors

rohitsinha54 avatar senghuot avatar

Watchers

 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.