to think hard in order to find an answer to sth
scratch your head (over sth)
Definitions from the Oxford Advanced Learner's Dictionary, 9th edition