+ 1

Given an array of integers, find the numbers that appears an odd number of times return an array of the numbers.

input: [1,1,1,2,2,3,3,3,2] output: [1,2,3]

16th Aug 2020, 9:59 PM
notGreat
notGreat - avatar
10 Respuestas
+ 3
For example, now in input you have number A if you have A in array - delete A from array and continue else add A to array In this case you'll have in array only that numbers, that appears an odd number of times
16th Aug 2020, 11:36 PM
Marina Vasilyova
Marina Vasilyova - avatar
+ 1
notGreat I described an algorithm for your problem lol
18th Aug 2020, 7:46 PM
Marina Vasilyova
Marina Vasilyova - avatar
+ 1
notGreat and my algorithm is better than your solution, cause it is O(n) and needs less memory Explanation: you have as input n numbers 1,1,1,2,... And as a data structure for this task you should choose hashset you add first number to hashmap - O(1) from second number to last you you check is there a number in hashset - if no then add O(1), if yes then delete O(1) Finally, you will have only numbers that appears an odd number of time
18th Aug 2020, 7:54 PM
Marina Vasilyova
Marina Vasilyova - avatar
0
Post your attempt first..
17th Aug 2020, 12:36 PM
Jayakrishna 🇮🇳
0
notGreat Pls tag the language also.. May you looking like this : for(i in obj){ if(obj[i].length % 2 !== 0 && obj[i].length != 1) num.push(+i); }
18th Aug 2020, 3:13 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 I don't completely know what your asking, but if that code is part of your solution to the asked problem then it's incorrect, you don't want to filter values with length not equal 1 you would want the first condition obj[I].length % 2 != 0 as 1 is an odd number, you can see that I had that idea on line 10 of my odd int problem
18th Aug 2020, 6:55 PM
notGreat
notGreat - avatar
0
Maria Vasilyova the problem is to determine if there is a number(s) in an array that appears an odd number of time you can view my solution on comment
18th Aug 2020, 7:03 PM
notGreat
notGreat - avatar
0
Jayakrishna🇮🇳 I completed the challenge in JavaScript but you can complete in whatever language you please
18th Aug 2020, 7:07 PM
notGreat
notGreat - avatar
0
notGreat That is a about, dublicate numbers printing.. Can you give an example which is you not getting write? With expected output?
23rd Aug 2020, 9:20 AM
Jayakrishna 🇮🇳