Searching massive numerical arrays (retired)
Description:
Goal
Make a really efficient function that searches through an array of integers and returns siblings for n
if it were placed into the array. Performance is very important, and there is a hard 100ms execution limit on the massive array tests. This may be accomplished with a BST (read: https://en.wikipedia.org/wiki/Binary_search_tree), and will most likely fail through traditional iteration.
Specifications
Your function will be passed two arguments, bigArray
and n
. Your function should return an array
with 2
elements that are integers
that are the members of the array in which n
would be placed next to. An exception is when n
has no next or previous sibling, in which the element returned should be null
.
bigArray
=> [ Number, Number, ... ]
, sorted least to greatest with at least 2 elements.
n
=> Number
Examples
Given bigArray = [ 1, 3, 5 ]
& n = 4
, your function should return [3, 5]
Same number siblings should prioritize placement near the end of the array.
Given bigArray = [ 1, 3, 3, 3, 5, 5, 6 ]
& n = 3
, your function should return [3, 5]
Leaf placement should show "null"
Given bigArray = [ 1, 3, 5 ]
& n = 0
, your function should return [null, 1]
Given bigArray = [ 1, 3, 5 ]
& n = 7
, your function should return [5, null]
Suggestions
Suggestions are welcomed!
@James1x0
Similar Kata:
Stats:
Created | Aug 6, 2019 |
Warriors Trained | 11 |
Total Skips | 0 |
Total Code Submissions | 60 |
Total Times Completed | 5 |
JavaScript Completions | 5 |
Total Stars | 0 |
% of votes with a positive feedback rating | 0% of 4 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |