We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
What exactly do you mean by "Initializing an array with -1"? Do you mean arr[0] = -1? Or perhaps for (int i = 0; i < c.length; i++) arr[i] = -1?
Also, since M - arr[i] is not an index I wouldn't know why to check if that is bigger than 0. Perhaps you meant that we should find the index of arr such that arr[index] = M - arr[i] && index >= 0 where i is your loop iterator.
It seems to me like this algorithm is O(n^2) though. You iterate over arr with loop iterator i and then iterate over arr again with loop iterator index.
What are my misunderstandings here?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
What exactly do you mean by "Initializing an array with -1"? Do you mean
arr[0] = -1
? Or perhapsfor (int i = 0; i < c.length; i++) arr[i] = -1
?Also, since
M - arr[i]
is not an index I wouldn't know why to check if that is bigger than 0. Perhaps you meant that we should find the index ofarr
such thatarr[index] = M - arr[i] && index >= 0
wherei
is your loop iterator.It seems to me like this algorithm is O(n^2) though. You iterate over
arr
with loop iteratori
and then iterate overarr
again with loop iteratorindex
.What are my misunderstandings here?