Like for a cookie 🍪Also, lets be friends! linkedin.com/in/afrazsiddiqui
@dandownscolorado Жыл бұрын
Did you try duplicate large numbers? [12, 12, 10, 9] How about [1, 2]? I bet it will give you [Int.min, 1, 2] for an output.
@user-gu1sl1mn2m Жыл бұрын
More interview vids please!! I don’t see many iOS interview videos and this was great!!
@1000ylovers Жыл бұрын
You finally posted interview question! Hopefully we will see more of these!!
@ipaktulane4748 Жыл бұрын
thanks for keeping doing this
@maqusss Жыл бұрын
Playing with indexes is a little confusing. Following seems simpler to me: func solve(_ arr: [Int]) -> (Int,Int,Int)? { guard arr.count >= 3 else { return nil } // m1 >= m2 >= m3 var m1: Int = arr.min()! var m2: Int = m1 var m3: Int = m1 for x in arr { if x >= m1 { m3 = m2 m2 = m1 m1 = x } else if x >= m2 { m3 = m2 m2 = x } else if x >= m3 { m3 = x } } return (m3,m2,m1) }
@victorriurean Жыл бұрын
welcome back
@waqarzahoor7201 Жыл бұрын
The solution that you have provided If we commented out the below lines it also works. func rearrange(number: Int, result: inout [Int]) { var toBeInsertedIdx = -1 if number > result[2] { toBeInsertedIdx = 2 } else if number > result[1] { toBeInsertedIdx = 1 } else if number > result[0] { toBeInsertedIdx = 0 } else { return } var currentIdx = toBeInsertedIdx while currentIdx > 0 { // let temp = result[currentIdx - 1] result[currentIdx - 1] = result[toBeInsertedIdx] currentIdx -= 1 // result[toBeInsertedIdx] = temp } result[toBeInsertedIdx] = number }
@waqarzahoor7201 Жыл бұрын
Gotchas: It fails on this input [7, 8, 9, 15] if we commented out
@MaxTymchii Жыл бұрын
What do you think about this? func threeLargestDigits(at inputArray: [Int]) -> [Int] { guard inputArray.count > 2 else { return [] } var result: [Int] = .init(repeating: Int.min, count: 3) inputArray.forEach { newValue in rearrange(newValue, result: &result) } return result.reversed() } func rearrange(_ number: Int, result: inout [Int]) { var candidateNumber = number for index in 0..
@techwithchavan Жыл бұрын
LGTM
@Денис-ж3ф5р8 ай бұрын
Unbelievable that Google asks such easy questions
@venuvenu2719 Жыл бұрын
Is native ios development dying due to KMP release?
@ihorzhukov Жыл бұрын
no, as it haven't died yet after React Native release, and after Flutter release.
@shaikrahim8071 Жыл бұрын
Never and ever, vision OS Coming, so all orther cross platform will be die very soon.
@ihorzhukov Жыл бұрын
@@shaikrahim8071 why?
@thinhphung7417 Жыл бұрын
Never. Because Apple will never let its son die. Cross platform will be depend on native, there are many APIs and functions that cross platform will never be easy to implement, and never has performance good as native code.
@fitdevelopertv51486 ай бұрын
=====SOLUTION IN SWIFT====== let array = [1,88,2,12,11,23,104] //[88,23,12] var resultArray = Array(Array(repeating: Int.min, count: 3)) for i in 0.. resultArray[0] { resultArray[2] = resultArray[1] resultArray[1] = resultArray[0] resultArray[0] = array[i] } else if array[i] > resultArray[1] { resultArray[2] = resultArray[1] resultArray[1] = array[i] } else { resultArray[2] = array[i] } } print(resultArray)
@XsiadzBiskup Жыл бұрын
func threeLargest(numbers:[int]) -> [int] { guard numbers.count >= 3 else {return []} return numbers.sorted(by: >).prefix(3) } You can do this in 2 lines of code. This is going to have a complexity of O(n log(n)). A more optimal way O(n) would be to do this without sorting and iterate though the numbers finding the 3 largest ones. func findThreeLargestNumbers(in array: [Int]) -> [Int] { guard array.count >= 3 else { print("Array should have at least 3 elements.") return [] } var largest = Int.min var secondLargest = Int.min var thirdLargest = Int.min for number in array { if number > largest { (largest, secondLargest, thirdLargest) = (number, largest, secondLargest) } else if number > secondLargest { (secondLargest, thirdLargest) = (number, secondLargest) } else if number > thirdLargest { thirdLargest = number } } return [largest, secondLargest, thirdLargest] }
@virajpadsala2572 Жыл бұрын
let sortedNumbers = numbers.sorted(by: >) // Sort the numbers in descending order return Array(sortedNumbers.prefix(3)) // Select the first three elements This will do the trick instead of repeating and rearranging
@markaurelius61 Жыл бұрын
If you can use sorting, it looks like this: let nums = [10, 9, 20, 22, 15, 100, 2] let upper = min(3, nums.count) let a1 = Array(nums.sorted().reversed()[0..
@timbass9822 Жыл бұрын
Should have used sort(). Writing code to do what sort() or sorted() does means money wasted managing unnecessary code. In my past, would not hire anyone who rewrites built-in functionality.
@anupdsouza13 күн бұрын
That's not the point. Higher order functions obviously make life easier but companies prefer that candidates come up with solutions without using them to gauge their problem solving & data structure skills.