How to Optimise my Time Optimisation Algorithm I recently encountered a problem which goes like this :
A student is given N number of questions and T time in total. Each question requires different time to complete and carries different marks. The problem asks to find the maximum marks the student can get by attempting some of the N questions within T time (Assuming if a question is attempted, it must be fully completed,no partial attempt of a question is allowed).

I tried to solve the problem by computing all possible combinations of questions which takes &lt;= T seconds to complete but soon found out its ineffective for large datasets.

How can I optimise my solution? Is there any alternative solution available?
You're trying to solve a knapsack problem&nbsp;&ndash; you're trying to choose items of maximum value, given a constraint on their total size. These problems are NP-complete but can be solved reasonably efficiently in practice. The standard technique is to use dynamic programming. This gives a solution in time polynomial in $N$ and&nbsp;$T$. This is still, technically, an exponential-time algorithm (since an input of length&nbsp;$\ell$ could give $T$ as large as&nbsp;$2^\ell$) but it works well in practice.

I won't give details of how to do the dynamic programming, since knapsack is one of the standard examples of the technique so it's easy to find the details online and in textbooks.