lib/super_digit.rb
# Time Complexity - O(n) where n is equal to the number of digits in the n-number passed in the method
# Space Complexity - O(n) where n is equal to the number of times the super_digit method is placed on the call stack
Time Complexity - O(n) where n is equal to the number of digits in the n-number passed in the method
Space Complexity - O(n) where n is equal to the number of times the super_digit method is placed on the call stack
Time Complexity - O ( n ) where n is equal to the number of digits in the n - number passed in the method Space Complexity - O ( n ) where n is equal to the number of times the super_digit method is placed on the call stack
def super_digit(n)
  total = 0
  until n % 10 == 0
    counter = n % 10
    total += counter
    n = n/10
  end
  if total > 9
    return super_digit(total)
  else
    return total
  end
end
def super_digit ( n ) total = 0 until n % 10 == 0 counter = n % 10 total += counter n = n / 10 end if total > 9 return super_digit ( total ) else return total end end
Time Complexity - O(n) where n is equal to the number of digits in the n-number passed in the method
Space Complexity - O(n) where n is equal to the number of times the super_digit method is placed on the call stack
Time Complexity - O ( n ) where n is equal to the number of digits in the n - number passed in the method Space Complexity - O ( n ) where n is equal to the number of times the super_digit method is placed on the call stack
# first modulo (n % 10) and add to a counter(number) # until n%10 is equal 0
n