educative.io

Constraints on the problem

From where are these constraints being determined?

Why are these constraints for the solution or why doesn’t the current solution work outside of these constraints?

Hello @PAWAN,

The constraints on this interview question or any problem-solving and algorithm design problem are determined using various factors, ranging from the computational power to real-world scenarios.

Let’s understand this with the help of the problem’s second constraint: “There will be at least one element in the data structure before the median is computed.”

Imagine a scenario where the data structure is empty, and no elements have been added yet. It wouldn’t make sense if the median were to be computed at this point, as there is no data to calculate a meaningful median from. By enforcing the constraint that there will be at least one element present before computing the median, the problem statement ensures that calculations are valid and relevant. It sets a baseline condition where a minimum amount of data is needed for a meaningful median calculation.

Usually the goal is to allow the learner to solve the interview problems by coming up with a solution that can be evaluated on non-trivial data and test cases based on the type of data structure that is used in that particular problem.

Hope this answers your query, feel free to share any more suggestions and feedbacks.

Thanks and regards,
Dian Us Suqlain
Developer Advocate @Educative.io

1 Like