Ranajoy Saha wrote:
I followed Junlu's tests, and thus handling all the test cases made this program. But I am desperate to know, if this problem could have been solved without using an for loop, or if there is some other approach that one could take.
And the function signature that must be stuck to is "public boolean array220(int[] nums, int index) ".
Campbell Ritchie wrote:Why have you got all those ifs?
All things are lawful, but not all things are profitable.
Ranajoy Saha wrote:Given an array of ints, compute recursively if the array contains somewhere a value followed in the array by that value times 10.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ranajoy Saha wrote:Is it not ""followed anywhere by" in the array? If it's "followed immediately by" then the base case will be simple if(index == nums.length-1) return false, but what if it's "followed anywhere by" in the array. What should be the approach then?
Ranajoy Saha wrote:if(index == nums.length-1) return false
About the base case think as about the simplest possible case/-s.Ranajoy Saha wrote:Is it not ""followed anywhere by" in the array? If it's "followed immediately by" then the base case will be simple if(index == nums.length-1) return false, but what if it's "followed anywhere by" in the array. What should be the approach then?
That part is wrong, it can be true.
Ranajoy Saha wrote:Here's the working code.
Ranajoy Saha wrote:The fixed code. Thanks for the suggestion Liutauras Vilda, implemented those in the code.
... Refactored the code as well
Ranajoy Saha wrote:Now please tell me what if, instead of "followed immediately by"" in the array if it's followed anywhere by" in the array. What should be the approach then? Is there any different approach other than my first posted approach?
Junilu Lacar wrote:Winston, based on the examples given, I would say it means "followed immediately by..."
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:ie: bad (or maybe really good) test set.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Only small hint:Ranajoy Saha wrote:Now please tell me what if, instead of "followed immediately by"" in the array if it's followed anywhere by" in the array. What should be the approach then? Is there any different approach other than my first posted approach?
Liutauras Vilda wrote:
Only small hint:Ranajoy Saha wrote:Now please tell me what if, instead of "followed immediately by"" in the array if it's followed anywhere by" in the array. What should be the approach then? Is there any different approach other than my first posted approach?
You'll need another signature, with 2 indices and 2 recursive calls.
Winston Gutkowski wrote:So how does TDD make sure that the tests completely convey intent?
I tried the coding bat example and there is no hint of a test like that. I think it should return false and coding bat have forgotten to include that test.Winston Gutkowski wrote:. . . I'm afraid that requirement is ambiguous. Specifically, what should:
array220([3, 5, 30, 4], 0)
return? . . .
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |