How to get middle element of array if we don't know size of array -


i asked question in interview ,write algorithm find middle element of array when don't know size of array.

is cheating count elements yourself?

java:

object [] mysteriousarray = getmysteriousarray(); int count = 0; (object value: mysteriousarray) {     count++; } object middle = mysteriousarray[count/2]; 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -