Codility Programmer Lessons - 04/Q1 (PermCheck)

preview_player
Показать описание
Line by line walkthrough to hit 100% on Codility.
Lesson 04 - Q1 PermCheck

Happy coding :D

- Tariq Albajjali
Рекомендации по теме
Комментарии
Автор

please come back with more lessons. Also i hope you're alive and well

gaeabeauty
Автор

python code
def solution(A):
# Implement your solution here
a_len = len(A)
B = set(A)
for e in range(1, a_len+1):
if e not in B:
return 0
return 1
pass

GiPa
Автор

Do u really need tmpNumber? As I can see ur j variable does tmpNumber's role. U check if j == A[I] and f success u doing j++, then if u miss a number it returns 0, but! If the number was duplicated it still will cause j==A[I] to return false too, cause u have a duplicated previous number which is less then j. After first iteration j == tmpNumber

alexeykolesnik
Автор

Thanks for the lesson.
It was confusing to me to understand how $tempNumber works before I recognize that the array is sorted

ahmadzano
Автор

C++ solution
int solution(std::vector<int>& A) {
std::sort(A.begin(), A.end());
for (std::size_t i = 0; i < A.size(); ++i) {
if (A[i] != (i + 1)) return 0;
}
return 1;
}

benw-lk