Code Monkey home page Code Monkey logo

hackerranksolutions's Introduction

HackerRankSolutions

Sample solutions to HackerRank problems (above medium difficulty level)

Problems

Maximum Difference in An Array

Given an array of integers a[], there should be a pair (i, j) that maximize a[i] - a[j] where i > j.
Return value of maximized a[i] - a[j] (return -1 if the value is negative).

For example, given a = [2, 3, 10, 1], the result should be 10 - 2 = 8.

Distinct Pairs

Given an array of integers a[], and target value k.
In this array, find count of distinct pairs that sum to target value.

For example, given a = [1, 1, 2, 3] and k = 4.
There is only one distinct pair (1, 3) fulfilling the requirement.
The result should be 1.

Sprint Training

Imagine there are n points along a straight trail, while a runner run sprints of intervals between those point.
The training plan is an array a[], which implies the runner should run from point a[i] to point a[i+1].

For example, given n = 10, a = [2, 4, 1, 2].
The runner should run from point 2 to point 4,
then turn back from point 4 to point 1,
and then from point 1 to point 2.

Find the point that visited the most by runner after he finished training, i.e. in above example, point 2 is the most visited.
If more than one point are visited the most, find the point with minimum index.

Number of Paths in A Matrix

Imagine there is an m-by-n matrix (m rows, n columns), with element value to be either 0 or 1.
There should be such a path, that start from the top left corner and end in the bottom right corner, with each step either move right or move down, and only pass by element with value 1.
Find how many paths are there.

For example, given matrix
1 1 0 1
1 1 1 1,
there are 2 possible paths as elaborated by *
* * 0 1
1 * * *
and
* 1 0 1
* * * *

In above example, result should be 2.

hackerranksolutions's People

Contributors

xialinbo avatar

Stargazers

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