DEV Community

0 seconds of 1 minute, 18 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
01:18
 
✨ thetealpickle 📱
✨ thetealpickle 📱

Posted on

3

First Duplicate!!Swift Coding Challenge!!

Swift coding challenge!!
First Duplicate. Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index.

😛 Level: Easy 😛

I have included a solutions video!! The video gives some insight into how I’ve solved the problem. Don’t forget to try the problem out BEFORE checking out the solution video and solution code 😉 😉

If you have a coding challenge you want me to solve feel free to drop a comment or message me with the problem!! 😊 😊 let’s get swole 💪🏾 💻 💻

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
roc3n profile image
roc3n

let array = [2, 1, 3, 5, 3, 2]

func firstDuplicateIn (array: [Int]) -> Int {
var array2 = Int
for i in 0..<array.count {
if array2.contains(array[i]) {
return array[i]
} else {
array2.append(array[i])
}
}
return -1
}
print(firstDuplicateIn(array: array))

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay