Giter Site home page Giter Site logo

mbicycle-algorithmic-task's Introduction

Welcome, candidate! ๐Ÿ‘‹

In that repository you can find our screening pre-interview task

Yes, I know, it's boring to solve tasks like that. But it's not my personal wish or will. Customers provide their own tasks in hackerrank and most of interviews are failed cuz of that. Hope you will understand.

Task: Sum in Range

Given an array arr of integers, and two l and r, find the number of pairs (i, j)(1 <= i < j <= n) such that value arr[i][] + arr[j][] lies between l and r, both inclusive. Array indices starts at 1.

Example

Suppose n = 4, arr = [2, 3, 4, 5], l = 5, r = 7

There are 4 pairs with a sum between 5 and 7:

  • arr[1] + arr[2] = 2 + 3 = 5
  • arr[1] + arr[3] = 2 + 4 = 6
  • arr[1] + arr[4] = 2 + 5 = 7
  • arr[2] + arr[3] = 3 + 4 = 7

!NB - avoid duplicates. (2 + 4 is same pair with 4 + 2)

!!NB - avoid time complexity of O(n^2)

Return 4.

Function description

Complete the function getNumPairs.

The function getNumPairs has the following signature:

  • int arr(n): an array of integers
  • int l: minimum acceptable sum
  • int r: maximum acceptable sum

Return

int: the number of pairs that satisfy the condition.

Constraints

  • 1 <= n <= 10^5
  • 1 <= arr[i] <= 10^9
  • 0 <= l <= r <= 10^9

Feel free to open index.js and write your own solution.

After finishing the solution create new pull request to current repo & tag me as reviewer (@kobuqa).

Wish you good luck! ๐Ÿ€

Test your solution

  1. npm i

  2. npm test

mbicycle-algorithmic-task's People

Contributors

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