Giter Club home page Giter Club logo

coding_assignment's Introduction

Coding Assignment

NB: You can also find the HD quality of the video using the link https://drive.google.com/file/d/1Kub_fA7cBhGra4bGavIIqCpGKInIDmmb/view?usp=sharing

Problem 1:

Problem Statement:
A factory has a list of jobs to perform. Each job has a start time, end time, and profit value. The manager has asked his employee John to pick jobs of his choice. John wants to select jobs for him in such a way that would maximize his earnings. Given a list of jobs, how many jobs and total earnings are left for other employees once John picks jobs of his choice. Note: John can perform only one job at a time.

Solution

The problem can be solved using two methods.

  • Using a Greedy Algorithm
  • Dynamic programming with interval scheduling maximization (weighted).

A greedy approach would always select the biggest jobs first but this might not be the optimal solution in some cases because there could be smaller jobs that would give John more earnings. So a Dynamic programming approach was chosen.

Running solution to Problem 1

Clone the Repo

Enable the lines below in index.js file

const { calculateJobsAndEarningsLeft } = require("./jobs_left");

calculateJobsAndEarningsLeft();

Next run the command npm run start

Enter the required values in the prompt

Problem 2:

Problem Statement:
Let's say the HR team of a company has goodies set of size N each with a different price tag for each goodie. Now the HR team has to distribute the goodies among the M employees in the company such that one employee receives one goodie. Find out the goodies the HR team can distribute so that the difference between the low price goodie and the high price goodie selected is minimum.

Solution

The problem is solved by

  • sorting the input
  • using a sliding window.

Running solution to Problem 1

Clone the Repo

Enable the lines below in index.js file

const { minimizePriceDifference } = require("./minimize_price_difference");

 const inputFilePath = "sample-inputs-outputs/sample_input.txt";
 const outputFilePath = "sample-inputs-outputs/sample_output.txt";

 // Call the async main function and handle the promise
 (async () => {
   try {
     await minimizePriceDifference(inputFilePath, outputFilePath);
   } catch (err) {
     console.error("Error:", err.message);
   }
 })();

Next run the command npm run start

An output file is generated in the sample-inputs-outputs folder

End

coding_assignment's People

Contributors

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