Introduction

Welcome to our exciting TypeScript lesson! Today, you'll tackle a fascinating programming challenge that will enhance your problem-solving skills using TypeScript. This exercise involves working with arrays while employing advanced techniques like sorting and the two-pointer method. Let's dive right in!

Task Statement

Your challenge is to create a TypeScript function to work on two equally long arrays, A and B. The arrays have a length between 1 and 1000, and each element is a unique positive integer ranging from 1 to 1,000,000. Your task involves the following steps:

  1. For each element B[i] in the array B, double its value to get 2 * B[i].
  2. Identify the closest number to 2 * B[i] in array B, naming it B[j].
  3. For each index i, retrieve the value at index j in array A and assign it to the new array.
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