#solved
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Double equals to also let's you compare two vals
Ah logic
What have you came up with already?
can you give some more context
what is your initial goal?
see how many elements of the same type are in that array?
...
so many possibilities
I think they wanna compare with neighbors maybe?
too many possibilities to guess here
Right so neighbors, what's your approach so far?
Not code wise just in general, like brief me in English.
hmm so you are headed to the right direction, think about the array values. Do you know how to access array elements?
right now think about the index, is there a way that somehow we can get both neighboring values?
yeah
you now still need to consider what happens if index = 0 and index is at the last element
and you also dont need to check if they are equals but instead greater/smaller
also its always nice to put seperate logic like that into () to avoid confusions, so (arr[2]==arr[2+1]) && (arr[2]==arr[2-1]), looks much better.
and you need to split the if
nah I mean what happens if you are at index 0 and want to check the element left to it?
do a dry run for a smaller array if you're confused. Take this [1 2 3]
there is no element left to it
and you calculation would give index - 1 for the element left of it
and if index is 0 then you get -1 as the result which is not a valid index
same with the last element
there is no element to the right of it
so your calculation gives you an invalid index
you need to consider that
you dont need to worry, its an edge case. You make mistakes and then come up with these cases. So always do a dry run for inputs, see how it goes.
you can compare indexes, but i dont understand what's the end goal here? You look at first element checkout its right element based on that you print result and then you move to next one and so on. I see that you used "2" + " " to add some space between. You could make a result StringBuilder, add your ans to it for each one and print it at the end.
is this an assignment ?why do you need to check for left and right ?
the wording is weird, first there are several typos like "to it's left" ? and most importantly, "then one of the buildings to it's left", there are several buildings to its left that you have to compare to ?
you have to think of conditions carefully, if its greater than "both" you give 2 points. If its greater than "either" you give 1 point. If its smaller than left "and" right you give 0 points.
right both the end values will have seperate conditions, rest all the indexes will have same conditions. So handle th first element, then rest of the values an at the last you want to do end value. The order is important.
i > 0 ?
you dont need to check for equal i think, if its only greater or less.
oh wait, you should chekc if i==0 here not arr[i]==arr[0]
i is the index
that's how you check first and last elements
you limit your index aka i, inside for loop using conditions.
or you can have two if conditions inside the loop which will check if its first element or last
for last element => arr.length-1 is the index
do this one, forget the limiting loop conditions part for now.
wdym, it's not always true ?
shift, i think you're confused how arrays work. Index is the position inside array, arr[index] is the actual value.
index always start from 0 in java
Closed the thread.