Daily programming challenge

Let's see how many brainlets are on Sup Forums tonight

Task:
>Rotate outer matrix by one element clockwise/counter-clockwise

Rules:
>time complexity: O(n) or better
>constant space complexity (= creating another matrix is not allowed)

Example:
>original
2 1 8 7 4
3 9 0 2 6
8 1 4 3 9
0 1 3 8 1
7 5 5 6 2
>rotated clockwise
3 2 1 8 7
8 9 0 2 4
0 1 4 3 6
7 1 3 8 9
5 5 6 2 1

>OP solution (try it yourself first, Pajeet):
pastebin.com/YhDAyj7W

Usually Sup Forums doesn't do someone's homework.

I see nothing hard here.

I have already done it and provided link to my solution. Learn to read, retard.

Sorry bro I'm not going to do your comp sci 2 homework

>"Let's see how many brainlets are on Sup Forums"
>uses python

Hello summer

your solution is in linear time, but is not better than O(n) time. Its something like O(10n) time, but lets just pretend you meant linear time so that your solution fits the parameters.

Other than me being a dick just now, I doubt this can be done better than linear time and the most straightforward solution is something along the lines of the swap solution you provided.

If you remove the constant space complexity requirement, this could be made into real O(n) time by just reading into a new matrix.

It can be done in leinear time.

>O(10n)
This notation is literally never used. It doesn't matter if it is n, 2n, or 44n + 365, it is alway O(n)

but can it be done better?

the solution already was a linear time solution it just wasnt O(n)

then call it linear time

No. It can not be improved. You need tomove every elements (except centre if there is one).

O(n) and O(100n) are exactly the same thing. I hope you understand why.

im just pedant

>If I post a bad solution Sup Forums will correct me and do my homework for me!
Really?

>im just pedant
No. You justfail to understand why big O notation was introduced,

And why exactly is my solution bad, faggot? And who the fuck have uni in middle of summer

>1 = 100
>your brain on CS

I'm laughing so hard right now, this is the perfect example of Sup Forums in 2017. Not surprised that most threads are about consumerism, when you are failing CS 101.

Do your own homework, cunt. Or ask /wsr/. I'm not gonna sit here and say why it's bad so you can fix it. Go learn and put forth effort.

this is really poor attempt at trolling, sorry.

>nobody does your homework for you
>f-f-f fucking Sup Forums newfags! I b-b-bet youre the ones failing cs 101!

Not as bad as your attempt to get people to do your homework for you.

I was pointing out they fucking doesn't understand what a Big O notation is. Back to "watz da best gpu for gayming" threads

I dunno, he has done the task, why would he ask anyone to do the done job?

>Daily programming challenge
What was yesterday's challenge?

O(n) literally means linear

are you kidding me? even the most obvious solution is O(n).

>someone doesn't know what O(n) means
a function f is O(g(n)) if there exists a c > 0 such that f(n) < cg(n) for all n.
as an application, any function that is O(100n) is O(n).

depending on how your matrix is stored, the solution can be done in O(1). but optimizing your data structure for such problems will leave it relatively useless for most other things.

Any pb can be solved in O(1) with a gopd coding.

okay, perform element-wise addition of two integer arrays (each of length n) in O(1).

I'd just use a reverse iterating vector in C++ easy peasy