forked from codecat15/Youtube-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding machine round part 1 questions
- Loading branch information
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
Interview series/Machine Round - 1/MyPlayground.playground/Contents.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import Foundation | ||
|
||
/** | ||
|
||
I hope the video was helpful, please feel free to reach out for any issues or any if you have any machine round question then feel free to share it with me I'll try and add them to the series | ||
|
||
Based on the feedback of the video, I plan to continue this series, if you like to see such content in the future then please do like the video and add your comments in the video | ||
|
||
Regards, | ||
Ravi | ||
|
||
*/ | ||
|
||
|
||
// Question # 1: remove duplicate from array | ||
var arrayWithDuplicates : [Int] = [3,3,4,7,15,2,1,2,7,10,12,11,10,15,18,15,20,11] | ||
|
||
var charArray : [Character] = ["a","a","c","b","b","d","e","e"] | ||
|
||
extension Array where Element : Equatable { | ||
|
||
func removeDuplicate() -> [Element] { | ||
|
||
guard !self.isEmpty else {return []} | ||
|
||
var temp : [Element] = [] | ||
|
||
self.forEach { item in | ||
if(!temp.contains(item)) { | ||
temp.append(item) | ||
} | ||
} | ||
|
||
return temp | ||
} | ||
} | ||
|
||
let result = arrayWithDuplicates.removeDuplicate() | ||
print(result) | ||
|
||
|
||
//let result = Set(arrayWithDuplicates) | ||
//print(result) | ||
|
||
//func removeDuplicate(arr: Array<Int>) -> Array<Int> { | ||
// | ||
// guard !arr.isEmpty else {return []} | ||
// | ||
// | ||
// var temp : [Int] = [] | ||
// | ||
// arr.forEach { item in | ||
// if(!temp.contains(item)) { | ||
// temp.append(item) | ||
// } | ||
// } | ||
// | ||
// return temp | ||
//} | ||
|
||
|
||
// Question # 2: create an array extension for only Int types | ||
|
||
//extension Array where Element == Int { | ||
// | ||
// func removeDuplicate() -> [Element] { | ||
// | ||
// guard !self.isEmpty else {return []} | ||
// | ||
// var temp : [Element] = [] | ||
// | ||
// self.forEach { item in | ||
// if(!temp.contains(item)) { | ||
// temp.append(item) | ||
// } | ||
// } | ||
// | ||
// return temp | ||
// } | ||
//} | ||
|
||
// Question #3: Get all the capital characters from a string | ||
|
||
var str = "Hello World" | ||
|
||
func filterCapitalCharacters(fromString input: String) -> String? { | ||
|
||
guard input.isEmpty == false else { return nil} | ||
let result = input.filter({("A"..."Z").contains($0)}) | ||
|
||
return result.isEmpty ? nil : result | ||
} | ||
|
||
print(filterCapitalCharacters(fromString: "")) | ||
|
||
// Question #4: convert [Any] to [Int] | ||
|
||
let input : [Any] = [true, 1, "ravi", 2, "codecat15", false, "test"] | ||
|
||
func convertToIntArray(inputValue: [Any]) -> [Int] { | ||
|
||
guard inputValue.isEmpty == false else { return [] } | ||
|
||
let result = inputValue.compactMap { item in | ||
item as? Int | ||
} | ||
|
||
return result.isEmpty == false ? result : [] | ||
} | ||
|
||
print(convertToIntArray(inputValue: input)) |
4 changes: 4 additions & 0 deletions
4
Interview series/Machine Round - 1/MyPlayground.playground/contents.xcplayground
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
...Machine Round - 1/MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+12.3 KB
...d/playground.xcworkspace/xcuserdata/ravirdixit.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
...layground.playground/xcuserdata/ravirdixit.xcuserdatad/xcschemes/xcschememanagement.plist
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>SchemeUserState</key> | ||
<dict> | ||
<key>MyPlayground (Playground).xcscheme</key> | ||
<dict> | ||
<key>isShown</key> | ||
<false/> | ||
<key>orderHint</key> | ||
<integer>0</integer> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |