6 kyu
Find the odd int
97,175 of 312,906rbuckley
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
Random test cases in C have multiple integers with odd count but description says test cases shouldn't examples: for array = {7, 1, 7, 75, 75, 1, -11, -11, 7, 7, 75, -11, -11, -11, -11, 7, 7, 7, 1, 1, 75, 7, -11, 75, 75, 1, 75, 75, -11, 75, 1} expected 1 but got 75 for array = {59, -34, 59, 59, 59, 59, 59, 59, 59, 59, 59, -34, -34, 59, 59, -34, -34, 59, 59, 59, -34, -34, 59, 59, 59, 59, 59, -36, 59} expected -36 but got 59
You are mutating the
array
array because of a buffer overflow. Note thatsizeof
do not return the number of elements in an array but the size in bytes of its operand. So an array of 4int
s will have a size of 16 bytes because eachint
has a size of 4 bytes.Just fix this minor issue and your code pass :)
closing as a user error and not an issue within the tests
Today I learned something new.
This comment has been hidden.
This comment has been hidden.
Reading the link you posted: "Browser compatibility: Node 21".
It is not a bug with the kata, you used API which is not available on Codewars.
Oh, You are right. Didn't noticed the compatibilty. Sorry.
What to return in case of [1,1,1,2,2,2]?
That's not a valid input value.
Fun kata, I liked it
Reminder it's been half an hour, think of the Roman Empire. Translation Dart
love it - i've solved it in the most inefficient way possible with 2 different arrays and 3 for loops lol welp i'm still learning
Easier than 6 Kyu.
Ranks can't be changed for old katas with high completions
My bad. Thanks for letting me know!
This comment has been hidden.
Your solution returns wrong answer for inputs like
[3, 2, 2]
.Your solution has a bug, it is not a kata issue.
the return statment should have a semi colon: (in java) INCREDABLY minor issue.
(OP was referring to the initial code, which would not compile) Fixed.
this kata is so bad bruh delete this sh
Why
This comment has been hidden.
You definitely can, and it seems that you did...
For some extrange reason, I thought the kata has to check if the number of instances is a PRIME number instead off ODD (realized when i saw the solutions from others), but somehow i passed the tests hahahahahahaha so don't trust my solution
https://www.codewars.com/kumite/6644cffce862e0c537554b7f
Python fork with negative test cases (author inactive)
Looks good, thanks.
Lua translation! (author inactive)
This comment has been hidden.
I USED BRO I LOVE YOU
I used a Set, not the same way you did though
had so much fun doing this in C.
This comment has been hidden.
You are most probably doing some mistake somewhere, and most probably you are running not exactly the same code on CW and locally.
It gives this error:
error[E0432]: unresolved import
super::find_odd
--> src/lib.rs:25:9 | 25 | use super::find_odd; | ^^^^^^^^^^^^^^^ nofind_odd
in the rootFor more information about this error, try
rustc --explain E0432
. error: could not compilechallenge
due to previous errorNOTE: Line numbers in error messages can be incorrect due to concatenation.
Did you change the name of the solution function? Your solution should be named
find_odd
, did you change this?Oh yeah, I changed the name of the function, it was not find_odd()
there is no way this is a level 6 question
I came here to post the same thing. Agreed.
Same
fr
me has solucionado la vida, muchas gracias
Easy with LinQ in C# solution.
how?
This comment has been hidden.
This comment has been hidden.
Hi, there is very little point in making a post like this. Because it has to be spoilered, it's useless to those that have not solved, and the solutions page is a place where people can see your method.
This comment has been hidden.
Hi, there is very little point in making a post like this. Because it has to be spoilered, it's useless to those that have not solved, and the solutions page is a place where people can see your method.
RISC-V Translation
This comment has been hidden.
Golang: I returned 1 as placeholder while developing, and it passes all the sample tests for some reason.
Should be fixed.
This comment has been hidden.
The mistake is in your code,
'7' !== 7
.Hey guys, how do i receive input. In intellij i would use a scanner but that seems to not work on here I cant seem to receive the test cases into my code
The input is the argument(s) of your function
Ok that makes sense. Thanks.
This comment has been hidden.
invalid input. don't post solutions, whether partial or wrong, without spoiler tag.
thank you for the response. I would like to see additional tests for this kata that could eliminate wrong solutions
the input you used isn't valid, so it doesn't matter how the solution responds to it. you haven't shown it to be wrong. there's nothing to be fixed here.
Hi,
My resolution returns a coorect answer but somehow the test fails.
In the [7] I return 7 and the test fails saying
expect 1 to match 7 , when even in the examples given, the solution is, obviously , 7.
I want my kyu : )
read the error message carefully:
1
7
Not a kata
issue
... over 80K solvers have completed the kata in JavaScriptRead the description again, your code doesn't do what is asked there. It returns the number of repetitions, not the repeated number.
The number 0 is being classified as an odd number, which is incorrect. This is causing confusion in various calculations and processes where odd and even numbers are involved.
The description is very clear:
find the one that appears an odd number of times
. It's not at all about selecting odd or even numbers.Anyway, not a suggestion.
Actually, the code has to return the amount of times that a number appears. If amount be odd number, return number that mathces with the amount. For example, in the array [0], return 0 because appears only 1 time, that is a odd number.
This comment has been hidden.
one of the tests do not include an odd number but expects 5 as the anwser.
Not true. Your code is wrong. Read the description again. Not a kata issue.
This comment has been hidden.
that sounds like their problem, not the kata's
Fair, I only mention it because of the comment under me.
The description is
you forgot
the problem isn't clear
The description tells you exactly what you need to do.
This comment has been hidden.
your issue report is not helpful. you do not specify what "seem to fail" means. please provide the input, expected and actual values, and explain why you think the expected value is wrong. I'm closing as there are 3,000+ Go completions, so an error in tests is unlikely.
This comment has been hidden.
That's not the input of a single test, that's the input of two or more together, see the sample tests. Not a kata issue.
Do you still need help? I can try.
thanks but I got how to make it. I just needed to separate array output after each method call
Hi there, I am new to coding.....,like totally new but have special interests in Python and SQL. Where and how do I begin because I don't have a single clue. Somebody help!!!!!!!!!!!!!
Hi. Self-taught, advanced beginner here. I started with a couple of college electives that got me going. I know that's not an option for everyone. From there, I did Codeacademy. There are some really good, free classes on there to get you started with syntax. My next step that I've finally decided to take will be a boot camp next month. But, what I mentioned previously helped me start out so much. For sure, dabble with a couple of those free classes. Good luck!
You should definitely not start here lmao
This comment has been hidden.
Hello, if u code on Java, u needs import library, on upper line maine class.
That depends on Ruby's version. It requires 2.7 or higher while this kata only has 2.5 enabled.
Thank you!
Enabled MRI 3.0.0, you could try again now.
Interesting kata, maps for u help!
solved the problem for 2 days, trying to find a number that occurs not only an odd number of times, but also more often among others of the same
I think the function of the tuple which is named count is the best solution.
it's too easy for 6 kata...
Arrays.sort() not supported?
You forgot some
import
This comment has been hidden.
This code most probably does not compile in your IDE, and the code which compiles in your IDE is not exactly this code.
Please use code formattign blocks when posting code next time.
This comment has been hidden.
Agreed!
And if there are several such numbers, which are contained in the list an odd number of times?
From kata description:
This comment has been hidden.
... but its you who added a call with an empty array into your solution?
Tests should not pass in empty arrays. Did you have such problem also before you added the call with empty array into your code?
I've added a check for the incoming array to see if it was empty. (Like this: "if (...arr.length !== 0)"). And yes: the result of the test before I added this check was the same.
The fixed test your code isn't passing is this:
And the input is not an empty array. The javascript tests never pass an empty array to the function.
Thank you. But at 1st comment I've just copied the output.
dont think too hard about the solution.
probably the easiest 6kyu... you'll come accross
This comment has been hidden.
C# version - sample test passed, but attempt test failed:
Expected: -1 But was: 0
There is no more information what is going wrong
Print the input to debug your code: https://docs.codewars.com/training/troubleshooting#print-input, not a kata issue. Your code is wrong by the way, 1 and 5 (and many more) are odd numbers and they're not divisible by 3.
Something funky appears to be going with the C# unit tests.
passing in this as the input paramater via the Console.WriteLine I used to get the output new[] { 1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1 } returns 10, but the unit test is reporting a -1 back. This happens for several unit tests. Anyone else getting this?
Yes I am getting this. When doing in IDE it returns the right value but when i submit and test it says failed
Good kata, feels more like a 7kyu though, but it's good
This comment has been hidden.
Your solution has a bug and it's not a kata issue.
What's the bug?
This comment has been hidden.
Approved
Some problem in the automatic test generation in javascript version, same code failed and passed in the next attemprs.
Tests in javascript are fine, this is no way of raising an issue. Please read this: https://docs.codewars.com/training/troubleshooting/
There is an error in c#, when passing a test with a return value of 5, "expected -1". However, when returning -1, "expected 5 Assert.AreEqual(5 , Kata.find_it ( new[] { 20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5 })); This is copied from the test.
Those are two different tests, your function fails the next test, not that one. Not a kata issue.
How look second test?
Read this: https://docs.codewars.com/training/troubleshooting#print-input
I am running to the same issue.
2 parameters received but instructions mention just one of them for C language
D translation
approved
Holy cow I overcomplicated the solution to this challenge lol
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
this was the most fun kata i have done in a while. a bit easy
"For the test line "20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5,1,1,2,-2,5,2,4,4,-1,-2,5" i receive: expected:<-1> but was:<5>. But there is odd number of <-1> and odd number of <5>.
That's the input of 2 tests together, not a kata issue.
C#
Method name should be
PascalCase
(Please refer to implementation of backward compatibility here )No random tests
This comment has been hidden.
Why are you trying to spoil the challenge for everyone?
Moreover there are different valid approaches.
This comment has been hidden.
You should write separate test cases. Bad practice.
My Answer: 466
This comment has been hidden.
Please use a spoiler flag when you post code and use markdown tags or it's unusable, see there: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
comp
?!You gave two different codes, the last you posted isn't a solution to the kata. How could we help you?
Hi, must have had a different code copied at the time as was doing a few of these! I have corrected this now, I tested again and it was getting the same result.
This comment has been hidden.
A suggestion is meant to be a suggestion to improve the kata, not hint to solve it. Don't give hints, users are supposed to solve the katas by themselves.
Okay I aplogize :)
This comment has been hidden.
I'd like to note the test's for c++ are simply untrue, there are multiple cases of odd numbers you have to find the first instance.
The C++ tests are true: the description is not talking about
odd numbers
... it's talking aboutnumbers that appears an odd number of times
.For the test 20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5, the correct answer is 5 because exists three (5), but the correct solution supposedly it is ( -1 ) but is not correct because there are only two
The test expects 5. Please don't raise issues so lightly, see the documentation: https://docs.codewars.com/training/troubleshooting/
That's the input of 2 tests together.
This comment has been hidden.
Please read this before opening an issue: https://docs.codewars.com/training/troubleshooting/
This kata has been solved more than tens of thousands of times in both Java and Javascript.
This comment has been hidden.
You can try to use
next
(read Python documentation about that) to get the first element from a generator. I advice you to try it and see, though I bet you will need to find a still more clever solution to actually pass all the tests ;)This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Hi. Please use a spoiler flag when you post code in a comment (I put the flag for you this time).
This comment has been hidden.
This comment has been hidden.
We do not know your code, co se cannot tel why it fails either. In any case, you could run your code in your local IDE and debug it locally, stepping through it line by line.
This comment has been hidden.
@Rabindra please don't spoil solutions, thanks.
@Rabindra
: please do not post spoilers. If you must post code, check theSpoiler
flag.The way the test module is set up is confusing. I'm writing a solution in the block for the given function with a parameter of 'A' and avoided changing anything that was already present that might disrupt the test. Without changing anything, and assuming 'A' to mean 'array', I'm writing what seems to be a workable solution, but then it doesn't recognize what 'A' even is and the test fails.. Has anyone else had this problem or know what I might be doing wrong?
You're writing your solution in the sample test area, or you're writing the solution in the solution area? The 'A' variable doesn't exist until it's passed into your function.
I guess I'm having trouble understanding what you're doing. When you write a function, you set the variable names for the values that are passed into your function. In javascript, it looks like this:
And then that function can be called from elsewhere. Like this:
In this example, when
3
,4
, and5
are passed to theblah
function, the code inside the function will recognize thata == 3
,b == 4
, andc == 5
However, if outside your function, you try to call on one of those variables, they won't exist. So if you try this outside of your function code:It won't print
3
to the console, it will printundefined
, becausea
doesn't exist outside of the function code.You shouldn't be writing in the sample text box unless you're trying to write your own tests. If you're just trying to come up with a solution, you should just stick to the solution box. The starter code looks like this:
Outside of the curly brackets of the function,
A
does not exist.Thanks for the quick and thorough reply! I'm quite new to this (also not sure why this reply text area looks like the coding input window.. I'll figure it out sooner or later). Anyhow, yes I'm writing my answer in the solution window and not for the tests, and regarding the reference to 'A', I'm assuming A stands for each of the given test arrays that are plugged into the funtion, so After changing all my references to 'A' in my solution code (as opposed to 'array') that problem seems to be mitigated, but now when I do this:
function findOdd(A) { for (let i = 0; i <= A.length; i++) //more code follows }
'i' comes up as undefined. I don't recall ever needing to declare 'i' when iterating through an array.. I tend to get stuck on the most rudimentary issues so this could be one of those times. Thanks for any insight you may have into this(!)
i
is coming up as undefined because you're probably trying to use it outside of yourfor
loop. While normally it's not a problem, by declaring it aslet i=0
in your loop construction, you are limiting the scope ofi
to just that loop.For example:
The above code will result in an error with
i
being undefined.This code will not:
The above will declare
i
as a global variable, which isn't the best thing to do, but the code will work.The best practice is probably to use
var
like the following:The above code will limit the scope of
i
to just this function. So, if you were to check the value ofi
outside of this function, it would be undefined.let i
- is block scoped. That is,i
will only exist inside the current block of code, and any blocks within that block.var i
- is function scoped.i
will only exist inside the function in which it is declared.Note that
A[A.length]
is undefined too.I only just started and it's already so difficult for me ㅠㅠ
Start with white katas, 8 and 7kyu.
How do I choose what katas to do? I'm very new and everything is confusing to me sorry.
Check this: https://docs.codewars.com/getting-started/finding-kata
Thank you, this helped a lot!
I've solved questions in 7 and 8 kyu that were harder than this... Or maybe it's just C doing its job being an easy language sunglasses
COBOL translation.
Approved
JS, Python, and probably others: negative numbers are only tested in fixed tests.
Is there any solution that doesn't work with negative numbers and hardcode fixed tests to pass?
I don't know, and that's not important. Tests should generate positive or negative numbers in random tests too, that should be easy to fix.
https://www.codewars.com/kumite/6644cffce862e0c537554b7f
Python fork with negative test cases
Ok for Python.
Fixed in Ruby
This comment has been hidden.
Late answer, sorry. Hope you're still up for the challenge! The problem is that the compiler doesn't know if inside of the foreach something will be returned, so you'd just need to return anything after the foreach, or throw an exception. Then your code should compile
I found this challenge worth the time. It was not too easy but not too hard either. It however required some amount of creative thinking.
Too easy shouldn't be 6kyu maybe 7kyu
This comment has been hidden.
Sorting is in average O(n log n). Please don't post solutions in Discourse, use Solutions section for this, and even there, mark your post as having spoiler content, about markdown formatting, read this: https://docs.codewars.com/references/markdown/#code-block
I am passing all the test cases but when I click Attempt it fails because of -1 and I am not sure what the combination could be that is making it fail
Question
Print the input
This comment has been hidden.
1 occurs only 2 times (just like -1), and the expected answer is 5, not -1. (it's even shown in sample tests)
You're seeing the input of two different tests together: { 20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5 } and { 1,1,2,-2,5,2,4,4,-1,-2,5 }
Why no tests with something like 10-100 millions elements in sequence, with time measurement? I think, then most of solutions marked as 'best practice' and 'clever' just fucked up while testing! :))))
Too late to enforce!
I'm not sure that cata translations like this should exists.
This cata teaches to write partial functions in cases in which it is not nessesary. Strongly unrecommend.
It's not haskell way :|
This comment has been hidden.
use question tag to ask for help
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
C translation (author inactive)
approved, despite the downvoters ^w^
There is a small spelling error:
"[1,2,2,3,3,3,4,3,3,3,2,2,1] shold return 4, because it appears 1 time (which is odd)."
It should be should not shold ;)
corrected !
This comment has been hidden.
This comment has been hidden.
Your problem should be very easy to reproduce. Did you try to debug your solution in your local IDE?
Additionally, some remarks:
I don't understand what we are supposed to return. Do we return the value of the integer that appears an odd number of times? Or do we return the number of times the odd integer appeared? This kata is very unclear.
You need to return the value of the integer that appears an odd number of times.
That's very clear to me. And you can look at the sample tests:
5 appears 3 times, and the expected answer is 5, so, it's the integer, not the times it appears.
This comment has been hidden.
Well, for [18, 1, 7, 1, 1, 1, 18, 18, 7], 18 occurs 3 times (odd number). The other array seems impossible, unless you're modifying the input. (but if so, 3 occurs 7 times, so it's a valid answer)
well, looks like it is my mistake. I did not understood correctly the word odd
Wow, I actually thought my solution was decently short lol. Seems to be a pattern
i dont get any fail at the current tests but i am getting fails with random tests and number of fails is not constant with same solution
This comment has been hidden.
What if there is only 1 occurance of number -1 ? Your code wouldn't catch it, but it's valid.
I know I was missing something simple, thank you so much!
This comment has been hidden.
Please discuss solutions in Solutions, I'm sure there is already explained what it is and how it works, top solution, 3rd post.
OMG I translate odd as strange and wrote a program that finds a number with an unusual pattern. Be careful comrades
This comment has been hidden.
Please read this again: https://docs.codewars.com/training/troubleshooting#post-discourse
Especially the third bullet point, which states:
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
Thanks!
Hi! Using JavaScript.
Could someone point me in the right direction of what to research? I tried for loop within a for loop, but ended up with an if statement within an if statment after that, and there must be a simpler way.
Tried to look it up but I don't want to copy and paste an answer, so if someone can give me the first 'breadcrumb' so I can follow the trail, I would really appreciate it!
This comment has been hidden.
Awsome ideia! Thanks man
Nice kata but I don't think it's 6 kyu.
ranks cannot be changed
This comment has been hidden.
This comment has been hidden.
Don't use global vars, they keep their values between tests. That's a problem with your code, not a kata issue.
ooohhhh, thx lol. Thanks for the info
The instruction clearly states that "There will always be only one integer that appears an odd number of times" then why some random tests return undefined? In order to reproduce the issue I tried something like this: doTest([874, 874, 874, 874, 974, 999, 999, 999, 999, 888], 974) with 2 odd integers and guess what? That returned undefined. All sample tests and some of the randoms like doTest([874, 874, 874, 874, 974, 999, 999, 999, 999], 974) and doTest([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5], 5) go fine. Language: JavaScript
Given how the random tests are written, what you say is not possible. Returning
undefined
is an easy and fast way to check no random test expects that.I do not understand. Using the reducer also did not pass random tests. When iterating over with a simple for, everything worked.
if you make the mistake of return the value and not the key of the map, the normal test pass ok but the random test fails.
C#: Test is passing but erroring out on submission, Kata class has no object instance.
Just solved the kata in C# and it seems to work OK.
Did you modify solution setup in any way? Please see if this FAQ helps: https://docs.codewars.com/training/troubleshooting
Thanks! Was using a different LINQ method in my implementation causing the object to be null. I was able to complete it now.
This comment has been hidden.
Please don't post solutions in Discourse.
I did not realize it was a pre discussion.
I can't seem to be able to delete it though.
Don't worry, discuss solutions in Solutions next time, and even there, mark your post as having spoiler content when needed, otherwise your posts there are also shown in the home page.
About your question, if you only need to return the single number that appears an odd number of times, why do you need the other function?
This comment has been hidden.
I wanted to be able to detect multiple odd or even numbers for fun. I solved the challenge differently but was curious how you would implement a function for multiple odd or even cases if you pass in an array.
This comment has been hidden.
I'm not familiar with Dictionaries so I'm not sure how the code works. But it doesn't seem to work correctly.
if I input allWhat([2, 1, 6, 7], 'odd'); it will return [1, 2, 6, 7]
Well, those numbers appear only 1 time. And you wanted to list all numbers that appear an odd number of times, so, it works as expected.
You're right. I confused my code by mistake.
This comment has been hidden.
From description:
It would be good to introduce tests of very large inputs, to encourage users to aim for more efficient solutions.
based on the instructions, I understood: whole array in, processed array out.
But in fact the it is whole array in and then integer by integer out. Odd.
umm.. i got it right pretty quickly but the submit button is only letting me attempt? weird
this one was actually rather funny, i had the answer in the first attempt, but something looked weird, so instead of testing, i refactored. I lost 50 minutes trying to figure out what was wrong, when i had the answer all along
Ruby 3.0 should be enabled.
Done.
This comment has been hidden.
Not a kata suggestion and please don't post solutions in Discourse.
Oh, my bad Chrono, I'm new here,joined today, wasn't aware of a seperate solutions section
No problem, take a look at the Docs: https://docs.codewars.com/ there are some guidelines there and some FAQs with their answers that'll be helpful.
so hard)
This is some basic "double for iteration" problem, really useful for a lot of things.
This comment has been hidden.
Please don't post solutions in Discourse, it's not for that.
ok
Hello, I am in need of some hints. I tried to solve this kata by bilding dictionaries, but failed. so, my question is there a way to solve this using only lists or sets, and not using dictionaries at all. Thanks for reading. Any hints will be welcomed.
You can solve it using any of those. What you should probably be doing though is to think about how you would solve it yourself as a human being. Then write your program to do the same actions.
Thank for usingful reply with hints. One ohter thing I forgot to mention that I am trying to solve this kata in Python. Next time I will go with your suggestion.
Thank you, natan(2 kyu). I followed your advice and solved it.
This one took me time than I care to admit, but at the and I was able to solve it without looking for external help such as Stack Overflow. Btw, I noticed something weird in Java, when you do modulo of a number with itself (for example 2 & 2), the answer is not 0, but rather the number you started with. So if you do 7 & 7, Java interprets it as a 7 instead of a 0. This messed up my program and I didn't realize it was the problem, cause I assumed Java would know it's 0? Why does this happen?
This comment has been hidden.
should be 7 or 8 kyu
I agree
even 9kyu if it existed
Yeah I'm pretty sure we already have something exactly like this on 7th or 8th.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
That's a question, not a kata issue. Print the input, see why your code fails.
Sorry, i singed up yesterday, don't know rules yet. I printed it, but still, everything seems fine to me.
Oh, got it
This comment has been hidden.
Have you imported it?
import java.util.HashMap; // import the HashMap class
That was it. Thanks. I guess I figured that was already taken care of under the hood.
Can anyone give me an example? like what input and output should look like?
few examples : [1,2,1,5,2] -> 5 [4,4,4,5,1,1,10,2,5,10,2] -> 4 [9,0,-1,0,9,8,8,9,10,9,10,10,10] -> -1 Basically, input array would always have ONLY ONE integer with ODD number of occurences and every other integer in array(if any) would always occur EVEN number of times. You are asked to find the integer that occurs ODD number of times.
Hi, im very new at this, can i ask why the code for the function provided in the code box has "return None", my understanding of the question is that i am to return the integer value that only appears an odd number of times in the arrays. I've previously been advised that the None value is effectively an object with no value, are we to assign a value to None in some way? Sorry if the question seems kind of stupid :(
This line is there just so the solution compiles and tests can be run. Your task is to modify it, if necessary. You can see it as something like:
If you think that
return None
is not what should be there, just remove or modify it. The only thing which has to stay unchanged is the function declaration (its name and arguments).Ah ok thanks for clarifying that :)
I Think this task is easier than 6kyu.
This comment has been hidden.
HI maxwell150, first: don't post code without the spoiler tag, (others can see it). Next: it's not a kata issue if your code is not working. Finally, you need to return the value, not print it.
So, im not sure whats wrong here, the code works on Replit when i copy the test arrays however it only works for 18 and fails for 27 on here, what kind of things should i be looking out for that could be wrong?
Read the error messages and compare them to input / output. Also, here's some documentation on troubleshooting.
why the answer is so weird? isn't the question ask to count the odd number?
Please read the description properly before asking questions.
So number can be odd or even.
This comment has been hidden.
Your functions should return the result, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
This comment has been hidden.
Please don't post spoilers like that.
sorry
I'm sorry, but why do people go to discuss section of a question then before solving the problem? Literally every coding website ever.
roopali1710, think for a while you're going to a movie theater, and the people next to you is talking about how the movie ends, would you like that? I don't know how other coding websites work, but here solutions should be discussed in Solutions, not in Discourse. About what Discourse is for, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#post-discourse
Discourse is basically for:
Discourse is not for:
This comment has been hidden.
No, that's not what the kata asks, the number can be even or odd (it doesn't matter) what needs to be odd is the number of times it appears in the array.
olá, não entendi a questão, devo criar uma array e depois indentificar um numero impar dentro desse array? é so o primeiro numero impar que devo encontrar ou todos que tiverem? se alguem puder me esclarecer eu agradeço
This comment has been hidden.
I could not understand well what he was asking me to do
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
See the last bullet point of this paragraph. Not a kata issue.
This comment has been hidden.
Hi, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution This is not a kata issue, it's a question (use the proper label please). What is
int
and thereforen
in your code?oops! I'm sorry about the wrong label on the comment. I wanted to tell the programm to look for an [int] called [n] in the [seq] I'm struggling to find a way to tell the programm to look for the number within the seq. Thanks @chrono79 for the link to troubleshooting
Can anybody please tell me how can I post solutions here?
Swift translation. Please check and approve
Approved
This comment has been hidden.
lolllllllllllllll if you use python then this kata is like 100 kyu difficulty
i completely agree!
How so? I just did it with 4 lines.
This comment has been hidden.
Groovy translation kumited. Please review and approve. Regards, suic
Approved some time agoo
Pascal translation. Please review its comment and approve.
This comment has been hidden.
Not a suggestion.
If only there was anything worth copying in there...
This comment has been hidden.
This comment has been hidden.
Closing as it's been answered. If you still don't get it, post a reply saying that.
This comment has been hidden.
This comment has been hidden.
Why can't I use vector::size() property? Like i<numbers.size() is not working.
This comment has been hidden.
First statement is correct - return the value
My code have a set.
This comment has been hidden.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#when-i-print-my-answer-it-looks-exactly-the-same-as-the-expected-output-yet-tests-fail
Return instead of printing the result.
Last bullet point in this paragraph of FAQ probably describes your problem : https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#expected-the-same
Okay that worked but I still get an error that says "None should equal -1" nevermind i solved it
I'm completely lost in this exercise. Can somebody help me?
Can you elaborate a bit more on what sort of help you're after? Do you need clarification on what you're being asked to do, or do you know what you need to do but not how to do in your language of choice?
Hello. Thank you for your answer. I know what I have to do, but I don't know how to do it. I don't know what to write. Also, I need an explanation after every code written so I can understand it better. I am having a hard time understanding arrays with loops. My language is Java.
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in Discourse.
i'm sorry, my bad
This comment has been hidden.
Why do you post your solution here?
This comment has been hidden.
Your solution is incorrect, it returns wrong answers for inputs like
[1, 2, 1]
. Debug through it locally to find your mistake.Not a kata issue.
This comment has been hidden.
This comment has been hidden.
this is not a suggestion ... ?
Hi everyone. When I run the code in my IDE(Qt) it shows the correct output, but when I run the code here, I get different output. Does someone encountered similar problem?
Just checked the C++ version, it seems to be OK. You probably have some mistake in your solution.
@TheCoder99
: Are you actually trolling? You keep posting questions and issues, which I answered and you just keep posting new ones without looking at the replies.Because you didn´t replay anything that could solve the problem
The Question is how can the code has mistakes when it runs correctly in Qt with the same array as input as in example.
Well, I'm not gonna give you the solution... I told you where to look at (spoiler: I fixed it and solved it with your code). There are random tests with random arrays so it's likely that you're not using the same inputs.
And by the way, there is a thread open already, so you should reply to it, not spam the whole thread with more posts. But if you're just gonna keep downvoting people trying to help you, well... good luck on your own.
It's difficult to tell why your code is wrong without seeing it. My crystal ball got broken, sorry. Nonetheless, your code would pass the tests if it were correct, and if it does not pass, it menas it's not correct. The fact that it works for you locally is a good sign, but still not enough.
Same here - I ran it in Visual Studio and got 5.
I am unable to se the example input & outputs
This comment has been hidden.
Please use code formatting as shown here https://github.com/Codewars/codewars.com/wiki/Markdown-Formatting#block-code-formatting when posting code, otherwise it's difficult to read.
Your loops are both set up incorrectly and are checking either too much or too little.
i might need some help
This comment has been hidden.
try doing some level 8 kyu katas first
This comment has been hidden.
In this example:
10 appears odd amount of times, so it's the answer.
About assertions, it depends on the language you are attempting. For some, like Java or C#, these are standard unit test libraries, like NUnit or JUnit, you just add reference to your project and you are good to go. For others, like Python, getting the test framework to work locally is a real PITA.
This comment has been hidden.
I'm using the .keys() and .values() functions, idk if it's correct but it keeps giving me an attribute error. Is there a way to fix this?
How can we know if the problem can be fixed if you don't know what you're doing?
This comment has been hidden.
This comment has been hidden.
Write min and max values next time...
I suspect something may be wrong with the test code in golang. I used a fmt.Printf to show the array for each test, and it was always the same (the last) test array, even though the test prints out each different test. That is, the input was always [5 4 3 2 1 5 4 3 2 10 10] even though it looked like it was different from what the test code printed out.
This comment has been hidden.
This comment has been hidden.
Not a kata issue, an odd number is a number that is not a multiple of two.
Use
Question
label next time for things like this.this problem can be solved not O(n^2)?
There's multiple O(n) solutions. The standard approach uses O(n) space. If you know the trick, you can use O(1) space.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You're evaluating the count of the last number of the array like that.
This comment has been hidden.
I'm surprised it doesn't crash. You've got a "fence-post error" in allocating the size of array a[]. If you have the numbers 1,2,3 ... this code allocates an array of size 2... not size 3.
Second, if the number is negative, you go outside the array bounds. When your code sees -1, it performs a[-1]++ which increments some value outside the array. Given a lot of negative numbers, your code would randomly corrupt memory, which is why I'm surprised it didn't crash.
This comment has been hidden.
This comment has been hidden.
Fascinating. Thank you!
This comment has been hidden.
Read this. Your code is returning a string and a number is expected. Mark your post as having spoiler content when posting code like this next time too.
This comment has been hidden.
Read this
I'm getting the right solution outside of codewars. Can't figure why I'm not having the same result inside codewars :(
return
notprint
the result because print displays it to the console and return actually returns a value.Thank you! :D
no need to use dictionary, use lists instead
This comment has been hidden.
maybe its indent level issues?
We can't tell without seeing your code, so post it with proper markdown and a spoiler tag, someone may be able to help you.
hey, I want to ask, does this second test case is correct ? Becasue it is a bit strange for me that second test case returns -1 instead of 1 or 5. Language : C# second test output:
1 2 2 2 -2 2 5 2 4 2 -1 1
Not a kata issue, print the input,
Console.WriteLine(string.Join(" ", seq) + "\n");
The tests are ok. And maybe you're misunderstanding what to do too:If the second number you showed there is the amount of the number at the left, then you can see the number "that appears an odd number of times" is -1, not 1 nor 5.
Thank you! :)
In JS and TS I assume that it should work for the whole range represented by number so I would include testcase containing a number larger than 2147483647 (Math.pow(2,31) - 1) ie.
doTest([2147483648, 1, 1, 2, 2, 2, 2], 2147483648)
Really nice problem. Cup of coffee + this on a saturday evening. . .
Fave Kata so far. Thanks so much!
the second test doesn't work in python. The test assert shown has the wrong answer in it.
The tests in Python are ok, so you're misreading the logs or the instructions.
well, turns out I am misreading the instructions. i wasn't counting the right thing, thank you.
Hello, coders! Unfortunately, I cant find the error in my code myself. Can anyone help with the problem?
def find_it(seq): cnt = 0 R = 0 seq = sorted(seq) if len(seq) > 1:
This comment has been hidden.
It seems that each there is a problem when executing in here, my code works on my laptop, but here test results have lag(each result test shows next true answer!!)
That can't happen. You're misunderstanding something.
每次看见你们的解答我就好羞耻,odd number 我以为是奇怪的数字,做了3个小时。。。。。。。。。
What does it mean? Is it Arabic or Japanese?
It is Chinese. He thought "Odd" means "Strange" here.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Use spoiler flag next time.
sorry im new to this platform didnt know that will keep in mind :)