sai rama krishna

Ranch Hand
+ Follow
since May 29, 2009
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sai rama krishna

I am working on below challenge

Given an array of ints, compute recursively if the array contains a 6. We'll use the convention of considering only the part of the array that begins at the given index. In this way, a recursive call can pass index+1 to move down the array. The initial call will pass in index as 0.

array6([1, 6, 4], 0) → true
array6([1, 4], 0) → false
array6([6], 0) → true

I was not clear on this description. Is it saying array contains 6 then return true if that is case what is purpose of index. I see few other challeges similar to this like next challenge to this as well. Can you help me understand this better so that i can move further
10 months ago
Thank you

I see some other interesting operators as below in that link which i never used or saw

(one of)
=  *=  /=  %=  +=  -=  <<=  >>=  >>>=  &=  ^=  |=

10 months ago
once added limit it worked with for loop also

i am not that used using more than one indexes. can we do this with just one index instead of 2 indexes(one to iterate given input index to check each element, other to put elements into result array to display finally)?
10 months ago

Above is working with while loop

I could not make my original for loop approach to work yet though. I am checking on that limit as well in for loop
10 months ago
Thank you Paul.

"a &= b" is the same as "a = a & b" right not a && b? This is first time I ever saw this expression. Is it in new edition of java or i just never got chance to look earlier i saw others like you mention more often a+=b and a-=b  and a*=b and a/=b

Gaurd clause is same as edge case? I hear people calling edge case for similar check at the beginning of method.

Regarding other question if number of lines of code in a method more than 10 lines say 15 lines if i use multiple returns what is the downside or disadvantage of it? As most of my challenges I used returns liberally without thinking about this type rule.

10 months ago
Thank you Ritchie, Lacar

I have some follow up questions after reading above 2 comments

I never saw &= operator. What this represent?

If number of lines more if we put more return statements visibility is lost right?

What is meaning of guard clauses? Can you please give some simple example for that?
10 months ago
Looks interesting.  I will take some time to digest above code.

Is it bad thing to have multiple returns?

Can I use for loop instead of while loop here?

can I use for loop interchangeably wherever while is used or there are any restrictions for for loop? I got used to for loop more than while loop
10 months ago
Below finally worked

It passed all tests

x is the new assigned number of n which used for chop off and while loop
digit is reminder digit
I have to check n reminder by dividing with digit and chop off that x to get new digit every time in the for loop
10 months ago
I agree. I debugged in eclipse and changed < condition to be less than n not the length of array and it worked fine as below

10 months ago
I agree. Lesson learnt Never test further when found required result

If 1, 2, 3 comes in random positions my solution will not work. May be I need one other for loop. I have to try that test scenario
10 months ago

Above refactored code failing some reason one test

whereas below further refactored code passing all tests

Looks like refactored code 1 is checking whole array which is not right approach for this challenge.
Refactored code 2 check part of array and as soon as finds 1,2, 3 next to each other returns true and program exited
10 months ago
Very interesting old sun link. Thank you for sharing.

I mean to say below code passed all tests

Like you mentioned let me refactor to remove those if else statements as well
10 months ago
Thank you. I agree with all above points. When I am using eclipse I am using debugger and sometimes system.out.println statements
10 months ago
I did not think about less than 0 scenario. Also did not pay much attention to 0 case as that was given in test case. I was focusing more on description.  Whatever challenges i wrote last night in codingbat were not registered not sure some issue going on with website currently
10 months ago

Definitely. Trying to understand how recursion works instead of loops. Above worked. Looks like I cannot take base case of bunnies==1 but only bunnies==0 and then keep adding 2 with recursion call of bunnies-1
10 months ago