Given an array of integers, find the largest possible product obtained by multiplying two adjacent numbers in an array.
Examples
adjacentProduct([1, 2, 3])
==> returns 6
adjacentProduct([3, 4, 5])
==> returns 20
Tests
adjacentProduct([3, 7, 9])
adjacentProduct([-3, -4, 15])
adjacentProduct([-4, -1, -10])
Good luck!
This challenge comes from MrZizoScream on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (12)
Rust
on stable you have the options of instead doing:
or
which produce identical assembly to each other in release mode (meaning the compiler proves different sized slices unreachable without your help)
Generic:
Haha square meters go brr
Golang solution
Python 3 oneliner with testcases and TIO link:
Try it online!
Perl
C
JS
Here is the simple solution in PHP:
A KISS version in typescript...
What counts as adjacent? Neighboring?
Like the tests, I'm gonna assume that this only takes 3 inputs.
But, Java: