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.
To get started, follow the instructions below for each exercise:
- Install dependencies:
npm install
- Navigate to the
tests
directory:cd tests
- Run Jest tests:
npx jest
- Install dependencies:
npm install
- Navigate to the
tests
directory:cd tests
- Run Jest tests:
npx jest
- Install dependencies:
npm install
- Navigate to the
tests
directory:cd tests
- Run Jest tests:
npx jest
- Navigate to the
exercise-4
directory:cd exercise-4
- Install dependencies:
npm install
- Run the server:
node server.js
- Open your browser and go to: http://localhost:3000/generate-and-sum?count=number
Replace
number
with the desired count of random generated numbers. - The sum result will be displayed in JSON format.
If you have any questions or need assistance, feel free to reach out via email at [email protected]
Max. duration: 48 hours
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]
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
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
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.
- 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));
}
-
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.
-
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.
- 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.
- 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.
- Submit all the code you wrote.
- Include clear instructions on how to run your program.
backend-technical-test's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.