# Codility – Lesson 2 – Arrays – Task 2 – CyclicRotation

An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).

The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.

Write a function:

```class Solution { public int[] solution(int[] A, int K); }
```

that, given an array A consisting of N integers and an integer K, returns the array A rotated K times.

For example, given A = [3, 8, 9, 7, 6] K = 3

the function should return [9, 7, 6, 3, 8]. Three rotations were made: [3, 8, 9, 7, 6] -> [6, 3, 8, 9, 7] [6, 3, 8, 9, 7] -> [7, 6, 3, 8, 9] [7, 6, 3, 8, 9] -> [9, 7, 6, 3, 8]

For another example, given A = [0, 0, 0] K = 1

the function should return [0, 0, 0]

Given A = [1, 2, 3, 4] K = 4

the function should return [1, 2, 3, 4]

Assume that:

• N and K are integers within the range [0..100];
• each element of array A is an integer within the range [−1,000..1,000].

In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

## Solution in C#:

```using System;
using System.Linq;
using System.Collections.Generic;

class Solution {
public int[] solution(int[] A, int K) {

var array = A;
var count = K;

if (array.Length <= 0) return array;
if (count <= 0) return array;

count %= array.Length;
int[] result = new int[array.Length];
Array.Copy(array, array.Length - count, result, 0, count);
Array.Copy(array, 0, result, count, array.Length - count);
return result;
}
}
```
Standard

# Codility – Lesson 2 – Arrays – Task 1 – OddOccurrencesInArray

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.

For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9

• the elements at indexes 0 and 2 have value 9,
• the elements at indexes 1 and 3 have value 3,
• the elements at indexes 4 and 6 have value 9,
• the element at index 5 has value 7 and is unpaired.

Write a function:

```class Solution { public int solution(int[] A); }
```

that, given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.

For example, given array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9

the function should return 7, as explained in the example above.

Write an efficient algorithm for the following assumptions:

• N is an odd integer within the range [1..1,000,000];
• each element of array A is an integer within the range [1..1,000,000,000];
• all but one of the values in A occur an even number of times.

## Solution in C#:

```using System;
using System.Linq;
using System.Collections.Generic;

class Solution {
public int solution(int[] A) {

List<int&gt; lst = A.OfType<int&gt;().ToList();

lst = lst
.GroupBy(n =&gt; n)
.Where(g =&gt; g.Count() == 1)
.Select(g =&gt; g.Key).ToList();

var result = lst.Distinct().FirstOrDefault();

return result;
}
}
```
Standard

# Git Cheatsheet

# traz todos os commit anteriores ao pull
` git fetch`

#exibe todos os commit anteriores
` git log`

#define a branch atual de trabalho
` git branch`

#define o upstream da branch definida acima
` git branch --set-upstream-to=origin/preproducao preproducao`

#permite unrelated histories
` git pull --allow-unrelated-histories`

#mantém minha modificações atuais e reseta o repositório para o commit citado
` git reset HEAD^2`

#reseta meu repositório para o primeiro commit depois do clone, apagando o histórico e minhas modificações atuais
` git reset --hard origin/preproducao`

#apaga minhas modificações atuais e volta para o ultimo commit
` git reset --hard HEAD`

#apaga minhas modificações atuais e volta para o anti-penúltimo commit apagando o histórico posterior
` git reset --hard HEAD^1`

#reseta o repositório para um commit específico, apagando todo o histórico posterior
` git reset --hard 4734d088`

#retorno a repositório para o revision citado, mantendo o histórico — cria um novo commit baseado no revision citado
` git revert HEAD^2`

#copia um commit específico
` git cherry-pick 4734d088`

#força o envio de um commit que modifica o histórico do repositório
` git push --force`

#utilizar o gerenciador de credenciais do windows
`git config --global credential.helper manager`

#listar as configuração de sistema do git
`git config --system --list`

` git rm -r --cached .`

Standard

# Carrousel

She can’t hide, no matter how hard she tries
Her secret disguise behind the lies
And at night, she cries away her pride
With eyes shut tight, staring at her inside

All her friends know why she can’t sleep at night
All her family asking if she’s alright
All she wants to do is get rid of this hell
Well, all she’s gotta do is stop kidding herself

She can only fool herself for so long

When it comes to how to live his life, he can’t be told
Says he’s got it all under control
Thinks he knows it’s not a problem he’s stuck with
But in reality, it’d be a problem to just quit

An addict and he can’t hold the reigns
The pain is worse ’cause his friends have it the same
Tries to slow down the problem he’s got
But can’t get off the carousel until he makes it stop

He can only fool himself for so long

Standard

# The Unlisence

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Standard

# Limping with the bizkit

I seen the fight club, about 28 times
I don’t even smoke, but I love the way it smells

It’s so easy to tell a lie
and it’s so easy to run and hide
but it’s not easy to be alive

I used to be alive
Now I feel pathetic
And now I get it
What’s done is done
You just leave it alone
And don’t regret it

Life is a lesson
You learn it when you through

Standard