programming/iOS/practice

// Arrays import Foundation import XCTest // 1,2,5 11 // Uber set class Solution { class Solution { func partitionString(s: String) -> [String] { var partitions = [String]() var currentPartition = "" var seenLetters = Set<Character>() for letter in s { if seenLetters.contains(letter) { partitions.append(currentPartition) currentPartition = "" seenLetters.removeAll() } currentPartition += String(letter) seenLetters.insert(letter) } if !currentPartition.isEmpty { partitions.append(currentPartition) } return partitions } func topKFrequent(nums: [Int], k: Int) -> [Int] { // Create a dictionary to keep track of the frequency of each element var frequencyDict = [Int: Int]() for num in nums { frequencyDict[num, default: 0] += 1 } // Create a min heap to store the elements based on their frequency var heap = MinHeap<(Int, Int)> { $0....

January 22, 2023

content/interviewing

Uber prep DSA SwiftSearchTrie/SwiftSearchTree.swift at main · wvabrinskas/SwiftSearchTrie #weblinks SimpleApiClient/SimpleApiClient.swift at master · wvabrinskas/SimpleApiClient #weblinks Genetic/Array+Extensions.swift at master · wvabrinskas/Genetic #weblinks Algorithms Recent HashMap with extra tasks + tests, Design photos news feed + API Code up a function that meets specific criteria, analyze runtime and optimize. Mobile systems design, algorithms, iOS live coding and behavioral with Hiring manager There was a behavioral interview, an iOS coding challenge, a data structures & algorithms whiteboard Interview, and iOS app architecture / design Interview....

January 11, 2023

programming/iOS

Apple Challenge 1 /* A FunkyNotificationCenter object that broadcasts events within a program. Code that wants to observe notification events registers a closure via the addObserver(:for:block:) method. Code that sends notifications uses the post(notificationName:) method. Each closure that was registered for that notification name should be called. */ import Foundation class FunkyNotificationCenter { typealias notifBlock = () -> Void var entries: [String: [notifBlock]] = [:] init() // mynotif, block1, block2 /// Post a notification with the given name....

January 11, 2023

About the Language Reference Read the notation that the formal grammar uses. This part of the book describes the formal grammar of the Swift programming language. The grammar described here is intended to help you understand the language in more detail, rather than to allow you to directly implement a parser or compiler. The Swift language is relatively small, because many common types, functions, and operators that appear virtually everywhere in Swift code are actually defined in the Swift standard library....

Attributes Add information to declarations and types. There are two kinds of attributes in Swift — those that apply to declarations and those that apply to types. An attribute provides additional information about the declaration or type. For example, the discardableResult attribute on a function declaration indicates that, although the function returns a value, the compiler shouldn’t generate a warning if the return value is unused. You specify an attribute by writing the @ symbol followed by the attribute’s name and any arguments that the attribute accepts:...

Declarations Introduce types, operators, variables, and other names and constructs. A declaration introduces a new name or construct into your program. For example, you use declarations to introduce functions and methods, to introduce variables and constants, and to define enumeration, structure, class, and protocol types. You can also use a declaration to extend the behavior of an existing named type and to import symbols into your program that are declared elsewhere....

Expressions Access, modify, and assign values. In Swift, there are four kinds of expressions: prefix expressions, infix expressions, primary expressions, and postfix expressions. Evaluating an expression returns a value, causes a side effect, or both. Prefix and infix expressions let you apply operators to smaller expressions. Primary expressions are conceptually the simplest kind of expression, and they provide a way to access values. Postfix expressions, like prefix and infix expressions, let you build up more complex expressions using postfixes such as function calls and member access....

Generic Parameters and Arguments Generalize declarations to abstract away concrete types. This chapter describes parameters and arguments for generic types, functions, and initializers. When you declare a generic type, function, subscript, or initializer, you specify the type parameters that the generic type, function, or initializer can work with. These type parameters act as placeholders that are replaced by actual concrete type arguments when an instance of a generic type is created or a generic function or initializer is called....

Lexical Structure Use the lowest-level components of the syntax. The lexical structure of Swift describes what sequence of characters form valid tokens of the language. These valid tokens form the lowest-level building blocks of the language and are used to describe the rest of the language in subsequent chapters. A token consists of an identifier, keyword, punctuation, literal, or operator. In most cases, tokens are generated from the characters of a Swift source file by considering the longest possible substring from the input text, within the constraints of the grammar that are specified below....

Patterns Match and destructure values. A pattern represents the structure of a single value or a composite value. For example, the structure of a tuple (1, 2) is a comma-separated list of two elements. Because patterns represent the structure of a value rather than any one particular value, you can match them with a variety of values. For instance, the pattern (x, y) matches the tuple (1, 2) and any other two-element tuple....