Retired

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

Algorithms
Arrays
Data Types

Stats:

CreatedAug 6, 2019
Warriors Trained11
Total Skips0
Total Code Submissions60
Total Times Completed5
JavaScript Completions5
Total Stars0
% of votes with a positive feedback rating0% of 4
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes4
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • James1x0 Avatar
Ad