How to solve Code Wars 3.0 COW3G?

Can anyone prove their solution ? I am not able to prove why the used approaches work?

I think it had really weak test cases , Even taking lcm of adjacent elements in sorted array passed :frowning:

1 Like

shit, why didn’t I tried that :frowning:

Don’t regret “not trying a wrong solution” to get AC :stuck_out_tongue_winking_eye:


I just wrote something (without logic) and it passed :stuck_out_tongue:
i found the largest number divisible by i and largest number divisible by i+1 (present in array) and took their lcm.
for i in range 1 to 1e5
It is completely WA for even small test cases :frowning:

1 Like

I see some people did lcm(a_{i}, a_{i+1}), but that was not correct. You have to amortize the solution with some break statements to make it faster or check for a certain amount of left-right may work. For some strong test case, checking for a certain amount of left-right may fail (but not sure). For the below test case some solution will fail.
2 5 8 12


I just saw one of my college mate passed it in O(n^2) these solutions should be marked wrong for providing justice to others

It’s okay for unrated contest… (it’s just for practice i think)

1 Like

that’s not going to happen bro

1 Like

Please have a look at this thread also…is my logic correct or not?

yeah I was just kidding :slight_smile:

I found this problem hardest! I mean compare it to the difficulty level of the other 6 problems. Even the last one was way easier.


I sort the array in decreasing order and check when i get the gcd of two elements 1 the print the product and break
here is the link of my solution

1 Like

It seems like shady to me but comparing all pairs of distinct largest 1000 or so elements apparently gives correct results. I cannot prove it, but It seems to me that it should be correct, unless someone helps me see other way

can you prove it bro?

How can this even work on arrays where all elements have a common multiple, say [2, 4, 6] ??

bro I know its a wrong solution but because of weak test cases it passes

1 Like

it wont even work on input 2 3 4 8

@benmirt Sir,can you kindly explain your approach for the problem
CodeChef: Practical coding for everyone
PLease Sir,it would be of great help to others like me who could not solve.
Thanks in advance.

No I don’t mean it but even some 6-7 star guys have written the same code that’s why I wanna ask brother