This paper is on the so called inverse problem of ordinary differential equations, i.e. the problem of determining the differential system satisfying a set of given properties. More precisely we characterize under very general assumptions the ordinary differential equations in $$\mathbb {R}^N$$ R N which have a given set of either $$M$$ M partial integrals, or $$M<N$$ M < N first integral, or $$M<N$$ M < N partial and first integrals. Moreover, for such systems we determine the necessary and sufficient conditions for the existence of $$N-1$$ N - 1 independent first integrals. We give two relevant applications of the solutions of these inverse problem to constrained Lagrangian and Hamiltonian systems respectively. Additionally we provide the general solution of the inverse problem in dynamics.