Git Product home page Git Product logo

supermarket-queue's Introduction

Supermarket Queue

You are in a supermarket with only self-checkout counters. Write a function to calculate the total time needed for all the customers to check out.

The function signature is as such:

computeQueueTime(customers, n)
  • customers: An array of positive integers. Each integer represents a customer, and its value is how long they require to check out.
  • n: The number of self-checkout counters in the supermarket.

Here are some examples:

computeQueueTime([5,3,4], 1)
  • should return 12
  • because when n=1, the total time is just the sum of the times
computeQueueTime([10,2,3,3], 2)
  • should return 10
  • because here n=2 and the 2nd, 3rd, and 4th people in the
  • queue finish before the 1st person has finished.
computeQueueTime([2,3,10], 2)
  • should return 12

You can assume the following:

  • There is only a single queue to use the counters.
  • The order of the queue will never change.
  • The person at the front of the queue proceeds to a counter as soon as it becomes free with no lag time.

Further - traditional staffed counters

Management is thinking to re-introduce some traditional staffed counters to facilitate faster checking out of customers who are less conversant with self-checkout.

These trained staff will be able to serve a customer twice as fast as a self-checkout counter.

Modify your function to incorporate a second type of counter. You should be able to use this function to advice management exactly how much faster the checkouts will be. The new function signature should be:

computeQueueTime(customers, n, m)
  • m (new): The number of traditional staffed counters that perform checkouts twice as fast as self-checkout counters.

Note:

  • There is still only 1 queue to access all counters, regardless of the type of counter.
  • Assume all customers are still the same and are not split by how conversant they are with self-checkout. The first person in the queue continues to use whichever counter is available.

Resources

  • This was adapted from a kata on Codewars.
  • The supermarket queue is analogous to the thread pool in computer science.
  • Concept of concurrency in computer science.

supermarket-queue's People

Contributors

nickangtc avatar awongh avatar

Watchers

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