dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.6 KiB
1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69e2383af7832c8032603b92 | Challenge 276: Offending Element | 29 | 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.
({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.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([1, 2, 3, 5, 4, 5]), 3)`)
}})
find_offender([2, 1]) should return 0.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([2, 1]), 0)`)
}})
find_offender([2, 4, 1, 6, 8]) should return 2.
({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.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_offender([5, 18, 24, 33, 40, 55, 15, 68, 84, 91]), 6)`)
}})
--seed--
--seed-contents--
def find_offender(arr):
return arr
--solutions--
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