Skip to content

Instantly share code, notes, and snippets.

@Somtuzy
Created October 31, 2022 13:23
Show Gist options
  • Save Somtuzy/511d67277342c0981b1d4573bc911135 to your computer and use it in GitHub Desktop.
Save Somtuzy/511d67277342c0981b1d4573bc911135 to your computer and use it in GitHub Desktop.
Learnable Technical Test Attempt
function nth_most_rate_signature(list, n) {
list.sort();
let min_count = n+1, res = -1;
let curr_count = 1;
for (let i = 1; i < n; i++) {
// eslint-disable-next-line eqeqeq
if (list[i] == list[i - 1])
curr_count++;
else {
if (curr_count < min_count) {
min_count = curr_count;
res = list[i - 1];
}
curr_count = 1;
}
}
// If last element is least frequent
if (curr_count < min_count)
{
min_count = curr_count;
res = list[n - 1];
}
return res;
}
let arr = [1, 3, 2, 1, 2, 2, 3, 1, 3, 3, 2, 1, 1];
let n = arr.length;
console.log(nth_most_rate_signature(arr, n));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment