Last active
September 15, 2023 23:40
-
-
Save lingoslinger/e81f28e8217617004839f89e174e173a to your computer and use it in GitHub Desktop.
Swift: Find second smallest and second largest elements in an array of integers
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
// Implement a function in Swift that finds the second smallest and second largest elements in an array of integers. | |
// this is a trick question designed to make you waste time if you haven't memorized Foundation... | |
func seconds(_ numbers: [Int]) -> (Int?, Int?){ | |
let sorted = numbers.sorted() | |
return (sorted.dropFirst().first, sorted.dropLast().last ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment