This file contains 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 minEdit(_ s1: String, _ s2: String) -> Int { | |
if s1.isEmpty { | |
return s2.count | |
} | |
if s1.first == s2.first { | |
return minEdit(String(s1.suffix(s1.count-1)), String(s2.suffix(s2.count-1))) | |
} else if s1.count == s2.count { | |
return 1 + minEdit(String(s1.suffix(s1.count-1)), String(s2.suffix(s2.count-1))) | |
} else { |
This file contains 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
/* | |
Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list. If there is more than one possible reconstruction, return any of them. If there is no possible reconstruction, then return null. | |
For example, given the set of words 'quick', 'brown', 'the', 'fox', and the string "thequickbrownfox", you should return ['the', 'quick', 'brown', 'fox']. | |
Given the set of words 'bed', 'bath', 'bedbath', 'and', 'beyond', and the string "bedbathandbeyond", return either ['bed', 'bath', 'and', 'beyond] or ['bedbath', 'and', 'beyond']. | |
store words in a set | |
loop through string | |
build word |
This file contains 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
/* | |
You are given an M by N matrix consisting of booleans that represents a board. Each True boolean represents a wall. Each False boolean represents a tile you can walk on. | |
Given this matrix, a start coordinate, and an end coordinate, return the minimum number of steps required to reach the end coordinate from the start. If there is no possible path, then return null. You can move up, left, down, and right. You cannot move through walls. You cannot wrap around the edges of the board. | |
For example, given the following board: | |
[[f, f, f, f], | |
[t, t, f, t], | |
[f, f, f, f], |
This file contains 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
struct Pixel { | |
var color: Color | |
var isExit: Bool | |
init(color: Color, isExit: Bool = false) { | |
self.color = color | |
self.isExit = isExit | |
} | |
} | |
enum Color { |
This file contains 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
-(void) swapFirst:(int)first withSecond:(int)second inArray:(NSMutableArray *)array | |
{ | |
NSNumber *temp = array[first]; | |
array[first] = array[second]; | |
array[second] = temp; | |
return; | |
} | |
-(int) findKthLargestNumber:(int)k | |
inArray:(NSMutableArray *)array |
This file contains 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
// O(E * logV) where E is the number of Edges and V is the number of Vertices | |
// Why? We process every vertex with extractMin in the pqueue which results in a lgV runtime and we do this for every vertex and their neighbors (edges). | |
// This results in a (E + V)(lgV) runtime. In a connected graph, V = O(E) therefore our runtime complexity is just O(ElgV). | |
@interface Pair | |
@property int vertex; | |
@property int weight; | |
+(instanceType)initWithVertex:(int)vertex; | |
@end |
This file contains 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
// TrieNode | |
// TrieNodes hold a dictionary of child TrieNode objects keyed by their character. | |
// isValid == YES means that the word exists in the dictionary | |
@interface TrieNode : NSObject | |
@property (strong, nonatomic) NSMutableDictionary<NSString *, TrieNode *> *children; | |
@property (assign, nonatomic) BOOL isValid; | |
-(instancetype)init; | |
@end |