Introduction

Hello there! Are you ready to tackle another engaging problem today? We have a practical task that will enhance your problem-solving skills. This task involves working with arrays, leveraging Ruby hashes, sorting, and using techniques such as the two-pointer method that we've covered in previous Ruby lessons. Let's dive in!

Task Statement

Our task is as follows. Suppose you have two equally long arrays, a and b, with a length varying from 1 to 1000, with each element being a unique positive integer ranging from 1 up to 1,000,000. Your challenge is to craft a Ruby method that identifies the closest number in array b to 2 * b[i] for each i. Upon finding this number, say for a specific i, it is b[j], we need to construct a new array using a[j] values in the order of increasing i.

Consider this example:

After executing your method, the resulting array should be:

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal