try checking the "move zeros to front" with the array [0, 7, 0]
@SerJG4 жыл бұрын
Thank you for the video and sharing this information. As for your method that should return an array with all zeros in the beginning of it: In case when array has already zero in the beginning it will swap it to the end e.g. 0, 1, 2, 3, 4 and results of function will be 4, 1, 2, 3, 0
@iOSAcademy4 жыл бұрын
Good catch - I actually noticed this after uploading. The solution would be to run a while loop to move the front index inward until a non 0 is found.
@Ryan-sr9zv4 жыл бұрын
Swift 5 ... Just removeAll(where:) O(n), take the counts before and after O(2), and then append the filtered array O(1) to an array of zeros O(zeros)? Easier to maintain, less iteration.
@christopherliudahl-rackley91083 жыл бұрын
FINALLY something in Objective-C! Please do more in Objective-C!
@iOSAcademy3 жыл бұрын
Coming soon
@venkateswarid82312 жыл бұрын
Thank u..do more for beginners coding questions in interview
@iOSAcademy2 жыл бұрын
Coming soon
@Oscar-ig2gm3 жыл бұрын
I think the solution for first question was wrong, but I liked your video ;)
@ZAP1able4 жыл бұрын
What a chance! I am looking for algorithms and data structures with swift videos and I said almost I found one but it is objc
@iOSAcademy4 жыл бұрын
Don’t worry, I will be adding more in Swift
@MrMarat243 жыл бұрын
I think that for "Return whether or not it contains the UIView" you could have used just a while loop that runs on while(targetView != nil) { if(targetView == view || view == [targetView superView]) { return YES; } targetView = [targetView superView]; } without recursion. this solution should solve it in O(logn) while your solution works in o(n)
@franciselias13814 жыл бұрын
swift solution for first question: func zerosHandler (_ array : [Int]) -> (Int, [Int]) { var counter = 0 var newArray = [Int]() for eachValue in array { if eachValue == 0 { counter += 1 newArray.insert(eachValue, at: 0) } else { newArray.append(eachValue) } } return (counter, newArray) }
@iOSAcademy4 жыл бұрын
Also a great solution! Thanks for sharing
@shynggyssaparbek22093 жыл бұрын
Doen't insert works in O(N). Your solution would be O(N ^ 2) then
@franciselias13813 жыл бұрын
@@shynggyssaparbek2209 the point of this comment was to show that you can return multiple values from one func in swift. Inserting at row 0 does cost o(n) time since it shifts all elements which would make this algo run at o(n^2). A simple dictionary/hashmap could make this run o(n)..
@amitnaskar14974 жыл бұрын
Thank you for making this video. Do you provide any session on ios interview?
@iOSAcademy4 жыл бұрын
You're welcome! And yes! I do 1 on 1 and I also have a whole program for interviewing coming soon. Dm me on instagram @frazzyfraz
@amitnaskar14974 жыл бұрын
@@iOSAcademy I sent the request, please accept and I messaged you on LinkedIn. Please let me know if we can speak on iOS interview program. Thanks!
@sarojtiwari24964 жыл бұрын
Your videos are very informative. Also can you share the code for the second question in swift
@iOSAcademy4 жыл бұрын
Glad you like them! Sure, I plan to do mock interviews in swift as well!
@vijaytholpadis4 жыл бұрын
I happened to solve it in Swift. Hope it helps. ------ func checkFor(_ view: UIView, in initialNode: UIView) -> UIView? { //Base case if initialNode.subviews.isEmpty { if initialNode == view { return initialNode.superview } } for i in 0..
@MrTalhakhan012 жыл бұрын
Aren't these very basic tests for a company like Facebook?
@iOSAcademy2 жыл бұрын
Yes
@JoffreyB3 жыл бұрын
You don't need to zoom in like 10000000x, it's hard to see the whole code structure when you zoom into 1 line of code. Please do take note of that. Great video!
@iOSAcademy3 жыл бұрын
Thanks for the feedback!
@cuevas7144 жыл бұрын
Awesome video ! Just subscribed :)
@iOSAcademy4 жыл бұрын
Glad you liked it!
@pallaviligade53983 жыл бұрын
Do we need to write testcase for this type small Question. Also If there are any 1 hr task e.g API Parsing etc then do we need to write test case.
@HaggleLad3 жыл бұрын
You recommend testing your solution but don't Facebook use Coderpad with execution *disabled* (in 2020), so that's not possible right?
@trs_46123 жыл бұрын
funky question, guys. i legit don't know if you are an iOS Developer then you will interview using swift? i'm not familiar with the language. why i can't picture it is because given the nature of the interviews like loops, DS, and algorithm, i can't picture using swift for that.
@iOSAcademy3 жыл бұрын
You can use swift or objc
@trs_46123 жыл бұрын
@@iOSAcademy thank you. i will do some more digging. i just switched from grinding leetcode using Python to iOS interviews.
@sheldon946664 жыл бұрын
It would be wrong if there is a nil nsnumber in that areay
@iOSAcademy4 жыл бұрын
Correct
@vijaytholpadis4 жыл бұрын
Thanks for the video. I solved the "Bringing zeros to the front" problem in the following way in Swift. It also retains the order of other elements. Time complexity: O(n) ---------- func bringZerosToTheFront(_ array: inout [Int]) { var countIndex = array.count - 1 let arrayLength = array.count for i in (0..
@iOSAcademy4 жыл бұрын
Nice! Great solution
@42ALR424 жыл бұрын
In a more Swifty way I would do a reorder function like this : func reArrangeArray(input: inout Array, indexDelete: Int, indexInsert: Int) -> Array { let reArrangedItem = input.remove(at: indexDelete) input.insert(reArrangedItem, at: indexInsert) return input } An then the method to use it func reorder() { var arrCopy = arr arrCopy.enumerated().forEach { (index , item) in if item == 0 { reArrangeArray(input: &arrCopy, indexDelete: index, indexInsert: 0) } } print(arrCopy) }
@mike_zander3 жыл бұрын
Hey great video! Even though Facebook uses Obj-C, can you use swift for these domain specific questions??
@iOSAcademy3 жыл бұрын
Yes you can! I personally did a few years back ;)
@abdulrahim464 жыл бұрын
Thanks. Keep up the good work!
@iOSAcademy4 жыл бұрын
thanks!
@AnkitSoni304 жыл бұрын
thanks for the video..
@SWATversion34 жыл бұрын
Your move zeros to front will not work if the array starts with 0 or a series of zeros. This solution will get you disqualified.