+ 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
38 Respostas
+ 3
This is my try, is there things I could improve ?
https://code.sololearn.com/c9j94Ken381p/?ref=app
+ 4
is this correct?
https://code.sololearn.com/c2674XRvnZcV/?ref=app
+ 4
here mine: https://code.sololearn.com/WX4DVo4aIjnq/
example's one has 6 inverses instead :)
+ 3
ALL YOUR ALGORITHMS ARE CORRECT BUT RUNNING IN O(n^2) RUNTIME ... TRY TO SPEED THEM UP ;)
+ 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)
+ 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
+ 3
My solution (C++)
:P
https://code.sololearn.com/c634WbQw0h2p/?ref=app
+ 2
Here you go. Checks for valid numerical input.
https://code.sololearn.com/cvzXba4GLWjO/?ref=app
+ 2
here my advertisement for: https://www.sololearn.com/Discuss/635638/?ref=app
sponsored by @Julian Fechner
+ 2
my try (maybe, the simplest of all :p)
https://code.sololearn.com/c16Rop2pDtO0/?ref=app
+ 2
https://code.sololearn.com/cK3b113TAmoj/#py
+ 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
+ 1
my limit for random integer is 9 not sure if this is correct.
https://code.sololearn.com/cjYmpiqPi6u3/?ref=app
+ 1
Here is my try
https://code.sololearn.com/cnKzT5iZs16m/?ref=app
+ 1
is it correct?
https://code.sololearn.com/cfqfMTfVxLED/?ref=app
+ 1
if number occurs twice or more in a array then what will be the output?
+ 1
Efficient coding challenge https://www.sololearn.com/discuss/637973/?ref=app
+ 1
MY NEW *DAILY CHALLENGE*:
GIVE IT A TRY!!!
https://www.sololearn.com/discuss/647083/?ref=app