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
/** | |
* TwoSum | |
* Write a function that takes a list and outputs alist of numbers | |
* belonging to the list that can be summed up to the first element of the list. | |
* | |
* Test Cases | |
* > twoSum [17, 4, 5, 6, 10, 11, 4, -3, -5, 3, 15, 2, 7] | |
* 6, 11, 10, 7, 15, 2 | |
* | |
* > twoSum [7, 6, 4, 1, 7, -2, 3, 12] |
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
func largestPair(_ num: Int) -> Int { | |
var largestPair: Int = 0 | |
let digits = String(num).map { Int(String($0))! } | |
for index in 0 ..< digits.count - 1 { | |
let pair = digits[index]*10 + digits[index+1] | |
if pair > largestPair { | |
largestPair = pair | |
} | |
} |
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
import Intents | |
extension IntentHandler: INSendPaymentIntentHandling { | |
func handle( | |
intent: INSendPaymentIntent, | |
completion: @escaping (INSendPaymentIntentResponse) -> Void | |
) { | |
// Perform the expected action. Report back to Siri | |
// This is the place to call your service, update database, or whatever you need to do. | |
completion(INSendPaymentIntentResponse.init(code: .success, userActivity: nil)) |
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
//Longest Word | |
// | |
//**Challenge** | |
// | |
//Have the function LongestWord(**sen**) take the **sen** parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume **sen** will not be empty. | |
// | |
//**Sample Test Cases** | |
// | |
//Input:"fun&!! time" | |
// |
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
func simpleAddingGauss(_ number: Int) -> Int { | |
return (number * (1 + number)) / 2 | |
} | |
func simpleAddingNaive(_ number: Int) -> Int { | |
var sum = 0 | |
for i in 0...number { | |
sum = sum + i | |
} | |
return sum |
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
//## Largest Four | |
// | |
//**Challenge** | |
// | |
//Have the function LargestFour(**arr**) take the array of integers stored in **arr**, and find the four largest elements and return their sum. | |
// | |
//**Sample Test Cases** | |
// | |
//Input:1, 1, 1, -5 | |
// |
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
func setIntersection(arr1: [Int], arr2: [Int]) -> [Int] { | |
var result: [Int] = [] | |
var pointer1 = 0 | |
var pointer2 = 0 | |
while pointer1 < arr1.count && pointer2 < arr2.count { | |
if arr1[pointer1] == arr2[pointer2] { | |
result.append(arr1[pointer1]) | |
pointer1 = pointer1 + 1 | |
pointer2 = pointer2 + 1 |