It took me two hours to solve that problem.

Literal

I [topic-は] that problem [object-を] solve [purpose-のに] 2 hours took.

The pattern [verb]+のにX時間かかる means 'it takes X hours to [verb].' のに here is the purpose/dative marker, not the adversative 'although.' かかる ('to take [time/money]') is intransitive — the time or cost is its subject.