---
id: 69e2383af7832c8032603b92
title: "Challenge 276: Offending Element"
challengeType: 29
dashedName: challenge-276
---

# --description--

Given an array of integers that is sorted in ascending order except for one out-of-place element, return the index of that element.

- If more than one element could be considered out of place, return the index of the first one.

# --hints--

`find_offender([1, 6, 2, 3, 4, 5])` should return `1`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([1, 6, 2, 3, 4, 5]), 1)`)
}})
```

`find_offender([1, 2, 3, 5, 4, 5])` should return `3`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([1, 2, 3, 5, 4, 5]), 3)`)
}})
```

`find_offender([2, 1])` should return `0`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([2, 1]), 0)`)
}})
```

`find_offender([2, 4, 1, 6, 8])` should return `2`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([2, 4, 1, 6, 8]), 2)`)
}})
```

`find_offender([5, 18, 24, 33, 40, 55, 15, 68, 84, 91])` should return `6`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([5, 18, 24, 33, 40, 55, 15, 68, 84, 91]), 6)`)
}})
```

# --seed--

## --seed-contents--

```py
def find_offender(arr):

    return arr
```

# --solutions--

```py
def find_offender(arr):
    for i in range(len(arr)):
        without = arr[:i] + arr[i+1:]
        if all(without[j-1] <= without[j] for j in range(1, len(without))):
            return i
```
