Skip to content

Instantly share code, notes, and snippets.

View ilyarmnzhdn's full-sized avatar

Ilyar Mnazhdin ilyarmnzhdn

  • Moscow
View GitHub Profile
@ilyarmnzhdn
ilyarmnzhdn / gist:c9fdd4216ee2e42212270b38167c5796
Last active August 24, 2018 17:48
771. Jewels and Stones (Amazon interview question, "easy")
// My Swift-y solution 28ms
func numJewelsInStones(_ J: String, _ S: String) -> Int {
var resultDict = [Character: Int]()
for element in Array(J) {
resultDict[element] = 0
}
for element in Array(S) {
@ilyarmnzhdn
ilyarmnzhdn / gist:c10b9c6a681ac90e0f552bdb9e53a270
Last active June 10, 2018 10:37
Unique Morse Code Words
let dictMap: [Character: String] = [
"a":".-",
"b":"-...",
"c":"-.-.",
"d": "-..",
"e":".",
"f":"..-.",
"g":"--.",
"h":"....",
"i":"..",
@ilyarmnzhdn
ilyarmnzhdn / gist:5e7493dc11ea27de5369da4ea6984671
Created June 7, 2018 21:32
Reverse Vowels of a String [swift 4]
extension Character {
var isVowel: Bool { return ["a","e","i","o","u","A","E","I","O","U"].contains(self) }
}
func reverseVowel(s: String) -> String {
if s.count == 0 { return "" }
var characters = [Character]()
var reversedString = ""
s.forEach { vowel in
if vowel.isVowel {
@ilyarmnzhdn
ilyarmnzhdn / gist:b13ecc792b55b66cba035a2b40a2f945
Created May 27, 2018 12:09
Beeline 2 interview question
import XCTest
@testable import InterviewQuestion2
class InterviewQuestion2Tests: XCTestCase {
func sumOfDigits(for number: Int) -> Int {
let arrayOfDigits = Array(sequence(state: number, next: { return $0 > 0 ? ($0 % 10, $0 = $0 / 10).0 : nil }))
return arrayOfDigits.reduce(0, {$0 + $1})
}
@ilyarmnzhdn
ilyarmnzhdn / gist:cd023ae34601b29af9ed658151b7822b
Last active May 27, 2018 12:29
Beeline 1 interview question
import XCTest
@testable import InterviewQuestion1
class InterviewQuestion1Tests: XCTestCase {
func addition(left: String, right: String) -> String {
guard left != "" || right != "" else {
return "Enter a correct number"
}
let leftDigitsArray = left.reversed().map { Int(String($0))! }
@ilyarmnzhdn
ilyarmnzhdn / gist:aa67838f392c532ede16861dfed93c42
Created November 1, 2017 09:28
Find the longest word in string (Swift 4)
func findLongestWord(word: String) -> String {
let wordArray = word.components(separatedBy: " ")
var maxLength = 0
for index in 0..<(wordArray.count) {
if wordArray[index].count > maxLength {
maxLength = wordArray[index].count
}
}
@ilyarmnzhdn
ilyarmnzhdn / gist:9ed816afeb57babddcf999c132256b1d
Created November 1, 2017 08:17
Factorialize Int using recursion (Swift)
func factorialize(number: Int) -> Int {
if (number == 0) { return 1 }
return (number * factorialize(number: number - 1))
}
factorialize(number: 6)