This file contains hidden or 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 insertionSort2(n: Int, arr: [Int]) -> Void { | |
var newArr = arr | |
for i in 1..<n { | |
var key = newArr[i] | |
var j = i - 1 | |
while j >= 0 && newArr[j] > key{ | |
newArr[j + 1] = newArr[j] |
This file contains hidden or 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 insertionSort1(n: Int, arr: [Int]) -> Void { | |
// Write your code here | |
var newArr = arr | |
for i in 1...n-1{ | |
var key = newArr[i] | |
var j = i - 1 | |
while j >= 0 && newArr[j] > key { | |
newArr[j + 1] = newArr[j] | |
j = j - 1 |
This file contains hidden or 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 bigSorting(unsorted: [String]) -> [String] { | |
let arr = unsorted.sorted { | |
if $0.endIndex == $1.endIndex { | |
return $0 < $1 | |
} else { | |
return $0.endIndex < $1.endIndex | |
} | |
} |
This file contains hidden or 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 recurssion(n: [Int]) -> [Int] { | |
var recursiveArray = String(n.reduce(0, +)).flatMap { Int(String($0)) } | |
return recursiveArray | |
} | |
func superDigit(n: String, k: Int) -> Int { |
This file contains hidden or 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 Foundation | |
actor MyStocks { | |
var snackStock = ["Oreo","Pringels","Lays","Mars"] | |
func remainingSnacks(){ | |
/// Print the snacks array | |
print("available snacks \(snackStock)") |
This file contains hidden or 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 UIKit | |
import Foundation | |
class ViewController: UIViewController { | |
var snackStock = ["Oreo","Pringels","Lays","Mars"] | |
override func viewDidLoad() { |
This file contains hidden or 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 UIKit | |
import Foundation | |
class ViewController: UIViewController { | |
var snackStock = ["Oreo","Pringels","Lays","Mars"] | |
This file contains hidden or 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 minimumSwaps(arr : [Int]) -> Int { | |
var swaps = 0 | |
var sortedArr = arr.sorted() | |
var tempArr = arr | |
var indexDict : [Int : Int] = [:] | |
for i in 0...tempArr.count - 1{ | |
indexDict[tempArr[i]] = i |
This file contains hidden or 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 totalFilter(ar : [Int]) -> Int { | |
var filters = 0 | |
var sum = ar.reduce(0, +) | |
var requiredSum = sum/2 | |
var tempArray = ar | |
This file contains hidden or 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 Foundation | |
import UIKit | |
func pascalTriangle(K: Int) { | |
var defaultArr = [[1],[1,1]] | |
var tempArray = [Int]() | |
NewerOlder