GithubHelp home page GithubHelp logo

backend-technical-test's Introduction

Candidate Exercise / Backend Engineer for Honei

Introduction

This repository contains solutions to the coding exercises provided for the Backend Engineer position at Honei. The exercises are designed to assess your programming and problem-solving skills.

Getting Started

To get started, follow the instructions below for each exercise:

Exercise 1: Highest Occurrence

  1. Install dependencies: npm install
  2. Navigate to the tests directory: cd tests
  3. Run Jest tests: npx jest

Exercise 2: Maximum Sub Array Sum

  1. Install dependencies: npm install
  2. Navigate to the tests directory: cd tests
  3. Run Jest tests: npx jest

Exercise 3: Average Pair

  1. Install dependencies: npm install
  2. Navigate to the tests directory: cd tests
  3. Run Jest tests: npx jest

Exercise 4: Parallel Processing

  1. Navigate to the exercise-4 directory: cd exercise-4
  2. Install dependencies: npm install
  3. Run the server: node server.js
  4. Open your browser and go to: http://localhost:3000/generate-and-sum?count=number Replace number with the desired count of random generated numbers.
  5. The sum result will be displayed in JSON format.

Contact

If you have any questions or need assistance, feel free to reach out via email at [email protected]

Max. duration: 48 hours

Exercice 1: Highest Occurrence (optional)

Write a function called highestOccurrence. Given an array of string and/or number, this function should return the array item with the highest frequency. The time complexity of the solution should be inferior or equal to O(n).

Signature:

type highestOccurrence = (input: Array<string | number>) => Array<string | number>;

Example:

highestOccurrence([2, 3, 2, 2, 2, 4, 2]);
// [2]

highestOccurrence([2, 3, 2, 3, 2, 3, 4]);
// [2, 3]

highestOccurrence(['a', 'b', 'c', 'a', 'a', 'a', 'a']);
// ['a']

highestOccurrence(['a', 'a', 2, 2, 2, 'a', 4]);
// ['a', 2]

Exercice 2: Maximum Sub Array Sum (optional)

Write a function called maxSubarraySum which accepts an array of integers and a number called n. The function should calculate the maximum sum of n consecutive elements in the array. The time complexity of the solution should be inferior or equal to O(n).

Signature:

type maxSubarraySum = (input: Array<number>, num: number) => number;

Example:

maxSubarraySum([1,2,5,2,8,1,5], 4)
// 17

maxSubarraySum([1,2,5,2,8,1,5], 2)
// 10

maxSubarraySum([4,2,1,6], 1)
// 6

maxSubarraySum([4,2,1,6,2], 4)
// 13

maxSubarraySum([], 4)
// null

Exercice 3: Average Pair (optional)

Write a function called averagePair. Given a sorted array of integers and a target average, determine if there is a pair of values in the array where the average of the pair equals the target average. There may be more than one pair that matches the average target. The time complexity of the solution should be inferior or equal to O(n).

Signature:

type averagePair = (input: Array<number>, target: number) => boolean;

Example:

averagePair([1,2,3], 2.5)
// true

averagePair([1,3,3,5,6,7,10,12,19], 8)
// true

averagePair([-1,0,3,4,5,6], 4.1)
// false

averagePair([], 4)
// false

Exercice 4: Parallel Processing (mandatory)

Objective:

Create a service in Node.js that generates a set of random numbers and then sums up these numbers efficiently using parallel processing. Through this task, you'll learn about leveraging multiple "threads" to process data more swiftly.

Steps:

  1. Random Number Generation: We're providing you with this function that generates a set of random numbers:
function generateRandomArray(length: number): Array<number> {
    return Array.from({ length }, () => Math.floor(Math.random() * 1000));
} 
  1. Why Use Parallel Processing?: Imagine you have to sum up 100,000 numbers. If you sum them up one at a time, it would take a while. But if you split those numbers into smaller groups and sum up several groups at the same time (in parallel), you could get the total much faster. This is the idea behind parallel processing.

  2. Create the Service:

  • Build a service with a POST endpoint named /generate-and-sum.
  • This endpoint should accept a number called count that decides how many random numbers you want to generate.
  • Generate the numbers using the generateRandomArray function.
  • Divide this large set of numbers into smaller batches. For instance, if you have 100,000 numbers, you might have 10 batches of 10,000 numbers each.
  • Use "worker threads" in Node.js to sum each batch in parallel.
  • As you sum up, display progress messages like "Summing up batch 1...", so we can see that your program is making progress.
  • Once all batches are summed, add up the totals from each batch to get the final sum and return it.
  1. Tips:
  • If you've never heard of "worker threads," don't worry. Look for documentation or tutorials on how to use them in Node.js. They're a tool to enable parallel processing.
  • Given the nature of the operation and the efficiency gains expected with parallel processing, your solution should be able to process 10k numbers in under 0.5 second.
  • Think about how you can efficiently split and sum the numbers.

What We're Looking For:

  • Functionality: Your program should generate numbers and sum them up.
  • Efficiency: Can you make the sum faster using parallel processing?
  • Communication: We like to see progress messages to know how the program is doing.

Submission:

  • Submit all the code you wrote.
  • Include clear instructions on how to run your program.

backend-technical-test's People

Contributors

brelats avatar marianroibu avatar sergiborja 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.