Three Largest Number Interview Question: iOS Interviews (Algorithms + FAANG)

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • 🚀 Welcome to our Swift programming interview preparation series! In this video, we dive into a classic coding question that frequently appears during technical interviews. If you're aiming to ace your next coding interview or simply looking to enhance your problem-solving skills in Swift, you're in the right place.
    🔥 Video Overview:
    In this tutorial, we'll walk you through the step-by-step process of solving the "Three Largest Numbers in an Array" interview question using Swift. We'll break down the problem, discuss the optimal approach, and provide you with a clear and concise Swift code implementation.
    🔍 What You'll Learn:
    Understanding the problem statement: We'll dissect the interview question and clarify what's expected from the solution.
    Efficient algorithm design: Learn how to devise an optimal algorithm to find the three largest numbers in an array.
    Swift coding strategies: See how to translate your algorithm into clean and effective Swift code.
    Handling edge cases: Discover how to handle scenarios involving duplicates, smaller arrays, and more.
    Testing and validation: We'll guide you through testing your code with various inputs to ensure its correctness.
    🎓 Who is This For:
    Swift programming enthusiasts
    Computer science students
    Junior developers preparing for coding interviews
    Anyone looking to sharpen their problem-solving skills
    👨‍💻 Prerequisites:
    Basic familiarity with Swift syntax and array manipulation concepts will be beneficial.
    By the end of this video, you'll not only have a solid understanding of how to approach and solve the "Three Largest Numbers in an Array" interview question but also gain valuable insights into problem-solving techniques that can be applied to a wide range of coding challenges.
    Don't forget to like, comment, and subscribe to our channel for more in-depth coding tutorials, interview tips, and programming insights. Let's dive into the world of Swift interview success together!
    💻 Source Code: / iosacademy
    🎥 Subscribe for more: www.youtube.co...
    😎 Like my teaching style? Check out some of my most popular courses! courses.iosaca...
    👉🏼 Connect (personal LinkedIn) / afrazsiddiqui
    🚀 Follow on LinkedIn / ios-academy
    ** Popular Series
    Building Instagram: courses.iosaca...
    Building TikTok: / @iosacademy
    SwiftUI for Beginners: ios-academy.te...
    ** Get Skillshare free for 2 Months and learn iOS
    www.skillshare...
    ** Manage all your investments from app earnings on Betterment!
    bit.ly/3eBwlI9
    ** Grow your own TH-cam tech channel with TubeBuddy:
    www.tubebuddy....
    #swift #interview #faang

ความคิดเห็น • 25

  • @iOSAcademy
    @iOSAcademy  ปีที่แล้ว +4

    Like for a cookie 🍪Also, lets be friends! linkedin.com/in/afrazsiddiqui

    • @dandownscolorado
      @dandownscolorado ปีที่แล้ว +1

      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.

  • @1000ylovers
    @1000ylovers ปีที่แล้ว

    You finally posted interview question! Hopefully we will see more of these!!

  • @MaxTymchii
    @MaxTymchii ปีที่แล้ว +4

    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..

  • @virajpadsala2572
    @virajpadsala2572 11 หลายเดือนก่อน +1

    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

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 4 หลายเดือนก่อน

    Unbelievable that Google asks such easy questions

  • @XsiadzBiskup
    @XsiadzBiskup 9 หลายเดือนก่อน

    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]
    }

  • @victorriurean
    @victorriurean ปีที่แล้ว

    welcome back

  • @r4lphTv
    @r4lphTv ปีที่แล้ว

    func threeLargestNumber(from array: [Int]) -> [Int]{
    guard array.count > 2 else { return [] }
    var result = array.sorted(by: { $0 < $1 })[array.count-3...array.count-1]
    return Array(result)
    }
    let array = [11, 122, 32, 46, 78, 1, 3, 91, 95, 101, 17, 103]
    print(threeLargestNumber(from: array))
    //[101, 103, 122]

  • @fitdevelopertv5148
    @fitdevelopertv5148 3 หลายเดือนก่อน

    =====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)

  • @markaurelius61
    @markaurelius61 ปีที่แล้ว +1

    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..

  • @user-gu1sl1mn2m
    @user-gu1sl1mn2m ปีที่แล้ว +5

    More interview vids please!! I don’t see many iOS interview videos and this was great!!

  • @maqusss
    @maqusss ปีที่แล้ว +2

    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)
    }

  • @waqarzahoor7201
    @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
      @waqarzahoor7201 ปีที่แล้ว

      Gotchas: It fails on this input [7, 8, 9, 15] if we commented out

  • @ipaktulane4748
    @ipaktulane4748 ปีที่แล้ว

    thanks for keeping doing this

  • @GerardRiera-j8u
    @GerardRiera-j8u 11 หลายเดือนก่อน

    I couldn't do that even in a million years T_T

    • @iOSAcademy
      @iOSAcademy  11 หลายเดือนก่อน

      Sure you can!

  • @venuvenu2719
    @venuvenu2719 ปีที่แล้ว

    Is native ios development dying due to KMP release?

    • @ihorzhukov
      @ihorzhukov ปีที่แล้ว

      no, as it haven't died yet after React Native release, and after Flutter release.

    • @shaikrahim8071
      @shaikrahim8071 ปีที่แล้ว

      Never and ever, vision OS Coming, so all orther cross platform will be die very soon.

    • @ihorzhukov
      @ihorzhukov ปีที่แล้ว

      @@shaikrahim8071 why?

    • @thinhphung7417
      @thinhphung7417 11 หลายเดือนก่อน

      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.

  • @timbass9822
    @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.