Skip to content

Instantly share code, notes, and snippets.

@inovramadani
Last active January 3, 2021 02:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inovramadani/65793ca2ca8b3774cf85805be42faf37 to your computer and use it in GitHub Desktop.
Save inovramadani/65793ca2ca8b3774cf85805be42faf37 to your computer and use it in GitHub Desktop.
Solution to programming problems in Codility (Javascript)
Lesson 1 - Iterations
BinaryGap: https://app.codility.com/demo/results/trainingMNDHQN-2SY/
Lesson 2 - Array
CyclicRotation: https://app.codility.com/demo/results/training672XDD-B8R/
OddOccurrencesInArray: https://app.codility.com/demo/results/trainingKHZYEY-RR6/
Lesson 3 - Time Complexity
FrogJmp: https://app.codility.com/demo/results/training6JSR59-MEM/
PermMissingElem: https://app.codility.com/demo/results/trainingBFETZ2-2GY/
TapeEquilibrium: https://app.codility.com/demo/results/training2VEEEE-8NJ/
Lesson 4 - Counting Elements
PermCheck: https://app.codility.com/demo/results/training33CW7C-XZ4/
FrogRiverOne: https://app.codility.com/demo/results/trainingV8WSNT-JSA/
MissingInteger: https://app.codility.com/demo/results/trainingQ2WAK5-5GD/
MaxCounters: https://app.codility.com/demo/results/trainingE3HRZ7-9G8/
Lesson 5 - Prefix Sums
CountDiv: https://app.codility.com/demo/results/trainingW92E84-XPZ/
GenomicRangeQuery-1: https://app.codility.com/demo/results/training2RDFM4-FDS/
GenomicRangeQuery-2: https://app.codility.com/demo/results/trainingVYAZGM-U8A/
Lesson 9 - Maximum Slice Problem
MaxSliceSum-1: https://app.codility.com/demo/results/trainingUJ7QCQ-XN9/
MaxSliceSum-2: https://app.codility.com/demo/results/trainingEH5U2S-Y5Z/
MaxProfit: https://app.codility.com/demo/results/trainingRVKYN7-5YY/
@codesnakers
Copy link

The solution provided for: PermCheck
Check whether array A is a permutation.
https://app.codility.com/demo/results/training33CW7C-XZ4/

fails when [5,6] or [13,14] or [29,30] or [61,62] ... is given as input

so basically it would fail for these numbers

[ (2^n + 2^n-1 + .... + 2^2 + 2^0), (2^n + 2^n-1 + .... + 2^2 + 2^1) ]
Consider X^Y here as X to the power of Y

so lets say n=5
[ (2^5 + 2^4 + 2^3 + 2^2 + 2^0), (2^5 + 2^4 + 2^3 + 2^2 + 2^1) ]
= [ 32+16+8+4+1, 32+16+8+4+2 ]
= [ 61,62 ]

the solution([61,62]) will return 1 instead of 0

we can put a simple check/flag in your solution where if number 1 is not present it would return 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment