Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя sdKrhMn286

Автор sdKrhMn286, история, 15 месяцев назад, По-английски

I wrote this solution for this problem and getting TLE on last test case. Can someone tell me how I can make my solution more optimal with or without DP .

Thanks in advance :);

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
15 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится
  1. Pass the string by reference in rec().
  2. Add this in the first line of rec() if((int)(ans.size()) return; because you only need one possible answer.
  3. You have not memoized your recursion. (And the dp array should be a 2D array instead, although you haven't used it).