What is wrong with my code ? I am not getting correct answer !! Check this : https://ide.codingblocks.com/s/181254
Doubt in Coding Question MIN QUERY
Hey.
In build tree function return the value that is inserted
public static void buildTree(long ar[], long segTree[] ,int s ,int e , int index)
{
//base case
if(s==e)
{
segTree[index] = ar[s];
//return ;
}
int mid = (s+e)/2;
buildTree(ar,segTree,s,mid,2index);
buildTree(ar,segTree,mid+1,e,2index+1);
segTree[index] = Math.min(segTree[2index],segTree[2index+1]);
//return ;
}
take back values in the buildTree because u are computing segTree[2*index] but no value is being sent to it
Return value from the function so that min of two values can be taken into segTree[index]
return value from the function
Here is the updated code which works well for all the test cases.
In case of doubts in any section fell free to clear them