Skip to content

Instantly share code, notes, and snippets.

View omi9430's full-sized avatar

Umair khan omi9430

  • Saudi Arabia
View GitHub Profile
@omi9430
omi9430 / gist:9c6e44346e94af38b3476d2b52309941
Created August 10, 2022 13:04
Insertion Sort Part - 2 Hacker Rank Swift Solution
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]
@omi9430
omi9430 / gist:8ece75689d8e051e41fc862ea5b7dd59
Last active August 10, 2022 13:02
Hacker Rank Insertion Sort Solution Part - 1
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
@omi9430
omi9430 / gist:2cba44ca1ae72306bcb3d18807572d38
Created August 10, 2022 12:40
Big Sorting Swift Solution
func bigSorting(unsorted: [String]) -> [String] {
let arr = unsorted.sorted {
if $0.endIndex == $1.endIndex {
return $0 < $1
} else {
return $0.endIndex < $1.endIndex
}
}
@omi9430
omi9430 / gist:57fbaa616d989b6fbe02201064792cb6
Created August 3, 2022 15:51
Recursive Digit Sum HackerRank Swift Solution
func recurssion(n: [Int]) -> [Int] {
var recursiveArray = String(n.reduce(0, +)).flatMap { Int(String($0)) }
return recursiveArray
}
func superDigit(n: String, k: Int) -> Int {
@omi9430
omi9430 / gist:8e98c29ababfe4d4164e0c478b140b3a
Created March 30, 2022 08:41
This gist is for Actor example mentioned in my article on https://medium.com/@khanumair-9430
import Foundation
actor MyStocks {
var snackStock = ["Oreo","Pringels","Lays","Mars"]
func remainingSnacks(){
/// Print the snacks array
print("available snacks \(snackStock)")
@omi9430
omi9430 / gist:64ac7abb0e2219f91028cbe7c1001d8b
Created March 30, 2022 08:01
This gist is for Data Race example mentioned in my article on https://medium.com/@khanumair-9430
import UIKit
import Foundation
class ViewController: UIViewController {
var snackStock = ["Oreo","Pringels","Lays","Mars"]
override func viewDidLoad() {
@omi9430
omi9430 / gist:07609d850ecdb14090da5b82f511e66b
Created March 30, 2022 07:55
This gist is for Data Race example mentioned in my article on https://medium.com/@khanumair-9430
import UIKit
import Foundation
class ViewController: UIViewController {
var snackStock = ["Oreo","Pringels","Lays","Mars"]
@omi9430
omi9430 / Minimum Swaps to sort an array
Created February 8, 2022 09:46
Minimum Swaps to sort an array Swift Solution
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
@omi9430
omi9430 / gist:031080043576bcbc6ed440cea79a2fb3
Created February 7, 2022 12:01
A company has N factories, each producing some pollution every month. The company has decided to reduce its total fume emissions by equipping some of the factories with one or more filters. Swift solution
func totalFilter(ar : [Int]) -> Int {
var filters = 0
var sum = ar.reduce(0, +)
var requiredSum = sum/2
var tempArray = ar
@omi9430
omi9430 / gist:85ddbfb33bea53ce8ea1374e351a0c19
Created February 7, 2022 11:41
Pascal's Triangle in Swift
import Foundation
import UIKit
func pascalTriangle(K: Int) {
var defaultArr = [[1],[1,1]]
var tempArray = [Int]()