LeetCode 38 Count and Say

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ธ.ค. 2024

ความคิดเห็น • 8

  • @dev-skills
    @dev-skills 3 ปีที่แล้ว

    Time complexity for this solution -> O(n * val.length()) = O(2 * n^2) as val.lenght

    • @abhishekjaiswal6492
      @abhishekjaiswal6492 3 ปีที่แล้ว

      space complexity should be O(size of greatest length string)
      not n because we will have to store the greatest string and then we will have to return it

  • @rajendrarv
    @rajendrarv 2 ปีที่แล้ว +1

    this can be solved using recursion, if u want I will give u the solution that is memory optimize

  • @TrIcKLoOthere
    @TrIcKLoOthere 4 ปีที่แล้ว +1

    hey Ashish what will be our time and space complexity for this solution ?

    • @ashishcode
      @ashishcode  4 ปีที่แล้ว

      It's a little difficult to understand,as for the time complexity,we have one loop 0 to n-1 but for each of that we are traversing through the length of val and val keeps incrementing with each n.
      Space complexity will be dependent on n as we are reforming our string at each n.

    • @dev-skills
      @dev-skills 3 ปีที่แล้ว +1

      Time complexity for this solution -> O(n * val.length()) = O(2 * n^2) as val.lenght

  • @madhukhare2417
    @madhukhare2417 4 ปีที่แล้ว +3

    This solution have memory limited exceeded problem for the input greater than 4

  • @madhukhare2417
    @madhukhare2417 4 ปีที่แล้ว +1

    Memory limit exceeded