Skip to content

Instantly share code, notes, and snippets.

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
@isisnaomi
isisnaomi / largestFour.swift
Created January 21, 2020 18:47
largestFour
//## 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
//
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
@isisnaomi
isisnaomi / longestWord
Created January 21, 2020 18:18
LongestWord
//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"
//
@isisnaomi
isisnaomi / IntentHandler.swift
Last active December 2, 2019 18:25
SiriKit Payment Intent Handler
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))
@isisnaomi
isisnaomi / largestPair.swift
Created October 16, 2019 21:23
Largest Pair
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
}
}
@isisnaomi
isisnaomi / twoSum.swift
Last active October 16, 2019 21:08
Two Sum
/**
* 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]