Two-Sum Problem - Swift Tutorial - iOS Interview Coding Challenge

preview_player
Показать описание
The next video in my iOS Interview questions series all about coding challenges explains the two-sum problem and its multiple solutions in Swift. We'll solve this problem three different ways with varying levels of efficiency (Big O Notation)

More on Big O Notation:

Xcode Project Source Code:

iOS Dev Courses:

Twitter:

Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):

Paul Hudson's Hacking With Swift:

Donny Wals - Combine:

Mark Moeyken’s SwiftUI Books:

Ray Wenderlich Books:

#swift #softwaredeveloper #iosdeveloper
Рекомендации по теме
Комментарии
Автор

Wow! The pointer solution is so clever! Simple and beautiful :)

danylokurylo
Автор

Thanks and I hope you realize how much value you are bringing to iOS developers. These algos are not easy to learn and you are doing a great job at chunking down the larger concept into code that is easy to absorb.

whansen
Автор

I really think showing the linear solution with a set here would’ve been highly beneficial. Our last solution works only because the array is sorted and this problem in interviews is almost never sorted. The solution below is always linear.

var seenSet: Set<Int> = []

for num in array {
If seenSet.contains(sum - num) {
return true
} else {
seenSet.insert(num)
}
}

return false

vrezhgulyan
Автор

First of all, thank you very much, your videos are very well explained and easy to understand. I think it's worth mentioning that the array need to be sorted for binary search and pointer move approach.

vastu
Автор

Just saw this video and i wanted to confirm something.
The Linear Solution you did for it Its fine for the Array you took. But you are taking 3 presumptions to solve this.
1. Data in array is sorted,
2. There is ONLY 1 match to get the sum value
3. No Value in Array is repeated (this one goes for all 3)

Can you confirm if I am thinking wrong here ? or am i right ?

allpurposeee
Автор

@Sean
If you look at the documentation the remove(at: Index) is of complexity O(n) it would add more computation in binarySearch flow
/// - Complexity: O(*n*), where *n* is the length of the array.
public mutating func remove(at index: Int) -> [Element].Element

MrSaberjack
Автор

That was the best explanation I found on youtube until now.

AgamRandhawa
Автор

Fast? Finally a video I don't need to speed up. :)

JayMutzafi
Автор

Pointer solution is really good bro.. i also solved this problem with 2 for loops but whatever you suggested its simply short and sweet

karunav
Автор

This was a long one.... Happy to help answer questions or clear up any confusion in the comments!

seanallen
Автор

Man! Thanks! Revisiting Algorithms on the Job Search! This explanation is dope. Any book Recommendations for Interview Questions?

jerrick.warren
Автор

The pointer solution doesn't work well in different scenarios like
[3, 2, 4] and the target is 6

muhammadusman
Автор

Your last two videos explain starting with a sorted array. Do you plan on reviewing any sorting algorithms?

Love your videos btw man. Easy to follow and you do a great job explaining concepts!

leeper
Автор

In brute-force methode you can loop j starting from i+1 instead of from 0, because for j = 0...i you've done in the previous loops. The loop should say "for j in i+1..<array.count" and you don't have to add "where j != i". And in worst case you need n*(n-1)/2 times instead of (n-1)*(n-1) time. For Big O notation, that might be the same but in real world, when n is significant, it matters. Lets take your array, and take sum = 26 (worst case), when you run j from 0, it takes 36 times, but when you run j from i+1, it takes 21 times. Thanks for the video!

Tamagochi
Автор

Just today I had oral exam in data structures and algorithms and was talking about brute force, binary search, notations etc... It fantastic to see how to work with something like that in swift :D keep crushing it

kristijanrotim
Автор

in Brute Force method, we could even skip the last iteration because the last number(14) has already been compared to all other numbers, like:
for i in 0..<array.count-1

dodilodi
Автор

Thanks so much for your videos. I love these videos as I can grasp it easier if I am stepped through it.

Thanks to your delegate tutorial, I was able to do my app which is on the app store now :) thanks so much for doing these videos please keep doing them.

GoldenSpud
Автор

Isn't "complement" written with "e" ? just to make sure I understand correctly. Anyway great video as always!

filippo
Автор

perfect!!!! Can you please make video on how to calculate time complexity of a program.It would be really helpful Thanks In Advance.

sheetalshinde
Автор

Nice Explanation....Are you planning to do a separate video on Time complexity and how to calculate it?

nikhilmuskur
join shbcf.ru