Question about daily coding problem 1# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Question about daily coding problem 1#

Inside my code is a description. I don't understand what "Can you do it in one pass?" means. https://code.sololearn.com/cV3VQCDiRGFL/?ref=app

13th Mar 2019, 1:44 AM
Denise Roßberg
Denise Roßberg - avatar
10 Answers
+ 2
If you want to do it in O(n) you can use Hashing. https://en.wikipedia.org/wiki/One-pass_algorithm
13th Mar 2019, 3:38 AM
Diego
Diego - avatar
+ 9
I understand "one pass" as "one iteration" but I'not sure...! 🙈🙈🙈
13th Mar 2019, 2:06 AM
Geovanny Martínez Forero
Geovanny Martínez Forero - avatar
+ 3
Diego Is this a one pass solution? https://code.sololearn.com/cMoh3wz0S2oE/?ref=app I have only one for loop to the get the numbers from the array. And a list. If the number is inside my list print true, if not add k-number to the list. If I'm right I check every number only once. And I think that is the sense of one pass.
13th Mar 2019, 11:46 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
You can simply do if (hash.contains(k-numbers[i]) == true){ // Code goes here }
13th Mar 2019, 11:54 PM
Diego
Diego - avatar
+ 3
Coder What makes you think that? I think it is clear that I had only problems with the phrase "one pass". At no point did I write that someone should solve this challenge.
14th Mar 2019, 7:04 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Diego Thank you :)
13th Mar 2019, 8:02 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Diego And add numbers[i] ? Is there a difference?
14th Mar 2019, 12:01 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
What happens when I use other Lists, for example ArrayList instead of a HashSet?
14th Mar 2019, 12:09 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Diego Thanks :)
14th Mar 2019, 12:21 AM
Denise Roßberg
Denise Roßberg - avatar