@amish19 i don’t know is there any mathematical soln is present or not,but the best way you can use is binary search,let assume that 1st container will have water level at 1 as we have to maximize K so now we will binary search over answer to find the maximum value of K,Now when we get it now again we will use binary search to maximize the initial water level of container 1 because we assume that first container has water level 1 but it might be possible that even the water level is >1 then also it will be possible :-).