*DALIY CHALLENGE* : Given a positive int n. Generate a random int array of size n and count the inverses! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

*DALIY CHALLENGE* : Given a positive int n. Generate a random int array of size n and count the inverses!

INFO: an inverse is an integer pair (left,right) where the left value is larger than the right value. TASK: 1) generate random int array 2) calculate inverses EXAMPLE: (n = 6) a random array could be: [1,3,4,2,0,9] - 1,0 is an inverse - 3,2 is an inverse - 3,0 is an inverse - 4,2 is an inverse - 4,0 is an inverse - 2,0 is an inverse ---> this array has 6 inverses! try to do this as EFFICIENT as possible ! HINT: divide & conquer (it's 2 faster as normal) https://code.sololearn.com/cL0bV3ZFuN3j/?ref=app

18th Aug 2017, 10:17 AM
Julian Fechner
Julian Fechner - avatar
37 Answers
+ 3
This is my try, is there things I could improve ? https://code.sololearn.com/c9j94Ken381p/?ref=app
18th Aug 2017, 12:29 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
18th Aug 2017, 11:28 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
18th Aug 2017, 10:39 AM
h8c
h8c - avatar
+ 4
here mine: https://code.sololearn.com/WX4DVo4aIjnq/ example's one has 6 inverses instead :)
18th Aug 2017, 4:15 PM
ysraelcon
ysraelcon - avatar
+ 3
ALL YOUR ALGORITHMS ARE CORRECT BUT RUNNING IN O(n^2) RUNTIME ... TRY TO SPEED THEM UP ;)
18th Aug 2017, 11:19 AM
Julian Fechner
Julian Fechner - avatar
+ 3
I did some optimizations, there are probably some more. But good enough for me ^^ Without output it can handle up to around 500.000 on sololearn before reaching the memory limit. * Edit: with some more optimizations sololearn should be able to handle up to around 9.000.000 elements before reaching the time limit. * On my pc it can calculate an array of 100.000.000 elements within 5 seconds. https://code.sololearn.com/ccVZvJB0vB25/?ref=app Btw, in your example I think you're missing (2,0)
18th Aug 2017, 12:34 PM
Dennis
Dennis - avatar
+ 3
this is my Solution. p.s. i did it hours ago, but put it in wrong challenge discussion https://code.sololearn.com/c7PjGjS3QH34/?ref=app
18th Aug 2017, 2:02 PM
wolfsan
wolfsan - avatar
19th Aug 2017, 9:31 PM
Nick
Nick - avatar
+ 2
Here you go. Checks for valid numerical input. https://code.sololearn.com/cvzXba4GLWjO/?ref=app
18th Aug 2017, 11:25 AM
Vari93
Vari93 - avatar
+ 2
here my advertisement for: https://www.sololearn.com/Discuss/635638/?ref=app sponsored by @Julian Fechner
18th Aug 2017, 5:08 PM
ysraelcon
ysraelcon - avatar
+ 2
my try (maybe, the simplest of all :p) https://code.sololearn.com/c16Rop2pDtO0/?ref=app
20th Aug 2017, 6:28 AM
‎ ‏‏‎Anonymous Guy
+ 2
https://code.sololearn.com/cK3b113TAmoj/#py
20th Aug 2017, 3:31 PM
Eka Aditya Pramudita
Eka Aditya Pramudita - avatar
+ 1
here is mine give 2 inputs... 1) how many random elements in the array. 2)max limit for the random integer. input eg: 6 189 ( SEPERATED BY ENTER) **it means 6 random integers between 0 to 189** check it out.. https://code.sololearn.com/cE5DY9cX0CSh/?ref=app
18th Aug 2017, 10:44 AM
sayan chandra
sayan chandra - avatar
18th Aug 2017, 10:46 AM
Jesse
Jesse - avatar
+ 1
my limit for random integer is 9 not sure if this is correct. https://code.sololearn.com/cjYmpiqPi6u3/?ref=app
18th Aug 2017, 10:56 AM
Matthias W
18th Aug 2017, 1:24 PM
hmysjiang🍀
hmysjiang🍀 - avatar
18th Aug 2017, 8:06 PM
Devendra KC
+ 1
if number occurs twice or more in a array then what will be the output?
18th Aug 2017, 8:09 PM
Devendra KC
19th Aug 2017, 12:49 PM
VcC
VcC - avatar
+ 1
MY NEW *DAILY CHALLENGE*: GIVE IT A TRY!!! https://www.sololearn.com/discuss/647083/?ref=app
22nd Aug 2017, 10:23 AM
Julian Fechner
Julian Fechner - avatar