0

Multiples of array elements

Write a function that returns the first 'n' multiples of each number in an array of string. Do not include the number itself in the multiples. ``` getMultiples(array,n) ``` Where n is the number of multiples we need. Ex: ``` getMultiples ([1,7,2],3) ``` Result: ``` { 1:[2,3,4], 7:[14,21,28], 2:[4,6,8] } Solve in any language of your choice ``` https://code.sololearn.com/cS05Dk2JESsi/?ref=app

22nd Oct 2021, 11:30 AM
J.cartoonist
J.cartoonist - avatar
7 Answers
+ 1
So it looks like we have to return something. So I would say a list of lists can do this. Create a list for Integers and put in all multiples of one number of your array. Create a list for lists in put in each of this sub-lists. Then return this outer list: It can be done, for example, like this: https://code.sololearn.com/c3F1XO3rRjIj/?ref=app
22nd Oct 2021, 12:13 PM
Coding Cat
Coding Cat - avatar
+ 1
Oh ok...thanks
22nd Oct 2021, 2:05 PM
J.cartoonist
J.cartoonist - avatar
+ 1
Is it ok if I ask for guides from you some time later??...kotlin per se
22nd Oct 2021, 2:06 PM
J.cartoonist
J.cartoonist - avatar
+ 1
fun multiples(array:ArrayList<Int>, N:Int for(i in array){ var list= arrayListOf<Int>() //move this line here
22nd Oct 2021, 2:09 PM
zemiak
0
I'd like my answers to be in a list like that of the "results" above separately put together for each element..... I tried putting it in the list but it just puts all the elements in the array like a new array..pls help
22nd Oct 2021, 11:32 AM
J.cartoonist
J.cartoonist - avatar
0
And please don't tag Java, if you want to do something with Kotlin 😉
22nd Oct 2021, 12:16 PM
Coding Cat
Coding Cat - avatar
0
Can u share solution in Java as well?
23rd Jun 2023, 5:41 PM
Abhinav Kishore M
Abhinav Kishore M - avatar