Return to List## Solve: Array Is Doubled

### Related Lessons

Created By: Geoffrey Challen

/ Version: `2021.8.0`

Write a method called `arrayIsDoubled`

that takes two non-empty `int`

arrays and returns `true`

if they are the same
length and if every element of the second array is equal to the element of the first array in the same position,
doubled.

So given `{1, 2, 4}`

and `{2, 4, 8}`

, you would return `true`

,
but given `{1, 2, 4}`

and `{2, 4}`

or `{1, 2, 4}`

and `{2, 4, 8, 10}`

you would return `false`

.

We suggest you approach this problem by looking for a counterexample. First, examine the lengths of the two arrays. If they are different, you can return immediately! Otherwise, loop through each element of the array looking for one that is incorrect. As soon as you find one, you can return. And, once the loop concludes, you can also draw a conclusion.

Stuck? You may find these lessons helpful: