Codility: MinPerimeterRectangle Solution

Lesson 10 Prime and Composite Numbers
1function solution(N) {
2 function perimeter(a, b) {
3 return 2 * (a + b)
4 }
5
6 let min = Infinity
7 let i = 1
8 while (i * i < N) {
9 if (N % i === 0) {
10 min = Math.min(min, perimeter(i, N / i))
11 }
12 i++
13 }
14 if (i * i === N) {
15 min = Math.min(min, 4 * i)
16 }
17
18 return min
19}

Comments

Loading comments...

Tags

codility

Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.

Next Post

Codility: Flags

Jan 26, 2021

Lesson 10 Prime and Composite Numbers

Previous Post

Codility: Peaks

Jan 26, 2021

Lesson 10 Prime and Composite Numbers

HoningJS

Search Posts