This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Task Description: | |
Please write a class in the language of your choice that contains the following two public methods: | |
aboveBelow | |
accepts two arguments | |
An unsorted collection of integers (the list) | |
an integer (the comparison value) | |
returns a hash/object/map/etc. with the keys "above" and "below" with the corresponding count of integers from the list that are above or below the comparison value | |
Example usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Some notes; | |
solution takes 2 integers in a range; returns all numbers that are sorted naturally already (number never 'descends' mid-string); | |
Took about 35-40 minutes (5-10 on devising a solution, 20-25ish on writing code) | |
Also there are certainly more loop-based performance optimizations, but PHP is already pretty performant; I like preg_match. | |
*/ | |
function sortNumberStringChars(string $string, bool $reverse=False): string { | |
$stringArray = str_split($string); |