Problem Description: Given an array, find the int that appears an odd number of times.
There will always be only one integer that appears an odd number of times.
Level: 6kyu
Link to Kata: Find the odd int
In this Kata we have to find the integer which comes odd number of times. We know that if we sort the array then all the occurrences of a particular integer will be in one continuous line. We initialize an array "indexes" and then we loop through the array. We push the index of the loop to the initialized array till we get the same integers. Once we stop getting the same integers we break out of the loop and check the length of indexes array. If its an odd number then we return the integer which we were checking as answer to this Kata otherwise we reinitialize the indexes array and continue checking with the next integer.
Here is a link to the code: Kata Day 15
Please mention your suggestions or your doubts in the comment below.
Happy coding. :)
No comments:
Post a Comment