6 kyu
Longest Strict Bouncy Subarray
183 of 584raulbc777
Loading description...
Performance
Algorithms
Mathematics
Data Structures
Arrays
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.
Julia translation
Appoved! Thanks
python new test framework + a faster ref. solution is required. updated in this fork
Approved!
Really interesting coding challenge, I wish I could optimize it.
Please review: C++ Translation
The definition of bouncy is not making sense to me. Can someone articulate it differently and see if it clicks. I can't see the rule that's determining the subarrays. Here is the closest I can get at what the definition means: FOR A GIVEN ELEMENT: # it MUST be HIGHER than one neighbor AND lower than another neighbor
please help.
No, draw the example as a bar chart, the first number is 7, the next one is 9 (higher than 7), the next one is 6 (lower than 9), and so on. They alternate between higher and lower. So for a given element, except for the ones at each end, the numbers immediatly before and after are both higher or lower than the number itself.
sweet! solved. thanks :)
Just solved this Kata. I think it should be 5 Kyu imho.
D translation
Approved +1
Rust translation
Approved +1
This note should be removed.
Done!
I could not understand the details of this kata. Could you please define it more clearly?
A "bouncy array" is an array where every element is either greater than each of its neigbors, or less than each of its neighbors, e.g.:
[9, 0, 8, 1, 7]
is bouncy because9 > 0 < 8 > 1 < 7
[1, 2, 3]
is NOT bouncy because1 < 2 < 3
[1, 1]
is NOT bouncy because1 == 1
Given an array, you have to find the longest subarray which has this "bouncy" property.
Nice effort on the Ruby test suite, that isn't going to be fun to translate.
My Ruby solution is ugly, but decently fast so I guess that counts for something.
Java typo :
longuestBouncyList
->longestBouncyList
Thanks for the feedback!
done
Thanks B4B for your quick answer
Having problems with this kata (in Java) and I'm not sure what I'm doing wrong. My current solution passes the provided sample tests, but doesn't pass the "Attempt" tests. For example, I got the following for one of the random tests:
Test for: [-4, -1, 10, 8, 9, -2, 3, 1, 1, -7, -2, -10] of length 12. Result ----> [1, -7, -2]
expected:<[1, -7, -2]> but was:<[-1, 10, 8, 9, -2, 3, 1]>
The array I returned appears to be strictly bouncy and longer than the expected result. Is this array not bouncy? Am I misunderstanding what's expected? Or is it something with the kata?
Thanks for your time!
Hi @ccgrover. Yes,
[-1, 10, 8, 9, -2, 3, 1]
is bouncy and is longer than[1, -7, -2]
. The translator, @Blind4Basics will answer you soon.Awesome, thanks for the speedy reply!
Hi,
I didn't see your message until now, sorry. Issue confirmed, and solved. That should be good, now. Sorry about that... :/ (a dirty seek&replace that became somewhat "wild"...)
No worries. Many thanks for addressing the problem!
Java translation, please review and approve.
Note that I saw you put a "performances" tag on your kata, though the tests doesn't seem that demanding in python. So implementing the same ones in java, the execution is crazy fast (note: java has an additional compilation time, on cw. About 2s...). So tell me if I have to make the tests harder and if so, to what point? What is the kind of implementations you wanna forbid?
This comment has been hidden.
no problem to me to push further. If you can provide the code you used in python (for this test up to 10s), I'll do the equivalence with java after. Could you post the exact test suite in a fork of my solution, please?
This comment has been hidden.
done. But I had to push the things crazy hard to obtain the same kind of timings in java.. x) (10 times the number of tests for each batch, but 5000 loops for the big one xo )
This comment has been hidden.
Yes, an update of the description might be a good idea. I didn't completely go through the generation process of the random arrays (just converted it to python without much thinking) so I'm not sure about the actual caracteristics of the inputs, but just look at the tests, they are written in the very same manner than yours, so you should be able to identify the actual constraints without any problem.
Note: don't mark as spoiler all your messages, especially if there is nothing sensible in them: CW doesn't send any notifications for flagged messages (already with unflagged, the notifications are wuite random... :/ )
Any aditional suggestion for the details?
Waiting for the first user solving it in Java :)
Mmmmh... either give the detail of the tests suites in both languages or not at all. Currently, something will sound really weird: there are currently 2800 tests in java... Against the 85 of python x/ That difference sounds unreasonable.
Hi,
Warning, you misplaced the
Test.it
statements: you have to put the call of the user's function in between theTest.it
and thetest.assert_equals
statements. If not, the infos the user prints to the console (if he does) are displayed before the "opening" of thetest.it
section.Oh thanks. Let me check
Let`s see now
This comment has been hidden.
it's an alias, for
test
, that doesn't change anything. ;)all good.