Great topic, thanks! I just add one more thing - change left, top, right, bottom variables not at the end of the while loop but each edge after for in loop. So we change top += 1 after left-right, right -= 1 after top - down, bottom -= 1 after right - left, left += 1 after up. So now we don't need to use +/- 1 in the 'from' argument in the 'stride' function.
hey I have a quick question, if you have created the result array as Array(repeating: nil, count: total), all the values will be nil, and the total count will be 9 anyway. so the code won't even enter the while loop, and in the loop too we have to change the value and not append to the list. I think if we change the while loop condition to check if the last element of the result array is still nil should be a better check! great video, please make more of these in the future, im having great fun finding solutions to these questions! thank you!
Hey Afraz, I wrote a different solution to this that basically peeled off the outer layer of the matrix one at a time and recursively ran the same function on the inner remaining matrix. I'm curious about your thoughts on this approach. It's only slightly faster since you can always rip the top and bottom rows in O(1), but you can't really say it's faster than O(MN)
This solution has a bug. Try running a simple matrix like [[6,7]], it will return [6,7,6] because it runs the backward append right->left even after appended [6,7]. You need to add intermediate checks too.
Hi I'm Sarath, I have one doubt, after changing var result = [Int]() // equivalent to result = [] To var result: [Int?] = Array(repeating: nil, count: total) // equivalent to result = [nil, nil, nil, nil, nil, nil, nil, nil, nil] here total value as 9 now result.count also 9 then how it will enter in to while condition( result.count(9) < total(9)). ?
Great question. I forgot to mention that youll change the while loop to check that the last value is still nil. You also wont append, youll need to change values in place with another index pointer. Great catch!
The two FB/Meta questions I got (with execution and autocomplete disabled on coder pad) QUESTION ONE: Define a Multiset that implements the following methods: 1. add(element) 2. remove(element) 3. count(for: element) QUESTION TWO: Write a function that takes in an input array of houses by the ocean and returns an array containing the indices of houses that can see the ocean (if a taller or equal height house is between a house and the ocean, that house cannot be added) // Ocean View // Input: [4, 3, 2, 3, 1] // Output: [0,3,4] // // ___ // 4 | | ___ ___ // 3 | | | | ___ | | // 2 | | | | | | | | ___ // 1 | | | | | | | | | | // ~~~~~ Ocean // b0, b1, b2, b3, b4
If you can offer a course where you teach High/Low level design aspect of iOS app, something like iOS/Mobile app architecture level it would be more beneficial. (Paid one is also fine). Thanks
Like my teaching style? Check out iOS Academy+ iosacademy.io/plus
MORE ASAP 🙏🏽
Plz continue this algo and design pattern series
I plan to!
Great topic, thanks!
I just add one more thing - change left, top, right, bottom variables not at the end of the while loop but each edge after for in loop.
So we change top += 1 after left-right,
right -= 1 after top - down,
bottom -= 1 after right - left,
left += 1 after up.
So now we don't need to use +/- 1 in the 'from' argument in the 'stride' function.
more of this please! ASAP! I have my interviews with facebook and google soon
Coming soon
This was such a great video. This has easily become my favorite iOS dev channel
Wow, thanks!
Honestly I’m inspired. Your confidence and approach are highly admirable Afraz. Thank you.
Thanks, much appreciated
For optimization. Is it possible to simply apply the reserve capacity of total.count to the resulting array?
Yes
Amazing! This is incredible educational! thanks a bunch!
Youre welcome
In which stage is this asked? In the phone screen interview or in the onsite?
Both
Happy new year sir. Thank you!
Thanks
These videos are amazing, thank you
Youre welcone
hey I have a quick question, if you have created the result array as Array(repeating: nil, count: total), all the values will be nil, and the total count will be 9 anyway. so the code won't even enter the while loop, and in the loop too we have to change the value and not append to the list. I think if we change the while loop condition to check if the last element of the result array is still nil should be a better check!
great video, please make more of these in the future, im having great fun finding solutions to these questions! thank you!
Yep, i forgot to tweak the loop. Answered in a comment below
@@iOSAcademy oh yeah I didn't check! thanks a lot man, appreciate your efforts and loving your recent content :D
@@KailashAnand06 youre welcome!
Hey Afraz, I wrote a different solution to this that basically peeled off the outer layer of the matrix one at a time and recursively ran the same function on the inner remaining matrix. I'm curious about your thoughts on this approach. It's only slightly faster since you can always rip the top and bottom rows in O(1), but you can't really say it's faster than O(MN)
Great solution. Id accept it
This solution has a bug. Try running a simple matrix like [[6,7]], it will return [6,7,6] because it runs the backward append right->left even after appended [6,7]. You need to add intermediate checks too.
You are correct. I forgot to mention this
This algorithm return one more element if there are 4 and more rows or columns
Hi I'm Sarath,
I have one doubt, after changing
var result = [Int]() // equivalent to result = []
To
var result: [Int?] = Array(repeating: nil, count: total) // equivalent to result = [nil, nil, nil, nil, nil, nil, nil, nil, nil] here total value as 9
now result.count also 9
then how it will enter in to while condition( result.count(9) < total(9)). ?
Great question. I forgot to mention that youll change the while loop to check that the last value is still nil. You also wont append, youll need to change values in place with another index pointer. Great catch!
The two FB/Meta questions I got (with execution and autocomplete disabled on coder pad)
QUESTION ONE:
Define a Multiset that implements the following methods:
1. add(element)
2. remove(element)
3. count(for: element)
QUESTION TWO:
Write a function that takes in an input array of houses by the ocean and returns an array containing the indices of houses that can see the ocean (if a taller or equal height house is between a house and the ocean, that house cannot be added)
// Ocean View
// Input: [4, 3, 2, 3, 1]
// Output: [0,3,4]
//
// ___
// 4 | | ___ ___
// 3 | | | | ___ | |
// 2 | | | | | | | | ___
// 1 | | | | | | | | | |
// ~~~~~ Ocean
// b0, b1, b2, b3, b4
Nice!
Dude, thank you. What did you do for question 1? Not sure how to approach it.
Was this asked for the phone interview?
If you can offer a course where you teach High/Low level design aspect of iOS app, something like iOS/Mobile app architecture level it would be more beneficial. (Paid one is also fine).
Thanks
Hey there! I plan to offer this & more in the coming months
Amazing 🤩
Thanks
This algorithm does not work for a 3x4 matrix
damn
Haha thanks
Facebook is trash, both as a company, product, and an idea.
swift is gold, react native is trash
If you pass an interview at Facebook, you can work on any of their products including Instagram and WhatsApp.
@@AllanSpreys I did pass their interviews, and Swiftly told them to fuck right off.
We’re just hear for the algorithms