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
class Solution { | |
func setZeroes(_ matrix: inout [[Int]]) { | |
if matrix.isEmpty { | |
return | |
} | |
struct Coordinate: Equatable, Hashable { | |
var row: Int | |
var column: 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
func selectionSort(forInput input: inout [Int]) { | |
let uptoIndex = input.count - 1 | |
var currentRunningMaximumNumber = input[0] | |
for rearIndex in 0..<uptoIndex { | |
// Assuming all are sorted | |
var isAllSorted = true | |
// Assuming rearIndex is minimum Index |
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 insertionSort(forInput input: inout [Int]) { | |
let uptoIndex = input.count - 1 | |
for rearIndex in 1...uptoIndex { | |
let rearValue = input[rearIndex] | |
var currentRunningIndex = rearIndex | |
while currentRunningIndex > 0 && input[currentRunningIndex - 1] > rearValue { | |
input[currentRunningIndex] = input[currentRunningIndex - 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 bubbleSort(forInput input: inout [Int]) { | |
let uptoEndIndex = input.count - 1 | |
for rearIndex in 0...uptoEndIndex { | |
var isAllSorted = true | |
for frontIndex in 0..<uptoEndIndex - rearIndex { | |
let currentRunning = frontIndex | |
let currentRunningAheadByOne = currentRunning + 1 | |
if input[currentRunning] > input[currentRunningAheadByOne] { | |
input.swapAt(currentRunning, currentRunningAheadByOne) |
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
// MARK: Data Structure | |
public class BinaryTreeNode<Element: Comparable> { | |
weak var parent:BinaryTreeNode? | |
var leftNode:BinaryTreeNode? | |
var payload:Element | |
var rightNode:BinaryTreeNode? | |
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
// Problem: https://www.pramp.com/challenge/2WBx3Axln1t7JQ2jQq96 | |
func findBusiestPeriod(data: [[Int]]) -> Int { | |
var timeStamp = 0 | |
var busiest = -1 | |
var currentBusiest = 0 | |
let length = data.count | |
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 isvalidPasswordPolicy(_ password: String) -> Bool { | |
// Output | |
var isValidPasswordPolicy = false | |
// Get the component of each password policy | |
let components = password.components(separatedBy: CharacterSet.whitespaces) | |
// From 1st component get the lower and upper bound | |
let first = components[0].components(separatedBy: "-") | |
guard var lowerBound = Int(first.first ?? "0") else { return isValidPasswordPolicy } |
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 isvalidPasswordPolicy(_ password: String) -> Bool { | |
// Output | |
var isValidPasswordPolicy = false | |
// Get the component of each password policy | |
let components = password.components(separatedBy: CharacterSet.whitespaces) | |
// From 1st component get the lower and upper bound | |
let first = components[0].components(separatedBy: "-") | |
guard let lowerBound = Int(first.first ?? "0") else { return isValidPasswordPolicy } |
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 Combine | |
// MARK: - Error | |
enum APIError: Error, LocalizedError { | |
case unKnown | |
case apiError(reason: String) | |
} | |
extension APIError { |
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 findIndexOf(targetSum sum: Int, in inputArray: [Int]) -> (Int,Int) { | |
// Output Indices | |
var indices: (Int,Int) = (-1, -1) | |
// hastable | |
var hashTable = [Int:Int]() | |
// enumerate it | |
for (index, value) in inputArray.enumerated() { | |
// check if hastable has complementry value (i.e index) | |
if let rightIndex = hashTable[value] { | |
indices.0 = index |
NewerOlder